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: <20191206143703.GA2291@roeck-us.net>
Date:   Fri, 6 Dec 2019 06:37:03 -0800
From:   Guenter Roeck <linux@...ck-us.net>
To:     Luuk Paulussen <luuk.paulussen@...iedtelesis.co.nz>
Cc:     Jean Delvare <jdelvare@...e.com>, linux-hwmon@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] hwmon: (adt7475) Make volt2reg return same reg as
 reg2volt input

On Fri, Dec 06, 2019 at 12:16:59PM +1300, Luuk Paulussen wrote:
> reg2volt returns the voltage that matches a given register value.
> Converting this back the other way with volt2reg didn't return the same
> register value because it used truncation instead of rounding.
> 
> This meant that values read from sysfs could not be written back to sysfs
> to set back the same register value.
> 
> With this change, volt2reg will return the same value for every voltage
> previously returned by reg2volt (for the set of possible input values)
> 
> Signed-off-by: Luuk Paulussen <luuk.paulussen@...iedtelesis.co.nz>

Applied.

Thanks,
Guenter

> ---
>  changes in v2:
>  - remove unnecessary braces.
>  drivers/hwmon/adt7475.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
> index 6c64d50c9aae..01c2eeb02aa9 100644
> --- a/drivers/hwmon/adt7475.c
> +++ b/drivers/hwmon/adt7475.c
> @@ -294,9 +294,10 @@ static inline u16 volt2reg(int channel, long volt, u8 bypass_attn)
>  	long reg;
>  
>  	if (bypass_attn & (1 << channel))
> -		reg = (volt * 1024) / 2250;
> +		reg = DIV_ROUND_CLOSEST(volt * 1024, 2250);
>  	else
> -		reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250);
> +		reg = DIV_ROUND_CLOSEST(volt * r[1] * 1024,
> +					(r[0] + r[1]) * 2250);
>  	return clamp_val(reg, 0, 1023) & (0xff << 2);
>  }
>  

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ