Re: [PATCH v3 2/7] gpiolib: use kref in gpio_desc

From: Linus Walleij
Date: Fri Feb 21 2020 - 08:41:09 EST

On Wed, Feb 19, 2020 at 10:22 AM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:

> From: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>
> GPIO descriptors are freed by consumers using gpiod_put(). The name of
> this function suggests some reference counting is going on but it's not
> true.
> Use kref to actually introduce reference counting for gpio_desc objects.
> Add a corresponding gpiod_get() helper for increasing the reference count.
> This doesn't change anything for already existing (correct) drivers but
> allows us to keep track of GPIO descs used by multiple users.
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>

I really like the simplicity of this approach ... hm!
It seems the only downside is a krefcount_t extra per gpio_desc
which is an atomic_t so I guess 32 or 64 bits per desc depending
on arch.

We discussed refcounts in gpiods in another context but it got
really complicated there. This is a clearly cut usecase.

Linus Walleij