summaryrefslogtreecommitdiff
path: root/drivers/hwmon/corsair-psu.c
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2020-11-05 14:50:19 +0300
committerGuenter Roeck <linux@roeck-us.net>2020-12-03 04:42:23 +0300
commit90673f713fceaa50eef1bff0bcc8ee4e6fbc8953 (patch)
tree861b45f2f5b84e96ccaf80ab470bdcfe8422d9f0 /drivers/hwmon/corsair-psu.c
parentd115b51e0e567199c821fc39e13b6af7e78f247d (diff)
downloadlinux-90673f713fceaa50eef1bff0bcc8ee4e6fbc8953.tar.xz
hwmon: (corsair-psu) fix unintentional sign extension issue
The shifting of the u8 integer data[3] by 24 bits to the left will be promoted to a 32 bit signed int and then sign-extended to a long. In the event that the top bit of data[3] is set then all then all the upper 32 bits of a 64 bit long end up as also being set because of the sign-extension. Fix this by casting data[3] to a long before the shift. Addresses-Coverity: ("Unintended sign extension") Fixes: ce15cd2cee8b ("hwmon: add Corsair PSU HID controller driver") Signed-off-by: Colin Ian King <colin.king@canonical.com> Link: https://lore.kernel.org/r/20201105115019.41735-1-colin.king@canonical.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/corsair-psu.c')
-rw-r--r--drivers/hwmon/corsair-psu.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
index e92d0376e7ac..5d19a888231a 100644
--- a/drivers/hwmon/corsair-psu.c
+++ b/drivers/hwmon/corsair-psu.c
@@ -241,7 +241,7 @@ static int corsairpsu_get_value(struct corsairpsu_data *priv, u8 cmd, u8 rail, l
* the LINEAR11 conversion are the watts values which are about 1200 for the strongest psu
* supported (HX1200i)
*/
- tmp = (data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0];
+ tmp = ((long)data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0];
switch (cmd) {
case PSU_CMD_IN_VOLTS:
case PSU_CMD_IN_AMPS: