On Tue, Sep 05, 2023 at 08:52:52PM +0200, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> > > Getting the GPIO descriptor directly from the gpio_chip struct is > dangerous as we don't take the reference to the underlying GPIO device. > In order to start working towards removing gpiochip_get_desc(), let's > provide a safer variant that works with an existing reference to struct > gpio_device. ... > +/** > + * gpio_device_get_desc() - get the GPIO descriptor corresponding to the given > + * hardware number for this GPIO device > + * @gdev: GPIO device to get the descriptor from > + * @hwnum: hardware number of the GPIO for this chip > + * > + * Returns: > + * A pointer to the GPIO descriptor or ``ERR_PTR(-EINVAL)`` if no GPIO exists The known constants can be referenced as %EINVAL. > + * in the given chip for the specified hardware number or ``ERR_PTR(-ENODEV)`` Ditto. > + * if the underlying chip already vanished. > + * > + * The reference count of struct gpio_device is *NOT* increased like when the > + * GPIO is being requested for exclusive usage. It's up to the caller to make > + * sure the GPIO device will stay alive together with the descriptor returned > + * by this function. > + */ -- With Best Regards, Andy Shevchenko