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().
Unified · Split
| @@ -140,7 +140,7 @@ EXPORT_SYMBOL_GPL(gpio_to_desc); · 139 unmodified lines | ||
| 140 | 140 | * in the given chip for the specified hardware number. |
| 141 | 141 | */ |
| 142 | 142 | struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, |
| 143 | − u16 hwnum) | |
| 143 | + unsigned int hwnum) | |
| 144 | 144 | { |
| 145 | 145 | struct gpio_device *gdev = chip->gpiodev; |
| 146 | 146 | |
| @@ -2990,7 +2990,8 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); · 2843 unmodified lines | ||
| 2990 | 2990 | * A pointer to the GPIO descriptor, or an ERR_PTR()-encoded negative error |
| 2991 | 2991 | * code on failure. |
| 2992 | 2992 | */ |
| 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, | |
| 2994 | 2995 | const char *label, |
| 2995 | 2996 | enum gpio_lookup_flags lflags, |
| 2996 | 2997 | enum gpiod_flags dflags) |
| @@ -78,7 +78,8 @@ struct gpio_array { · 77 unmodified lines | ||
| 78 | 78 | unsigned long invert_mask[]; |
| 79 | 79 | }; |
| 80 | 80 | |
| 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); | |
| 82 | 83 | int gpiod_get_array_value_complex(bool raw, bool can_sleep, |
| 83 | 84 | unsigned int array_size, |
| 84 | 85 | struct gpio_desc **desc_array, |
| @@ -715,7 +715,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip) · 714 unmodified lines | ||
| 715 | 715 | |
| 716 | 716 | #endif /* CONFIG_PINCTRL */ |
| 717 | 717 | |
| 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, | |
| 719 | 720 | const char *label, |
| 720 | 721 | enum gpio_lookup_flags lflags, |
| 721 | 722 | enum gpiod_flags dflags); |