From patchwork Thu May 11 03:45:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 9720883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4D8BA6031B for ; Thu, 11 May 2017 03:46:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46F8F28668 for ; Thu, 11 May 2017 03:46:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BE102866B; Thu, 11 May 2017 03:46:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C60F28675 for ; Thu, 11 May 2017 03:46:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753487AbdEKDp7 (ORCPT ); Wed, 10 May 2017 23:45:59 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:52010 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751208AbdEKDp6 (ORCPT ); Wed, 10 May 2017 23:45:58 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 1ADA88448A; Thu, 11 May 2017 15:45:55 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1494474355; bh=lfgN3v6JyRsj8pbnkL89fwfpb+btSqM+w+fFgvYzCdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JeDnU/aDOdRsR+rSu+kViqHlOIYATWE+Ex5rguoxLyG709q53PUy/OltSHAXr9R0J pZJYLnxvPT57StOKXzs49uKBA0+Tiwyl6gqvJxKtdfQxlN1yYS7h0XKgcUAC8p3Vcq cwcMAhOgceh8STDEqj81uhI9ilXFx9zZknm31wkg= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 7, 9061) id ; Thu, 11 May 2017 15:45:55 +1200 Received: from chrisp-dl.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id A816713EC67; Thu, 11 May 2017 15:45:54 +1200 (NZST) Received: by chrisp-dl.atlnz.lc (Postfix, from userid 1030) id 8C9EA1E1E37; Thu, 11 May 2017 15:45:53 +1200 (NZST) From: Chris Packham To: linux-hwmon@vger.kernel.org, linux@roeck-us.net Cc: Tobi Wulff , Chris Packham , Jean Delvare , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] hwmon: (adt7475) replace find_nearest() with find_closest() Date: Thu, 11 May 2017 15:45:21 +1200 Message-Id: <20170511034524.22698-2-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.11.0.24.ge6920cf In-Reply-To: <20170511034524.22698-1-chris.packham@alliedtelesis.co.nz> References: <20170511034524.22698-1-chris.packham@alliedtelesis.co.nz> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The adt7475 has had find_nearest() since it's creation in 2009. Since then find_closest() has been introduced and several drivers have been updated to use it. Update the adt7475 to use find_closest() and remove the now unused find_nearest(). Signed-off-by: Chris Packham --- Changes in v3: - None drivers/hwmon/adt7475.c | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index c803e3c5fcd4..ec0c43fbcdce 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -22,6 +22,7 @@ #include #include #include +#include /* Indexes for the sysfs hooks */ @@ -314,35 +315,6 @@ static void adt7475_write_word(struct i2c_client *client, int reg, u16 val) i2c_smbus_write_byte_data(client, reg, val & 0xFF); } -/* - * Find the nearest value in a table - used for pwm frequency and - * auto temp range - */ -static int find_nearest(long val, const int *array, int size) -{ - int i; - - if (val < array[0]) - return 0; - - if (val > array[size - 1]) - return size - 1; - - for (i = 0; i < size - 1; i++) { - int a, b; - - if (val > array[i + 1]) - continue; - - a = val - array[i]; - b = array[i + 1] - val; - - return (a <= b) ? i : i + 1; - } - - return 0; -} - static ssize_t show_voltage(struct device *dev, struct device_attribute *attr, char *buf) { @@ -606,7 +578,7 @@ static ssize_t set_point2(struct device *dev, struct device_attribute *attr, val -= temp; /* Find the nearest table entry to what the user wrote */ - val = find_nearest(val, autorange_table, ARRAY_SIZE(autorange_table)); + val = find_closest(val, autorange_table, ARRAY_SIZE(autorange_table)); data->range[sattr->index] &= ~0xF0; data->range[sattr->index] |= val << 4; @@ -864,7 +836,7 @@ static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr, if (kstrtol(buf, 10, &val)) return -EINVAL; - out = find_nearest(val, pwmfreq_table, ARRAY_SIZE(pwmfreq_table)); + out = find_closest(val, pwmfreq_table, ARRAY_SIZE(pwmfreq_table)); mutex_lock(&data->lock);