History

gpiolib: convert the type of hwnum to unsigned int in gpiochip_get_desc()

gpiochip_get_desc() takes a u16 hwnum, but it turns out most users don't respect that and usually pass an unsigned int. Since implicit casting to a smaller type is dangerous - let's change the type of hwnum to unsigned int in gpiochip_get_desc() and in gpiochip_request_own_desc() where the size of hwnum is not respected either and who's a user of the former. This is safe as we then check the hwnum against the number of lines before proceeding in gpiochip_get_desc().

Bartosz Golaszewski committed 6 years ago

Commit 06863621 parent d90f3683 files · +7 −4Browse files

Unified · Split

3 files
  1. drivers/gpio/gpiolib.c +3 −2
  2. drivers/gpio/gpiolib.h +2 −1
  3. include/linux/gpio/driver.h +2 −1
drivers/gpio/gpiolib.c+3−2
@@ -140,7 +140,7 @@ EXPORT_SYMBOL_GPL(gpio_to_desc); · 139 unmodified lines
140140 * in the given chip for the specified hardware number.
141141 */
142142 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip,
143− u16 hwnum)
143+ unsigned int hwnum)
144144 {
145145 struct gpio_device *gdev = chip->gpiodev;
146146
@@ -2990,7 +2990,8 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); · 2843 unmodified lines
29902990 * A pointer to the GPIO descriptor, or an ERR_PTR()-encoded negative error
29912991 * code on failure.
29922992 */
2993−struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
2993+struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip,
2994+ unsigned int hwnum,
29942995 const char *label,
29952996 enum gpio_lookup_flags lflags,
29962997 enum gpiod_flags dflags)
drivers/gpio/gpiolib.h+2−1
@@ -78,7 +78,8 @@ struct gpio_array { · 77 unmodified lines
7878 unsigned long invert_mask[];
7979 };
8080
81−struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum);
81+struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip,
82+ unsigned int hwnum);
8283 int gpiod_get_array_value_complex(bool raw, bool can_sleep,
8384 unsigned int array_size,
8485 struct gpio_desc **desc_array,
include/linux/gpio/driver.h+2−1
@@ -715,7 +715,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip) · 714 unmodified lines
715715
716716 #endif /* CONFIG_PINCTRL */
717717
718−struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
718+struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip,
719+ unsigned int hwnum,
719720 const char *label,
720721 enum gpio_lookup_flags lflags,
721722 enum gpiod_flags dflags);