From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Mika Westerberg <westeri@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Mathias Nyman <mathias.nyman@linux.intel.com>,
linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by()
Date: Thu, 3 Dec 2026 20:55:00 +0000 [thread overview]
Message-ID: <20261203205606.3905705-3-lee@kernel.org> (raw)
In-Reply-To: <20261203205606.3905705-1-lee@kernel.org>
acpi_dev_gpio_irq_wake_get_by() obtains a descriptor from
__acpi_find_gpio() without holding gpio_devices_srcu or acquiring a
reference to desc->gdev. Because acpi_get_gpiod() releases its
gpio_device reference before returning, a concurrent GPIO controller
unbind can free gdev and gdev->descs before gpiod_to_irq() and the
subsequent descriptor configuration helpers run.
Expose gpio_devices_srcu internally within gpiolib, guard the
__acpi_find_gpio() lookup with gpio_devices_srcu, and acquire a scoped
gpio_device reference via gpio_device_get() before leaving the SRCU
read-side critical section.
Fixes: e348544f7994 ("gpio: protect the list of GPIO devices with SRCU")
Closes: https://sashiko.dev/#/bug/linux-97d822c4-1532-47ad-ab8d-717448607bc1
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/gpio/gpiolib-acpi-core.c | 9 +++++++--
drivers/gpio/gpiolib.c | 2 +-
drivers/gpio/gpiolib.h | 2 ++
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
index f94f456dbe5f..fccb4fe71e80 100644
--- a/drivers/gpio/gpiolib-acpi-core.c
+++ b/drivers/gpio/gpiolib-acpi-core.c
@@ -1027,10 +1027,15 @@ int acpi_dev_gpio_irq_wake_get_by(struct acpi_device *adev, const char *con_id,
for (i = 0, idx = 0; idx <= index; i++) {
struct acpi_gpio_info info = {};
+ struct gpio_device *gdev __free(gpio_device_put) = NULL;
struct gpio_desc *desc;
- /* Ignore -EPROBE_DEFER, it only matters if idx matches */
- desc = __acpi_find_gpio(fwnode, con_id, i, true, &info);
+ scoped_guard(srcu, &gpio_devices_srcu) {
+ /* Ignore -EPROBE_DEFER, it only matters if idx matches */
+ desc = __acpi_find_gpio(fwnode, con_id, i, true, &info);
+ if (!IS_ERR(desc))
+ gdev = gpio_device_get(desc->gdev);
+ }
if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER)
return PTR_ERR(desc);
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 22c9288fea10..8843b2175caf 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -102,7 +102,7 @@ static LIST_HEAD(gpio_devices);
/* Protects the GPIO device list against concurrent modifications. */
static DEFINE_MUTEX(gpio_devices_lock);
/* Ensures coherence during read-only accesses to the list of GPIO devices. */
-DEFINE_STATIC_SRCU(gpio_devices_srcu);
+DEFINE_SRCU(gpio_devices_srcu);
const char *const gpio_suffixes[] = { "gpios", "gpio", NULL };
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 8dd8ea747f8a..c4a390231086 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -283,6 +283,8 @@ int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev);
struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum);
const char *gpiod_get_label(struct gpio_desc *desc);
+extern struct srcu_struct gpio_devices_srcu;
+
/* With descriptor prefix */
#define __gpiod_pr(level, desc, fmt, ...) \
--
2.56.1.911.g883d8bcb20-goog
next prev parent reply other threads:[~2026-12-03 20:56 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 20:54 ` Lee Jones
2026-12-03 20:54 ` [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe() Lee Jones
2026-12-03 20:55 ` Lee Jones [this message]
2026-12-04 11:35 ` [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by() Andy Shevchenko
2026-12-03 20:55 ` [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind Lee Jones
2026-12-03 21:13 ` sashiko-bot
2026-12-03 22:10 ` Andrew Lunn
2026-12-04 0:05 ` Rosen Penev
2026-12-04 1:17 ` Andrew Lunn
2026-12-05 3:12 ` Rosen Penev
2026-12-03 20:55 ` [PATCH 04/10] gpio: rockchip: Unregister gpiochip on pin-range lookup errors Lee Jones
2026-12-03 20:55 ` Lee Jones
2026-12-03 20:55 ` [PATCH 05/10] gpiolib: Avoid undersized array bitmap in set fastpath Lee Jones
2026-12-03 20:55 ` [PATCH 06/10] gpio: mlxbf2: Embed context save registers to prevent suspend NULL dereference Lee Jones
2026-12-03 20:55 ` [PATCH 07/10] gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg Lee Jones
2026-12-04 11:36 ` Andy Shevchenko
2026-12-03 20:55 ` [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler Lee Jones
2026-12-03 21:17 ` sashiko-bot
2026-12-03 20:55 ` [PATCH 09/10] gpio: mpsse: Allocate DMA-safe buffer in mpsse_write() Lee Jones
2026-12-03 20:55 ` [PATCH 10/10] gpio: pcie-idio-24: Fix COS_ENABLE_RISING bit definition Lee Jones
2026-12-04 21:02 ` William Breathitt Gray
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=20261203205606.3905705-3-lee@kernel.org \
--to=lee@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brgl@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=stable@vger.kernel.org \
--cc=westeri@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.