From: Pufan Jin <cyan2254650260@gmail.com>
To: Bartosz Golaszewski <brgl@kernel.org>,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Linus Walleij <linusw@kernel.org>,
Philipp Zabel <p.zabel@pengutronix.de>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/5] gpiolib: shared: match reset-gpio against translated entry offset
Date: Sat, 5 Dec 2026 14:43:53 +0800 [thread overview]
Message-ID: <20261205064355.137581-4-cyan2254650260@gmail.com> (raw)
In-Reply-To: <20261205064355.137581-1-cyan2254650260@gmail.com>
gpiochip_setup_shared() translates entry->offset via gc->of_xlate() when
an OF GPIO chip is registered.
gpio_shared_dev_is_reset_gpio() parses the consumer's devicetree
reset-gpios specifier and compares ref_args.args[0] with
aux_args.args[0] from the reset-gpio software node. When reset-gpio
stores the of_xlate()-translated hardware offset in its software node,
this comparison mismatches on controllers with custom of_xlate()
callbacks such as tegra186-gpio, and gpio_shared_add_proxy_lookup()
hits WARN_ON(1) and returns -ENOENT.
Check ref->is_reset_gpio and compare aux_args.args[0] against
entry->offset under entry->lock.
Signed-off-by: Pufan Jin <cyan2254650260@gmail.com>
---
drivers/gpio/gpiolib-shared.c | 70 ++++++++---------------------------
1 file changed, 16 insertions(+), 54 deletions(-)
diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
index f34315a205..1753524544 100644
--- a/drivers/gpio/gpiolib-shared.c
+++ b/drivers/gpio/gpiolib-shared.c
@@ -361,14 +361,16 @@ static bool gpio_shared_dev_is_reset_gpio(struct device *consumer,
struct gpio_shared_ref *ref)
{
struct fwnode_handle *reset_fwnode = dev_fwnode(consumer);
- struct fwnode_reference_args ref_args, aux_args;
+ struct fwnode_reference_args aux_args;
struct device *parent = consumer->parent;
- struct gpio_shared_ref *real_ref;
bool match;
int ret;
lockdep_assert_held(&ref->lock);
+ if (!ref->is_reset_gpio)
+ return false;
+
/* The reset-gpio device must have a parent AND a firmware node. */
if (!parent || !reset_fwnode)
return false;
@@ -380,62 +382,22 @@ static bool gpio_shared_dev_is_reset_gpio(struct device *consumer,
if (!device_match_fwnode(parent, entry->fwnode))
return false;
- /*
- * Now we need to find the actual pin we want to assign to this
- * reset-gpio device. To that end: iterate over the list of references
- * of this entry and see if there's one, whose reset-gpios property's
- * arguments match the ones from this consumer's node.
- */
- list_for_each_entry(real_ref, &entry->refs, list) {
- if (real_ref == ref)
- continue;
-
- guard(mutex)(&real_ref->lock);
-
- if (!real_ref->fwnode)
- continue;
-
- /*
- * The device associated with the shared reference's firmware
- * node is the consumer of the reset control exposed by the
- * reset-gpio device. It must have a "reset-gpios" property
- * that's referencing the entry's firmware node.
- *
- * The reference args must agree between the real consumer and
- * the auxiliary reset-gpio device.
- */
- ret = fwnode_property_get_reference_args(real_ref->fwnode,
- "reset-gpios",
- NULL, 2, 0, &ref_args);
- if (ret)
- continue;
-
- ret = fwnode_property_get_reference_args(reset_fwnode, "reset-gpios",
- NULL, 2, 0, &aux_args);
- if (ret) {
- fwnode_handle_put(ref_args.fwnode);
- continue;
- }
-
- match = ((ref_args.fwnode == entry->fwnode) &&
- (aux_args.fwnode == entry->fwnode) &&
- (ref_args.args[0] == aux_args.args[0]));
+ ret = fwnode_property_get_reference_args(reset_fwnode, "reset-gpios",
+ NULL, 2, 0, &aux_args);
+ if (ret)
+ return false;
- fwnode_handle_put(ref_args.fwnode);
- fwnode_handle_put(aux_args.fwnode);
+ scoped_guard(mutex, &entry->lock)
+ match = (aux_args.fwnode == entry->fwnode) &&
+ (aux_args.args[0] == entry->offset);
- if (!match)
- continue;
+ fwnode_handle_put(aux_args.fwnode);
- /*
- * Reuse the fwnode of the real device, next time we'll use it
- * in the normal path.
- */
- ref->fwnode = fwnode_handle_get(reset_fwnode);
- return true;
- }
+ if (!match)
+ return false;
- return false;
+ ref->fwnode = fwnode_handle_get(reset_fwnode);
+ return true;
}
#else
static bool gpio_shared_dev_is_reset_gpio(struct device *consumer,
--
2.56.1
next prev parent reply other threads:[~2026-12-05 6:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 6:43 [PATCH v2 0/5] gpiolib / reset: resolve GPIO specifiers via gpiolib Pufan Jin
2026-12-05 6:43 ` [PATCH v2 1/5] gpiolib: add gpio_device_find_by_fwnode_args() Pufan Jin
2026-12-05 6:43 ` [PATCH v2 2/5] gpiolib: swnode: prefer matching parent gpio_device Pufan Jin
2026-12-05 6:43 ` Pufan Jin [this message]
2026-12-05 6:43 ` [PATCH v2 4/5] reset: gpio: derive fwnode_reset_n_cells from platform data Pufan Jin
2026-12-05 6:43 ` [PATCH v2 5/5] reset: core: translate GPIO specifier via gpio_device_find_by_fwnode_args() Pufan Jin
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=20261205064355.137581-4-cyan2254650260@gmail.com \
--to=cyan2254650260@gmail.com \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=brgl@kernel.org \
--cc=krzk@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
/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