From: Adrian Ambrozewicz <aambrozewicz@nvidia.com>
To: Bartosz Golaszewski <brgl@kernel.org>, Linus Walleij <linusw@kernel.org>
Cc: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Kent Gibson <warthog618@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Mika Westerberg <westeri@kernel.org>,
Herve Codina <herve.codina@bootlin.com>,
linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/3] gpiolib: shared: remove the proxies before releasing the shared line
Date: Fri, 27 Nov 2026 09:49:25 +0200 [thread overview]
Message-ID: <20261127-gpiolib-ownlines-v2-1-aambrozewicz@nvidia.com> (raw)
In-Reply-To: <20261127-gpiolib-ownlines-v2-0-aambrozewicz@nvidia.com>
Since commit 4918cc05137c ("gpio: shared: propagate configuration to
pinctrl"), gpio_device_teardown_shared() releases the shared line with
gpiod_free_commit() and only then removes the proxy devices. Until a
proxy is gone, its consumers can still drive the line through the
parent chip. The late error path of gpiochip_add_data_with_key()
calls gpio_device_teardown_shared() with the chip live, so there they
can. gpiochip_remove() calls it after numbing the chip, so those calls
fail until "gpiolib: release the chip's own lines before numbing it on
removal" moves the call ahead of the numbing.
Remove the proxies first, then release the line.
With that patch and without this one, a test-only log on a shared
gpio-sim line showed both proxies still bound when the line was
released; with this one, none.
Fixes: 4918cc05137c ("gpio: shared: propagate configuration to pinctrl")
Signed-off-by: Adrian Ambrozewicz <aambrozewicz@nvidia.com>
---
drivers/gpio/gpiolib-shared.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
index f34315a2059a..c1e346a56177 100644
--- a/drivers/gpio/gpiolib-shared.c
+++ b/drivers/gpio/gpiolib-shared.c
@@ -611,9 +611,6 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
if (!device_match_fwnode(&gdev->dev, entry->fwnode))
continue;
- scoped_guard(mutex, &entry->lock)
- gpiod_free_commit(&gdev->descs[entry->offset]);
-
list_for_each_entry(ref, &entry->refs, list) {
if (ref->lookup) {
gpiod_remove_lookup_table(ref->lookup);
@@ -625,6 +622,10 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
gpio_shared_remove_adev(&ref->adev);
}
+
+ /* Release the line only once no proxy can drive it. */
+ scoped_guard(mutex, &entry->lock)
+ gpiod_free_commit(&gdev->descs[entry->offset]);
}
}
--
2.43.0
next prev parent reply other threads:[~2026-11-27 7:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 7:49 [PATCH v2 0/3] gpiolib: free the lines a chip owns before numbing it Adrian Ambrozewicz
2026-11-27 7:49 ` Adrian Ambrozewicz [this message]
2026-11-27 7:49 ` [PATCH v2 2/3] gpiolib: release the chip's own lines before numbing it on removal Adrian Ambrozewicz
2026-11-27 7:49 ` [PATCH v2 3/3] gpiolib: release user space's lines when adding the chip fails late Adrian Ambrozewicz
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=20261127-gpiolib-ownlines-v2-1-aambrozewicz@nvidia.com \
--to=aambrozewicz@nvidia.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=brgl@kernel.org \
--cc=herve.codina@bootlin.com \
--cc=linusw@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=warthog618@gmail.com \
--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 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®