Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: sm501: Switch to BIT() to mitigate integer overflows

If offset end up being high enough, right hand expression in functions
like sm501_gpio_set() shifted left for that number of bits, may
not fit in int type.

Just in case, fix that by using BIT() both as an option safe from
overflow issues and to make this step look similar to other gpio
drivers.

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: f61be273d369 ("sm501: add gpiolib support")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
Link: https://lore.kernel.org/r/20250115171206.20308-1-n.zhandarovich@fintech.ru
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Nikita Zhandarovich and committed by
Lee Jones
2d8cb9ff 9675c059

+3 -3
+3 -3
drivers/mfd/sm501.c
··· 920 920 { 921 921 struct sm501_gpio_chip *smchip = gpiochip_get_data(chip); 922 922 struct sm501_gpio *smgpio = smchip->ourgpio; 923 - unsigned long bit = 1 << offset; 923 + unsigned long bit = BIT(offset); 924 924 void __iomem *regs = smchip->regbase; 925 925 unsigned long save; 926 926 unsigned long val; ··· 946 946 struct sm501_gpio_chip *smchip = gpiochip_get_data(chip); 947 947 struct sm501_gpio *smgpio = smchip->ourgpio; 948 948 void __iomem *regs = smchip->regbase; 949 - unsigned long bit = 1 << offset; 949 + unsigned long bit = BIT(offset); 950 950 unsigned long save; 951 951 unsigned long ddr; 952 952 ··· 971 971 { 972 972 struct sm501_gpio_chip *smchip = gpiochip_get_data(chip); 973 973 struct sm501_gpio *smgpio = smchip->ourgpio; 974 - unsigned long bit = 1 << offset; 974 + unsigned long bit = BIT(offset); 975 975 void __iomem *regs = smchip->regbase; 976 976 unsigned long save; 977 977 unsigned long val;