[PATCH v2 3/5] gpiolib: shared: match reset-gpio against translated entry offset

From: Pufan Jin

Date: Sat Dec 05 2026 - 01:44:24 EST


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@xxxxxxxxx>
---
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