From: Andy Shevchenko <andy.shevchenko@gmail.com> To: Bartosz Golaszewski <brgl@bgdev.pl> Cc: Kent Gibson <warthog618@gmail.com>, Linus Walleij <linus.walleij@linaro.org>, "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, Bartosz Golaszewski <bgolaszewski@baylibre.com> Subject: Re: [PATCH v2 03/11] gpiolib: convert the type of hwnum to unsigned int in gpiochip_get_desc() Date: Thu, 5 Dec 2019 00:19:11 +0200 Message-ID: <CAHp75VfL95BXuj=bhEjh0zbwoiaj3bQb0HEGfx8RqGppHDCyHQ@mail.gmail.com> (raw) In-Reply-To: <20191204155912.17590-4-brgl@bgdev.pl> On Wed, Dec 4, 2019 at 6:04 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > From: Bartosz Golaszewski <bgolaszewski@baylibre.com> > > 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(). > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> > Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> > --- > drivers/gpio/gpiolib.c | 5 +++-- > drivers/gpio/gpiolib.h | 3 ++- > include/linux/gpio/driver.h | 3 ++- > 3 files changed, 7 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index 72211407469f..b3ffb079e323 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -140,7 +140,7 @@ EXPORT_SYMBOL_GPL(gpio_to_desc); > * in the given chip for the specified hardware number. > */ > struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, > - u16 hwnum) > + unsigned int hwnum) > { > struct gpio_device *gdev = chip->gpiodev; > > @@ -2990,7 +2990,8 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); > * A pointer to the GPIO descriptor, or an ERR_PTR()-encoded negative error > * code on failure. > */ > -struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, > +struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, > + unsigned int hwnum, > const char *label, > enum gpio_lookup_flags lflags, > enum gpiod_flags dflags) > diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h > index ca9bc1e4803c..a1cbeabadc69 100644 > --- a/drivers/gpio/gpiolib.h > +++ b/drivers/gpio/gpiolib.h > @@ -78,7 +78,8 @@ struct gpio_array { > unsigned long invert_mask[]; > }; > > -struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum); > +struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, > + unsigned int hwnum); > int gpiod_get_array_value_complex(bool raw, bool can_sleep, > unsigned int array_size, > struct gpio_desc **desc_array, > diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h > index e2480ef94c55..4f032de10bae 100644 > --- a/include/linux/gpio/driver.h > +++ b/include/linux/gpio/driver.h > @@ -715,7 +715,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip) > > #endif /* CONFIG_PINCTRL */ > > -struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, > +struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, > + unsigned int hwnum, > const char *label, > enum gpio_lookup_flags lflags, > enum gpiod_flags dflags); > -- > 2.23.0 > -- With Best Regards, Andy Shevchenko
next prev parent reply index Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-12-04 15:59 [PATCH v2 00/11] gpiolib: add an ioctl() for monitoring line status changes Bartosz Golaszewski 2019-12-04 15:59 ` [PATCH v2 01/11] gpiolib: use 'unsigned int' instead of 'unsigned' in gpio_set_config() Bartosz Golaszewski 2019-12-04 22:18 ` Andy Shevchenko 2019-12-04 15:59 ` [PATCH v2 02/11] gpiolib: have a single place of calling set_config() Bartosz Golaszewski 2019-12-04 22:18 ` Andy Shevchenko 2019-12-04 15:59 ` [PATCH v2 03/11] gpiolib: convert the type of hwnum to unsigned int in gpiochip_get_desc() Bartosz Golaszewski 2019-12-04 22:19 ` Andy Shevchenko [this message] 2019-12-04 15:59 ` [PATCH v2 04/11] gpiolib: use gpiochip_get_desc() in linehandle_create() Bartosz Golaszewski 2019-12-04 22:20 ` Andy Shevchenko 2019-12-04 15:59 ` [PATCH v2 05/11] gpiolib: use gpiochip_get_desc() in lineevent_create() Bartosz Golaszewski 2019-12-04 22:20 ` Andy Shevchenko 2019-12-04 15:59 ` [PATCH v2 06/11] gpiolib: use gpiochip_get_desc() in gpio_ioctl() Bartosz Golaszewski 2019-12-04 16:25 ` Rainer Sickinger 2019-12-04 22:21 ` Andy Shevchenko 2019-12-04 15:59 ` [PATCH v2 07/11] gpiolib: rework the locking mechanism for lineevent kfifo Bartosz Golaszewski 2019-12-04 22:25 ` Andy Shevchenko 2019-12-05 9:31 ` Bartosz Golaszewski 2019-12-05 10:22 ` Andy Shevchenko 2019-12-04 15:59 ` [PATCH v2 08/11] gpiolib: emit a debug message when adding events to a full kfifo Bartosz Golaszewski 2019-12-04 22:28 ` Andy Shevchenko 2019-12-04 15:59 ` [PATCH v2 09/11] gpiolib: provide a dedicated function for setting lineinfo Bartosz Golaszewski 2019-12-04 22:30 ` Andy Shevchenko 2019-12-05 9:28 ` Bartosz Golaszewski 2019-12-05 10:20 ` Andy Shevchenko 2019-12-05 13:45 ` Bartosz Golaszewski 2019-12-05 16:47 ` Andy Shevchenko
Reply instructions: You may reply publically to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CAHp75VfL95BXuj=bhEjh0zbwoiaj3bQb0HEGfx8RqGppHDCyHQ@mail.gmail.com' \ --to=andy.shevchenko@gmail.com \ --cc=bgolaszewski@baylibre.com \ --cc=brgl@bgdev.pl \ --cc=linus.walleij@linaro.org \ --cc=linux-gpio@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=warthog618@gmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Linux-GPIO Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/linux-gpio/0 linux-gpio/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 linux-gpio linux-gpio/ https://lore.kernel.org/linux-gpio \ linux-gpio@vger.kernel.org public-inbox-index linux-gpio Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.linux-gpio AGPL code for this site: git clone https://public-inbox.org/public-inbox.git