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

regulator: max77686: fix gpio_enabled shift wrapping bug

The code should handle more than 32 bits here because "id"
can be a value up to MAX77686_REGULATORS (currently 34).

Convert the gpio_enabled type to DECLARE_BITMAP and use
test_bit/set_bit.

Fixes: 3307e9025d29 ("regulator: max77686: Add GPIO control")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org

authored by

Joe Perches and committed by
Mark Brown
c53403a3 e4e8cccc

+3 -3
+3 -3
drivers/regulator/max77686.c
··· 88 88 }; 89 89 90 90 struct max77686_data { 91 - u64 gpio_enabled:MAX77686_REGULATORS; 91 + DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS); 92 92 93 93 /* Array indexed by regulator id */ 94 94 unsigned int opmode[MAX77686_REGULATORS]; ··· 121 121 case MAX77686_BUCK8: 122 122 case MAX77686_BUCK9: 123 123 case MAX77686_LDO20 ... MAX77686_LDO22: 124 - if (max77686->gpio_enabled & (1 << id)) 124 + if (test_bit(id, max77686->gpio_enabled)) 125 125 return MAX77686_GPIO_CONTROL; 126 126 } 127 127 ··· 277 277 } 278 278 279 279 if (gpio_is_valid(config->ena_gpio)) { 280 - max77686->gpio_enabled |= (1 << desc->id); 280 + set_bit(desc->id, max77686->gpio_enabled); 281 281 282 282 return regmap_update_bits(config->regmap, desc->enable_reg, 283 283 desc->enable_mask,