Skip to content

gpiolib: add reference counting to GPIO descriptors

Bartosz Golaszewski linux-gpio lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 14 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3gpiolib: provide VALIDATE_DESC_PTR() macrodrivers/gpio/gpiolib.c+8 -00 replies
2/3gpiolib: use kref in gpio_descdrivers/gpio/gpiolib.c drivers/gpio/gpiolib.h include/linux/gpio/consumer.h+46 -414 replies
3/3nvmem: increase the reference count of a gpio passed over configdrivers/nvmem/core.c+1 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] gpiolib: add reference counting to GPIO descriptors

From: Bartosz Golaszewski <[email protected]>

This was: nvmem/gpio: fix resource management.

These are the remaining patches from the series aimed at fixing resource management problems in nvmem.

The first one adds a new descriptor validation macro. The second uses kref to add reference counting to GPIO descriptors. The last one fixes a potential use-after-free problem in nvmem.

The last change should actually go into v5.6 but it depends on a new feature. I'm not sure how to go about applying this.

Changes in patch 2/3 since the last submission:
- add a stub for when GPIOLIB is not selected
- use might_sleep() in gpiod_put() as we may not necessarily call gpiod_free() every time now (where it would have been called normally) depending on the reference count

Bartosz Golaszewski (3):
gpiolib: provide VALIDATE_DESC_PTR() macro
gpiolib: use kref in gpio_desc
nvmem: increase the reference count of a gpio passed over config

 drivers/gpio/gpiolib.c        | 48 ++++++++++++++++++++++++++++++++---
 drivers/gpio/gpiolib.h        |  1 +
 drivers/nvmem/core.c          |  2 +-
 include/linux/gpio/consumer.h |  9 +++++++
 4 files changed, 55 insertions(+), 5 deletions(-)
Signature · 1 line
2.25.0