Re: [PATCH 04/21] gpiolib: provide gpio_device_get_desc()
Andy Shevchenko <[email protected]> Wed, 6 Sep 2023 17:15:59 +0300
| Newsgroups | dev.linux.lists.timestamp,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-acpi,org.kernel.vger.linux-gpio,org.kernel.vger.linux-kernel,org.kernel.vger.linux-omap,org.kernel.vger.linux-tegra,org.kernel.vger.platform-driver-x86 |
|---|---|
| Organization | Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo |
| Message-ID | <[email protected]> |
On Tue, Sep 05, 2023 at 08:52:52PM +0200, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski <[email protected]> > > 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