Skip to content

Commit 2d8cb9f

Browse files
Nikita Zhandarovichlag-linaro
authored andcommitted
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: f61be27 ("sm501: add gpiolib support") Signed-off-by: Nikita Zhandarovich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 9675c05 commit 2d8cb9f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/mfd/sm501.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ static void sm501_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
920920
{
921921
struct sm501_gpio_chip *smchip = gpiochip_get_data(chip);
922922
struct sm501_gpio *smgpio = smchip->ourgpio;
923-
unsigned long bit = 1 << offset;
923+
unsigned long bit = BIT(offset);
924924
void __iomem *regs = smchip->regbase;
925925
unsigned long save;
926926
unsigned long val;
@@ -946,7 +946,7 @@ static int sm501_gpio_input(struct gpio_chip *chip, unsigned offset)
946946
struct sm501_gpio_chip *smchip = gpiochip_get_data(chip);
947947
struct sm501_gpio *smgpio = smchip->ourgpio;
948948
void __iomem *regs = smchip->regbase;
949-
unsigned long bit = 1 << offset;
949+
unsigned long bit = BIT(offset);
950950
unsigned long save;
951951
unsigned long ddr;
952952

@@ -971,7 +971,7 @@ static int sm501_gpio_output(struct gpio_chip *chip,
971971
{
972972
struct sm501_gpio_chip *smchip = gpiochip_get_data(chip);
973973
struct sm501_gpio *smgpio = smchip->ourgpio;
974-
unsigned long bit = 1 << offset;
974+
unsigned long bit = BIT(offset);
975975
void __iomem *regs = smchip->regbase;
976976
unsigned long save;
977977
unsigned long val;

0 commit comments

Comments
 (0)