Patch "hwmon: (ltc2991) Fix mixed signed/unsigned in DIV_ROUND_CLOSEST" has been added to the 6.12-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    hwmon: (ltc2991) Fix mixed signed/unsigned in DIV_ROUND_CLOSEST

to the 6.12-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     hwmon-ltc2991-fix-mixed-signed-unsigned-in-div_round.patch
and it can be found in the queue-6.12 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 650c0e6becd814d7d2c11082e681138ccdeda643
Author: David Lechner <dlechner@xxxxxxxxxxxx>
Date:   Wed Jan 15 14:48:27 2025 -0600

    hwmon: (ltc2991) Fix mixed signed/unsigned in DIV_ROUND_CLOSEST
    
    [ Upstream commit e9b24deb84863c5a77dda5be57b6cb5bf4127b85 ]
    
    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@xxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20250115-hwmon-ltc2991-fix-div-round-closest-v1-1-b4929667e457@xxxxxxxxxxxx
    Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/hwmon/ltc2991.c b/drivers/hwmon/ltc2991.c
index 7ca139e4b6aff..6d5d4cb846daf 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;
 }




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux