Skip to content

Commit 0686362

Browse files
committed
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(). Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Linus Walleij <[email protected]>
1 parent d90f368 commit 0686362

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ EXPORT_SYMBOL_GPL(gpio_to_desc);
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);
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ struct gpio_array {
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip)
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);

0 commit comments

Comments
 (0)