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: <1a1f56d8-1783-487b-b57e-3c873f64150a@roeck-us.net>
Date: Wed, 15 Jan 2025 13:52:56 -0800
From: Guenter Roeck <linux@...ck-us.net>
To: David Lechner <dlechner@...libre.com>
Cc: Antoniu Miclaus <antoniu.miclaus@...log.com>,
	Jean Delvare <jdelvare@...e.com>, linux-hwmon@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] hwmon: (ltc2991) Fix mixed signed/unsigned in
 DIV_ROUND_CLOSEST

On Wed, Jan 15, 2025 at 02:48:27PM -0600, David Lechner wrote:
> Fix use of DIV_ROUND_CLOSEST where a possibly negative value is divided
> by an unsigned type by casting the unsigned type to the signed type of
> the same size (st->r_sense_uohm[channel] has type of u32).
> 
> The docs on the DIV_ROUND_CLOSEST macro explain that dividing a negative
> value by an unsigned type is undefined behavior. The actual behavior is
> that it converts both values to unsigned before doing the division, for
> example:
> 
>     int ret = DIV_ROUND_CLOSEST(-100, 3U);
> 
> results in ret == 1431655732 instead of -33.
> 
> Fixes: 2b9ea4262ae9 ("hwmon: Add driver for ltc2991")
> Signed-off-by: David Lechner <dlechner@...libre.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/ltc2991.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 
> ---
> base-commit: dab2734f8e9ecba609d66d1dd087a392a7774c04
> change-id: 20250115-hwmon-ltc2991-fix-div-round-closest-c65c05afb881
> 
> Best regards,
> 
> diff --git a/drivers/hwmon/ltc2991.c b/drivers/hwmon/ltc2991.c
> index 7ca139e4b6aff0b6c3024183e19970b36f927f6e..6d5d4cb846daf3025e55d43cfe311f38bb353621 100644
> --- a/drivers/hwmon/ltc2991.c
> +++ b/drivers/hwmon/ltc2991.c
> @@ -125,7 +125,7 @@ static int ltc2991_get_curr(struct ltc2991_state *st, u32 reg, int channel,
>  
>  	/* Vx-Vy, 19.075uV/LSB */
>  	*val = DIV_ROUND_CLOSEST(sign_extend32(reg_val, 14) * 19075,
> -				 st->r_sense_uohm[channel]);
> +				 (s32)st->r_sense_uohm[channel]);
>  
>  	return 0;
>  }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ