[PATCH v2 02/11] gpiolib: add support for scope-based management to gpio_device

Bartosz Golaszewski posted 11 patches 2 years, 3 months ago
There is a newer version of this series
[PATCH v2 02/11] gpiolib: add support for scope-based management to gpio_device
Posted by Bartosz Golaszewski 2 years, 3 months ago
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

As the few users that need to get the reference to the GPIO device often
release it right after inspecting its properties, let's add support for
the automatic reference release to struct gpio_device.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
 include/linux/gpio/driver.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index a2060dc3344b..a52c6cc5162b 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -609,6 +609,8 @@ struct gpio_chip *gpiochip_find(void *data,
 struct gpio_device *gpio_device_get(struct gpio_device *gdev);
 void gpio_device_put(struct gpio_device *gdev);
 
+DEFINE_FREE(gpio_device_put, struct gpio_device *, if (_T) gpio_device_put(_T));
+
 bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset);
 int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset);
 void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset);
-- 
2.39.2
Re: [PATCH v2 02/11] gpiolib: add support for scope-based management to gpio_device
Posted by Andy Shevchenko 2 years, 3 months ago
On Tue, Sep 12, 2023 at 12:07:18PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> As the few users that need to get the reference to the GPIO device often
> release it right after inspecting its properties, let's add support for
> the automatic reference release to struct gpio_device.

...

> +DEFINE_FREE(gpio_device_put, struct gpio_device *, if (_T) gpio_device_put(_T));

Looks like this should be

	if (!IS_ERR_OR_NULL(_T))

(with linux/err.h included).

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 02/11] gpiolib: add support for scope-based management to gpio_device
Posted by Bartosz Golaszewski 2 years, 3 months ago
On Tue, Sep 12, 2023 at 1:33 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Tue, Sep 12, 2023 at 12:07:18PM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > As the few users that need to get the reference to the GPIO device often
> > release it right after inspecting its properties, let's add support for
> > the automatic reference release to struct gpio_device.
>
> ...
>
> > +DEFINE_FREE(gpio_device_put, struct gpio_device *, if (_T) gpio_device_put(_T));
>
> Looks like this should be
>
>         if (!IS_ERR_OR_NULL(_T))
>

Good catch, thanks!

Bart