From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
To: Linus Walleij <linusw@kernel.org>, Bartosz Golaszewski <brgl@kernel.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Subject: [PATCH 1/3] gpiolib: allow multiple lookup tables per consumer
Date: Mon, 22 Dec 2025 11:01:26 +0100 [thread overview]
Message-ID: <20251222-gpio-shared-reset-gpio-proxy-v1-1-8d4bba7d8c14@oss.qualcomm.com> (raw)
In-Reply-To: <20251222-gpio-shared-reset-gpio-proxy-v1-0-8d4bba7d8c14@oss.qualcomm.com>
The GPIO machine lookup mechanism dates back to old ARM board files
where lookup tables would all be defined in a single place. Since then,
lookup tables have also been used to address various DT and ACPI quirks
like missing GPIOs and - as of recently - setting up shared GPIO proxy
devices.
The lookup itself stops when we find the first matching table for a
consumer and - if it doesn't contain the right entry - the lookup fails.
Since the tables can now be defined in multiple places and we can't know
how many there are, effectively limiting a consumer to only a single
lookup table is no longer viable.
Rework the code to always look through all tables matching the consumer.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpiolib.c | 91 +++++++++++++++++++++++++++++++-------------------
1 file changed, 56 insertions(+), 35 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 91e0c384f34ae5c0ed61ccd3a978685d4f72e867..6d583b3b07bb5c3e5886ced53deca7cd02460890 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4508,45 +4508,41 @@ void gpiod_remove_hogs(struct gpiod_hog *hogs)
}
EXPORT_SYMBOL_GPL(gpiod_remove_hogs);
-static struct gpiod_lookup_table *gpiod_find_lookup_table(struct device *dev)
+static bool gpiod_match_lookup_table(struct device *dev,
+ const struct gpiod_lookup_table *table)
{
const char *dev_id = dev ? dev_name(dev) : NULL;
- struct gpiod_lookup_table *table;
- list_for_each_entry(table, &gpio_lookup_list, list) {
- if (table->dev_id && dev_id) {
- /*
- * Valid strings on both ends, must be identical to have
- * a match
- */
- if (!strcmp(table->dev_id, dev_id))
- return table;
- } else {
- /*
- * One of the pointers is NULL, so both must be to have
- * a match
- */
- if (dev_id == table->dev_id)
- return table;
- }
+ lockdep_assert_held(&gpio_lookup_lock);
+
+ if (table->dev_id && dev_id) {
+ /*
+ * Valid strings on both ends, must be identical to have
+ * a match
+ */
+ if (!strcmp(table->dev_id, dev_id))
+ return true;
+ } else {
+ /*
+ * One of the pointers is NULL, so both must be to have
+ * a match
+ */
+ if (dev_id == table->dev_id)
+ return true;
}
- return NULL;
+ return false;
}
-static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
- unsigned int idx, unsigned long *flags)
+static struct gpio_desc *gpio_desc_table_match(struct device *dev, const char *con_id,
+ unsigned int idx, unsigned long *flags,
+ struct gpiod_lookup_table *table)
{
- struct gpio_desc *desc = ERR_PTR(-ENOENT);
- struct gpiod_lookup_table *table;
+ struct gpio_desc *desc;
struct gpiod_lookup *p;
struct gpio_chip *gc;
- guard(mutex)(&gpio_lookup_lock);
-
- table = gpiod_find_lookup_table(dev);
- if (!table)
- return desc;
+ lockdep_assert_held(&gpio_lookup_lock);
for (p = &table->table[0]; p->key; p++) {
/* idx must always match exactly */
@@ -4600,6 +4596,29 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
return desc;
}
+ return NULL;
+}
+
+static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
+ unsigned int idx, unsigned long *flags)
+{
+ struct gpio_desc *desc = ERR_PTR(-ENOENT);
+ struct gpiod_lookup_table *table;
+
+ guard(mutex)(&gpio_lookup_lock);
+
+ list_for_each_entry(table, &gpio_lookup_list, list) {
+ if (!gpiod_match_lookup_table(dev, table))
+ continue;
+
+ desc = gpio_desc_table_match(dev, con_id, idx, flags, table);
+ if (!desc)
+ continue;
+
+ /* On IS_ERR() or match. */
+ return desc;
+ }
+
return desc;
}
@@ -4610,14 +4629,16 @@ static int platform_gpio_count(struct device *dev, const char *con_id)
unsigned int count = 0;
scoped_guard(mutex, &gpio_lookup_lock) {
- table = gpiod_find_lookup_table(dev);
- if (!table)
- return -ENOENT;
+ list_for_each_entry(table, &gpio_lookup_list, list) {
+ if (!gpiod_match_lookup_table(dev, table))
+ continue;
- for (p = &table->table[0]; p->key; p++) {
- if ((con_id && p->con_id && !strcmp(con_id, p->con_id)) ||
- (!con_id && !p->con_id))
- count++;
+ for (p = &table->table[0]; p->key; p++) {
+ if ((con_id && p->con_id &&
+ !strcmp(con_id, p->con_id)) ||
+ (!con_id && !p->con_id))
+ count++;
+ }
}
}
--
2.47.3
next prev parent reply other threads:[~2025-12-22 10:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-22 10:01 [PATCH 0/3] gpio: shared: close remaining gaps Bartosz Golaszewski
2025-12-22 10:01 ` Bartosz Golaszewski [this message]
2025-12-22 10:01 ` [PATCH 2/3] gpio: shared: verify con_id when adding proxy lookup Bartosz Golaszewski
2025-12-22 10:01 ` [PATCH 3/3] gpio: shared: allow sharing a reset-gpios pin between reset-gpio and gpiolib Bartosz Golaszewski
[not found] ` <CGME20260105115023eucas1p1af1f8e80041f94843beb664966894fb9@eucas1p1.samsung.com>
2026-01-05 11:50 ` Marek Szyprowski
2026-01-05 12:28 ` Bartosz Golaszewski
2026-01-05 17:26 ` Marek Szyprowski
2026-01-05 18:16 ` Marek Szyprowski
2026-01-06 10:55 ` Bartosz Golaszewski
2026-01-05 15:53 ` Bartosz Golaszewski
2026-01-06 12:21 ` Mark Brown
2026-01-06 12:25 ` Bartosz Golaszewski
2026-01-08 15:46 ` Mark Brown
2026-01-08 15:52 ` Bartosz Golaszewski
2026-01-08 16:29 ` Mark Brown
2026-01-08 18:04 ` Bartosz Golaszewski
2026-01-02 9:34 ` [PATCH 0/3] gpio: shared: close remaining gaps Bartosz Golaszewski
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=20251222-gpio-shared-reset-gpio-proxy-v1-1-8d4bba7d8c14@oss.qualcomm.com \
--to=bartosz.golaszewski@oss.qualcomm.com \
--cc=brgl@kernel.org \
--cc=linus.walleij@linaro.org \
--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®