lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <84dc473a-a780-7166-4d1e-5e88a89fce8a@roeck-us.net>
Date:   Sun, 14 May 2017 07:52:56 -0700
From:   Guenter Roeck <linux@...ck-us.net>
To:     Chris Packham <chris.packham@...iedtelesis.co.nz>,
        linux-hwmon@...r.kernel.org
Cc:     Tobi Wulff <tobi.wulff@...iedtelesis.co.nz>,
        Jean Delvare <jdelvare@...e.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 1/4] hwmon: (adt7475) replace find_nearest() with
 find_closest()

On 05/10/2017 08:45 PM, Chris Packham wrote:
> 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 <chris.packham@...iedtelesis.co.nz>

Applied to hwmon-next.

Thanks,
Guenter

> ---
> 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 <linux/hwmon-vid.h>
>  #include <linux/err.h>
>  #include <linux/jiffies.h>
> +#include <linux/util_macros.h>
>
>  /* 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);
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ