mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Linus Walleij <linusw@kernel.org>,
	 Bartosz Golaszewski <brgl@kernel.org>
Cc: Andy Shevchenko <andy@kernel.org>,
	 Janusz Krzysztofik <jmkrzyszt@gmail.com>,
	linux-gpio@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@intel.com>
Subject: [PATCH v3 0/8] gpiolib: scope-based management and cleanup for GPIO descriptor arrays
Date: Thu, 05 Nov 2026 22:30:14 -0800	[thread overview]
Message-ID: <20261105-b4-gpiolib-free-v3-0-bb47ad58642d@gmail.com> (raw)

This series fixes a GPIO descriptor leak and a fast-path cancellation
bug in gpiod_get_array(), fixes the !CONFIG_OF_GPIO stub for
of_gpio_count() to return -ENOENT instead of 0, introduces
DEFINE_FREE() scope-based cleanup helpers for GPIO descriptors
(gpiod_put and gpiod_put_array), converts gpiod_get_array() to use
them, reworks descriptor array allocation to avoid krealloc(),
switches fastpath bitmaps in struct gpio_array to bitmap_zalloc()
and bitmap_free(), and uses the %*pb format specifier when printing
array masks.

In patch 7/8, each of the three fastpath bitmaps (get_mask,
set_mask, and invert_mask) is allocated with its own bitmap_zalloc()
call rather than packing all three into a single bitmap_zalloc()
allocation. While Andy suggested a single 3x bitmap_zalloc() call to
avoid multiple allocations, slicing one bitmap into three pointers
still requires rounding the bit count up to BITS_PER_LONG and doing
manual unsigned long pointer arithmetic (which would still break if
bitmaps ever gained a header or tail), while still adding a second
allocation and extra bitmap_free() paths on fastpath cancellation and
teardown. Using three separate bitmap_zalloc() calls achieves full
bitmap API abstraction at the cost of three extra slab allocations when
the fastpath is used, and is kept as a separate patch so the
maintainers can decide whether they prefer the single contiguous
allocation in patch 6/8 or the strict bitmap abstraction in patch 7/8.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
Changes in v3:
- In patch 1/8, declared loop induction variable in for loop header and
  carried it through the series.
- In patch 5/8, placed descs definition and kzalloc_flex()
  initialization on a single line, and preserved reverse Christmas
  tree order.
- In patch 6/8, moved descs definition after count < 0 error check.
- In patch 7/8, deferred descs definition in gpio_descs_alloc() until
  after the early return, using struct_size_t() and a single statement
  initialization at the kzalloc() call site.
- Added patch 8/8 using %*pb format specifier when printing array masks.
- Added Reviewed-by tags from Andy Shevchenko and Linus Walleij.
- Link to v2: https://patch.msgid.link/20261103-b4-gpiolib-free-v2-0-ea46767c9cf8@gmail.com

Changes in v2:
- Added cover letter for the series.
- Added a patch fixing the !CONFIG_OF_GPIO of_gpio_count() stub to
  return -ENOENT instead of 0, and dropped the count == 0 check in
  gpiod_get_array().
- In patch 6/7, separated array_info assignment from declaration in
  gpio_descs_check_fastpath() immediately before NULL check to preserve
  reverse-christmas-tree order.
- Added patch 7/7 switching fastpath bitmaps in struct gpio_array to
  individual bitmap_zalloc() and bitmap_free() calls per Andy's review
  feedback.
- Link to v1: https://patch.msgid.link/20261021190212.2237804-1-dmitry.torokhov@gmail.com

---
Dmitry Torokhov (8):
      gpiolib: fix GPIO descriptor leak in gpiod_get_array()
      gpiolib: fix fast-path cancellation in gpiod_get_array()
      gpiolib: of: return -ENOENT from of_gpio_count() stub
      gpiolib: add support for scope-based management of GPIO descriptors
      gpiolib: use __free(gpiod_put_array) in gpiod_get_array()
      gpiolib: avoid krealloc() in gpiod_get_array()
      gpiolib: use bitmap_zalloc() for fastpath bitmaps
      gpiolib: use %*pb format specifier when printing array masks

 drivers/gpio/gpiolib-of.h     |   2 +-
 drivers/gpio/gpiolib.c        | 225 ++++++++++++++++++++++++------------------
 drivers/gpio/gpiolib.h        |   2 +-
 include/linux/gpio/consumer.h |   4 +
 4 files changed, 135 insertions(+), 98 deletions(-)
---
base-commit: ddfe51b0a0f5dc9e415cc2c8ad8db17532dd426b
change-id: 20261021-b4-gpiolib-free-74d92ea91503

Thanks.

-- 
Dmitry


             reply	other threads:[~2026-11-06  6:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06  6:30 Dmitry Torokhov [this message]
2026-11-06  6:30 ` [PATCH v3 1/8] gpiolib: fix GPIO descriptor leak in gpiod_get_array() Dmitry Torokhov
2026-11-06  6:30 ` [PATCH v3 2/8] gpiolib: fix fast-path cancellation " Dmitry Torokhov
2026-11-06  6:30 ` [PATCH v3 3/8] gpiolib: of: return -ENOENT from of_gpio_count() stub Dmitry Torokhov
2026-11-06  6:30 ` [PATCH v3 4/8] gpiolib: add support for scope-based management of GPIO descriptors Dmitry Torokhov
2026-11-06  6:30 ` [PATCH v3 5/8] gpiolib: use __free(gpiod_put_array) in gpiod_get_array() Dmitry Torokhov
2026-11-06  6:30 ` [PATCH v3 6/8] gpiolib: avoid krealloc() " Dmitry Torokhov
2026-11-06 13:56   ` Linus Walleij
2026-11-06  6:30 ` [PATCH v3 7/8] gpiolib: use bitmap_zalloc() for fastpath bitmaps Dmitry Torokhov
2026-11-06 13:56   ` Linus Walleij
2026-11-06  6:30 ` [PATCH v3 8/8] gpiolib: use %*pb format specifier when printing array masks Dmitry Torokhov
2026-11-06 13:57   ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261105-b4-gpiolib-free-v3-0-bb47ad58642d@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=brgl@kernel.org \
    --cc=jmkrzyszt@gmail.com \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®