[PATCH] reset: gpio: recreate auxiliary device when backing GPIO chip is replaced

From: Ajay Kumar Nandam

Date: Thu Dec 03 2026 - 04:47:32 EST


The reset-gpio auxiliary device is parented to the GPIO chip that
provides the reset line. A GPIO provider can be removed and later
recreated on the same firmware node, while the reset-gpio lookup entry
remains.

During an ADSP restart this can happen when the GPIO provider is removed
and registered again. The current code reparents the existing auxiliary
device using device_del() followed by device_add(), but device_del()
marks the underlying struct device dead. Re-adding the same device does
not clear that state, so it cannot bind again.

Delete and release the old auxiliary device when its GPIO provider
changes, then allocate and register a new one against the new parent.
Keep the allocated ID in the lookup entry so it remains stable across
auxiliary-device recreations.

If that recreation fails, the lookup entry is left with no auxiliary
device. Treat a NULL auxiliary device the same as a provider change on
the next lookup, instead of dereferencing it, so the device is simply
recreated again rather than crashing.

Co-developed-by: Ravi Hothi <ravi.hothi@xxxxxxxxxxxxxxxx>
Signed-off-by: Ravi Hothi <ravi.hothi@xxxxxxxxxxxxxxxx>
Signed-off-by: Ajay Kumar Nandam <ajay.nandam@xxxxxxxxxxxxxxxx>
---
This is a single, standalone fix in the reset-gpio auxiliary device
code; it does not depend on anything else and has no series
relationship to other work I have sent.

I ran into this while testing SoundWire controller/peripheral restart
on a QCM6490-based board, where a GPIO-backed reset line's chip gets
torn down and replaced across an audio-subsystem restart. The second
replacement left the reset-gpio auxiliary device permanently unbound,
even though its probe function ran again without error.

While fixing that, I also found and fixed an adjacent failure-recovery
gap: if the auxiliary-device recreation itself fails, the next lookup
for the same GPIO provider would dereference a NULL auxiliary device.
---
drivers/reset/core.c | 57 +++++++++++++++++++++++++++++++++++++---------------
1 file changed, 41 insertions(+), 16 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 0bff49d9b558..3d9c936d8021 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -87,13 +87,16 @@ struct reset_control_array {
* @ref_args: Reference to the reset controller with all the args like GPIO number
* @swnode: Software node containing the reference to the GPIO provider
* @list: list entry for the reset_gpio_lookup_list
- * @adev: Auxiliary device representing the reset controller
+ * @adev: Auxiliary device for the current GPIO provider, or NULL if it still
+ * needs to be (re)created
+ * @id: Auxiliary device ID kept across provider replacements
*/
struct reset_gpio_lookup {
struct fwnode_reference_args ref_args;
struct fwnode_handle *swnode;
struct list_head list;
- struct auxiliary_device adev;
+ struct auxiliary_device *adev;
+ int id;
};

static const char *rcdev_name(struct reset_controller_dev *rcdev)
@@ -1022,20 +1025,21 @@ static void reset_control_put_internal(struct reset_control *rstc)

static void reset_gpio_aux_device_release(struct device *dev)
{
- WARN(1, "reset-gpio device %s should never have been removed", dev_name(dev));
+ kfree(to_auxiliary_dev(dev));
}

+/* Recreate the auxiliary device when the GPIO provider changes. */
static int reset_create_gpio_aux_device(struct reset_gpio_lookup *rgpio_dev,
struct device *parent)
{
- struct auxiliary_device *adev = &rgpio_dev->adev;
- int ret, id;
+ struct auxiliary_device *adev;
+ int ret;

- id = ida_alloc(&reset_gpio_ida, GFP_KERNEL);
- if (id < 0)
+ adev = kzalloc_obj(*adev);
+ if (!adev)
return -ENOMEM;

- adev->id = id;
+ adev->id = rgpio_dev->id;
adev->name = "gpio";
adev->dev.parent = parent;
adev->dev.platform_data = &rgpio_dev->ref_args;
@@ -1044,20 +1048,28 @@ static int reset_create_gpio_aux_device(struct reset_gpio_lookup *rgpio_dev,

ret = auxiliary_device_init(adev);
if (ret) {
- ida_free(&reset_gpio_ida, id);
+ kfree(adev);
return ret;
}

ret = __auxiliary_device_add(adev, "reset");
if (ret) {
auxiliary_device_uninit(adev);
- ida_free(&reset_gpio_ida, id);
return ret;
}

+ rgpio_dev->adev = adev;
+
return 0;
}

+static void reset_destroy_gpio_aux_device(struct reset_gpio_lookup *rgpio_dev)
+{
+ auxiliary_device_delete(rgpio_dev->adev);
+ auxiliary_device_uninit(rgpio_dev->adev);
+ rgpio_dev->adev = NULL;
+}
+
static void reset_gpio_add_devlink(struct fwnode_handle *fwnode,
struct reset_gpio_lookup *rgpio_dev)
{
@@ -1071,7 +1083,7 @@ static void reset_gpio_add_devlink(struct fwnode_handle *fwnode,
*/
consumer = get_dev_from_fwnode(fwnode);
if (consumer) {
- if (!device_link_add(consumer, &rgpio_dev->adev.dev,
+ if (!device_link_add(consumer, &rgpio_dev->adev->dev,
DL_FLAG_AUTOREMOVE_CONSUMER))
pr_warn("Failed to create a device link between reset-gpio and its consumer");

@@ -1150,19 +1162,24 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,

guard(mutex)(&reset_gpio_lookup_mutex);

+ parent = gpio_device_to_device(gdev);
+
list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) {
if (fwnode_reference_args_equal(args, &rgpio_dev->ref_args)) {
- /*
- * Already on the list, create the device link
- * and stop here.
- */
+ /* Recreate the auxiliary device if the provider changed. */
+ if (!rgpio_dev->adev || rgpio_dev->adev->dev.parent != parent) {
+ if (rgpio_dev->adev)
+ reset_destroy_gpio_aux_device(rgpio_dev);
+ ret = reset_create_gpio_aux_device(rgpio_dev, parent);
+ if (ret)
+ return ret;
+ }
reset_gpio_add_devlink(fwnode, rgpio_dev);
return 0;
}
}

lflags = GPIO_PERSISTENT | (flags & GPIO_ACTIVE_LOW);
- parent = gpio_device_to_device(gdev);
properties[prop++] = PROPERTY_ENTRY_STRING("compatible", "reset-gpio");
properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags);

@@ -1171,6 +1188,12 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
if (!rgpio_dev)
return -ENOMEM;

+ rgpio_dev->id = ida_alloc(&reset_gpio_ida, GFP_KERNEL);
+ if (rgpio_dev->id < 0) {
+ ret = rgpio_dev->id;
+ goto err_free_rgpio_dev;
+ }
+
rgpio_dev->ref_args = *args;
/*
* We keep the fwnode_handle reference, but ref_args.fwnode is put at
@@ -1198,6 +1221,8 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
fwnode_remove_software_node(rgpio_dev->swnode);
err_put_fwnode:
fwnode_handle_put(rgpio_dev->ref_args.fwnode);
+ ida_free(&reset_gpio_ida, rgpio_dev->id);
+err_free_rgpio_dev:
kfree(rgpio_dev);

return ret;

---
base-commit: d138596e9f822033490b2e577ec2ea64f2aa246c
change-id: 20261203-ak-gt-reset-gpio-aux-recreate-851dea7624f6

Best regards,
--
Ajay Kumar Nandam <ajay.nandam@xxxxxxxxxxxxxxxx>