Skip to content

nvmem/gpio: fix resource management

Bartosz Golaszewski linux-gpio lkml 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest5 patches 4 repliesIn review
  2. v44 patches 5 repliesSuperseded
  3. v37 patches 5 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v27 patches7 repliesSuperseded
v16 patches8 repliesSuperseded

Changes in v5 from the cover letter

- don't reference nvmem once it's freed
- add GPIO descriptor validation in gpiod_ref()

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5nvmem: fix memory leak in error pathdrivers/nvmem/core.c+6 -21 reply
2/5gpiolib: provide VALIDATE_DESC_PTR() macrodrivers/gpio/gpiolib.c+8 -01 reply
3/5gpiolib: use kref in gpio_descdrivers/gpio/gpiolib.c drivers/gpio/gpiolib.h include/linux/gpio/consumer.h+36 -42 replies
4/5nvmem: increase the reference count of a gpio passed over configdrivers/nvmem/core.c+1 -10 replies
5/5nvmem: release the write-protect pindrivers/nvmem/core.c+1 -00 replies

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchLinus Walleij
1/5
2/5R-b
3/5
4/5
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH v5 0/5] nvmem/gpio: fix resource management

From: Bartosz Golaszewski <[email protected]>

Hi Srinivas,

sorry for the lack of proper QA last time. This time the code is tested on real HW (Beagle Bone Black with an ACME cape) including the error path.

--

This series addresses a couple problems with memory management in nvmem core.

First we fix a memory leak introduced in this release cycle. Next we extend the GPIO framework to use reference counting for GPIO descriptors. We then use it to fix the resource management problem with the write-protect pin.

While the memory leak with wp-gpios is now in mainline - I'm not sure how to go about applying the kref patch. This is theoretically a new feature but it's also the cleanest way of fixing the problem.

v1 -> v2:
- make gpiod_ref() helper return
- reorganize the series for easier merging
- fix another memory leak

v2 -> v3:
- drop incorrect patches
- add a patch adding a comment about resource management
- extend the GPIO kref patch: only increment the reference count if the descriptor is associated with a requested line

v3 -> v4:
- fixed the return value in error path in nvmem_register()
- dropped patches already applied to the nvmem tree
- dropped the patch adding the comment about resource management

v4 -> v5:
- don't reference nvmem once it's freed
- add GPIO descriptor validation in gpiod_ref()

Bartosz Golaszewski (4):
nvmem: fix memory leak in error path
gpiolib: provide VALIDATE_DESC_PTR() macro
gpiolib: use kref in gpio_desc
nvmem: increase the reference count of a gpio passed over config

Khouloud Touil (1):
nvmem: release the write-protect pin

 drivers/gpio/gpiolib.c        | 46 ++++++++++++++++++++++++++++++++---
 drivers/gpio/gpiolib.h        |  1 +
 drivers/nvmem/core.c          | 11 ++++++---
 include/linux/gpio/consumer.h |  1 +
 4 files changed, 52 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.0