* [PATCH] reset: gpio: Keep reset-gpio device under the GPIO controller device
@ 2026-12-01 16:28 ` Birk Skyum via B4 Relay
0 siblings, 0 replies; 4+ messages in thread
From: Birk Skyum @ 2026-12-01 16:28 UTC (permalink / raw)
To: Philipp Zabel
Cc: linux-kernel, Bartosz Golaszewski, Krzysztof Kozlowski,
linux-gpio, linux-arm-msm, Birk Skyum
reset-gpio auxiliary devices are persistent subsystem devices that are
never removed, but they are created as children of the GPIO device
(gpiochipN). That GPIO device is unregistered whenever the GPIO
controller's driver unbinds and recreated when it binds again.
On a Lenovo Yoga Slim 7x (X1E80100), the WSA884x speaker amplifiers
share reset GPIOs on the LPASS LPI pin controller. Because that
controller depends on clocks supplied by the audio DSP, it unbinds and
rebinds whenever the ADSP restarts (such as after crash recovery,
driver reload, or resuming from hibernation). The reset-gpio auxiliary
devices are then left attached to the deleted GPIO device, subsequent
probes fail with "really_probe: driver_sysfs_add failed", the speakers
never acquire their reset line, and the sound card cannot return.
Parent the reset-gpio auxiliary device under the GPIO device's parent
(the GPIO controller device, which persists across driver unbind/rebind)
when available, and add a DL_FLAG_AUTOPROBE_CONSUMER device link to it
so the reset-gpio driver unbinds with the controller and probes again
once it returns. Tested on a Lenovo Yoga Slim 7x across ADSP reloads
and five consecutive hibernation cycles.
Fixes: 46dae84a90f9 ("reset: make the provider of reset-gpios the parent of the reset device")
Signed-off-by: Birk Skyum <birk.skyum@pm.me>
---
drivers/reset/core.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 38e189d04..09bb7784c 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -1015,7 +1015,7 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
struct property_entry properties[3] = { };
unsigned int offset, flags, lflags;
struct reset_gpio_lookup *rgpio_dev;
- struct device *parent;
+ struct device *gdev_dev, *parent;
int ret, prop = 0;
/*
@@ -1070,9 +1070,20 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
}
lflags = GPIO_PERSISTENT | (flags & GPIO_ACTIVE_LOW);
- parent = gpio_device_to_device(gdev);
+ gdev_dev = gpio_device_to_device(gdev);
properties[prop++] = PROPERTY_ENTRY_STRING("compatible", "reset-gpio");
- properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags);
+ properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", gdev_dev->fwnode, offset, lflags);
+
+ /*
+ * The reset-gpio device is never removed, but the GPIO device goes
+ * away whenever the GPIO controller's driver unbinds, for example the
+ * LPASS pin controller when the audio DSP restarts. A reset-gpio
+ * device left under the old GPIO device can never bind again
+ * ("driver_sysfs_add failed"). Put it under the device that provides
+ * the GPIO controller instead, which stays, and link it to that
+ * device below so it follows the controller's driver.
+ */
+ parent = gdev_dev->parent ?: gdev_dev;
/* Not freed on success, because it is persisent subsystem data. */
rgpio_dev = kzalloc_obj(*rgpio_dev);
@@ -1097,6 +1108,17 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
if (ret)
goto err_del_swnode;
+ /*
+ * Unbind when the GPIO controller's driver unbinds and probe again
+ * when it is back, so the reset controller never holds GPIO
+ * descriptors of a removed chip.
+ */
+ if (parent != gdev_dev &&
+ !device_link_add(&rgpio_dev->adev.dev, parent,
+ DL_FLAG_AUTOPROBE_CONSUMER))
+ pr_warn("Failed to link reset-gpio device %s to its GPIO controller\n",
+ dev_name(&rgpio_dev->adev.dev));
+
reset_gpio_add_devlink(fwnode, rgpio_dev);
list_add(&rgpio_dev->list, &reset_gpio_lookup_list);
---
base-commit: ef922b721a5e99348fc1f5801fdeb427ee14ee9f
change-id: 20261201-reset-gpio-parent-devlink-4b1149416a5f
Best regards,
--
Birk Skyum <birk.skyum@pm.me>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] reset: gpio: Keep reset-gpio device under the GPIO controller device
@ 2026-12-01 16:28 ` Birk Skyum via B4 Relay
0 siblings, 0 replies; 4+ messages in thread
From: Birk Skyum via B4 Relay @ 2026-12-01 16:28 UTC (permalink / raw)
To: Philipp Zabel
Cc: linux-kernel, Bartosz Golaszewski, Krzysztof Kozlowski,
linux-gpio, linux-arm-msm, Birk Skyum
From: Birk Skyum <birk.skyum@pm.me>
reset-gpio auxiliary devices are persistent subsystem devices that are
never removed, but they are created as children of the GPIO device
(gpiochipN). That GPIO device is unregistered whenever the GPIO
controller's driver unbinds and recreated when it binds again.
On a Lenovo Yoga Slim 7x (X1E80100), the WSA884x speaker amplifiers
share reset GPIOs on the LPASS LPI pin controller. Because that
controller depends on clocks supplied by the audio DSP, it unbinds and
rebinds whenever the ADSP restarts (such as after crash recovery,
driver reload, or resuming from hibernation). The reset-gpio auxiliary
devices are then left attached to the deleted GPIO device, subsequent
probes fail with "really_probe: driver_sysfs_add failed", the speakers
never acquire their reset line, and the sound card cannot return.
Parent the reset-gpio auxiliary device under the GPIO device's parent
(the GPIO controller device, which persists across driver unbind/rebind)
when available, and add a DL_FLAG_AUTOPROBE_CONSUMER device link to it
so the reset-gpio driver unbinds with the controller and probes again
once it returns. Tested on a Lenovo Yoga Slim 7x across ADSP reloads
and five consecutive hibernation cycles.
Fixes: 46dae84a90f9 ("reset: make the provider of reset-gpios the parent of the reset device")
Signed-off-by: Birk Skyum <birk.skyum@pm.me>
---
drivers/reset/core.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 38e189d04..09bb7784c 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -1015,7 +1015,7 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
struct property_entry properties[3] = { };
unsigned int offset, flags, lflags;
struct reset_gpio_lookup *rgpio_dev;
- struct device *parent;
+ struct device *gdev_dev, *parent;
int ret, prop = 0;
/*
@@ -1070,9 +1070,20 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
}
lflags = GPIO_PERSISTENT | (flags & GPIO_ACTIVE_LOW);
- parent = gpio_device_to_device(gdev);
+ gdev_dev = gpio_device_to_device(gdev);
properties[prop++] = PROPERTY_ENTRY_STRING("compatible", "reset-gpio");
- properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags);
+ properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", gdev_dev->fwnode, offset, lflags);
+
+ /*
+ * The reset-gpio device is never removed, but the GPIO device goes
+ * away whenever the GPIO controller's driver unbinds, for example the
+ * LPASS pin controller when the audio DSP restarts. A reset-gpio
+ * device left under the old GPIO device can never bind again
+ * ("driver_sysfs_add failed"). Put it under the device that provides
+ * the GPIO controller instead, which stays, and link it to that
+ * device below so it follows the controller's driver.
+ */
+ parent = gdev_dev->parent ?: gdev_dev;
/* Not freed on success, because it is persisent subsystem data. */
rgpio_dev = kzalloc_obj(*rgpio_dev);
@@ -1097,6 +1108,17 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
if (ret)
goto err_del_swnode;
+ /*
+ * Unbind when the GPIO controller's driver unbinds and probe again
+ * when it is back, so the reset controller never holds GPIO
+ * descriptors of a removed chip.
+ */
+ if (parent != gdev_dev &&
+ !device_link_add(&rgpio_dev->adev.dev, parent,
+ DL_FLAG_AUTOPROBE_CONSUMER))
+ pr_warn("Failed to link reset-gpio device %s to its GPIO controller\n",
+ dev_name(&rgpio_dev->adev.dev));
+
reset_gpio_add_devlink(fwnode, rgpio_dev);
list_add(&rgpio_dev->list, &reset_gpio_lookup_list);
---
base-commit: ef922b721a5e99348fc1f5801fdeb427ee14ee9f
change-id: 20261201-reset-gpio-parent-devlink-4b1149416a5f
Best regards,
--
Birk Skyum <birk.skyum@pm.me>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] reset: gpio: Keep reset-gpio device under the GPIO controller device
2026-12-01 16:28 ` Birk Skyum via B4 Relay
(?)
@ 2026-12-01 16:50 ` sashiko-bot
-1 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-01 16:50 UTC (permalink / raw)
To: Birk Skyum; +Cc: linux-gpio
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] reset: gpio: reparenting breaks gpio_shared_dev_is_reset_gpio()
match
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] reset: spurious WARN and use-after-free on
reset_create_gpio_aux_device() failure [1]
--
commit 890ede247418cae89ef97a10e0ba05a7fd77ed0d
Author: Birk Skyum <birk.skyum@pm.me>
reset: gpio: Keep reset-gpio device under the GPIO controller device
This commit parents reset-gpio auxiliary devices under the GPIO controller
device instead of the gpiochip device and adds a DL_FLAG_AUTOPROBE_CONSUMER
device link so the reset-gpio device unbinds and re-probes across GPIO
controller driver unbind and rebind cycles.
> diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> index 38e189d04d09b..09bb7784c877b 100644
> --- a/drivers/reset/core.c
> +++ b/drivers/reset/core.c
[ ... ]
> @@ -1070,9 +1070,20 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
> }
>
> lflags = GPIO_PERSISTENT | (flags & GPIO_ACTIVE_LOW);
> - parent = gpio_device_to_device(gdev);
> + gdev_dev = gpio_device_to_device(gdev);
> properties[prop++] = PROPERTY_ENTRY_STRING("compatible", "reset-gpio");
> - properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags);
> + properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", gdev_dev->fwnode, offset, lflags);
> +
> + /*
> + * The reset-gpio device is never removed, but the GPIO device goes
> + * away whenever the GPIO controller's driver unbinds, for example the
> + * LPASS pin controller when the audio DSP restarts. A reset-gpio
> + * device left under the old GPIO device can never bind again
> + * ("driver_sysfs_add failed"). Put it under the device that provides
> + * the GPIO controller instead, which stays, and link it to that
> + * device below so it follows the controller's driver.
> + */
> + parent = gdev_dev->parent ?: gdev_dev;
[Severity: High]
Does reparenting the reset-gpio auxiliary device to gdev_dev->parent break
shared GPIO lookup in gpio_shared_dev_is_reset_gpio() when the gpio_chip
has its own fwnode?
In gpiolib-shared, entry->fwnode is the firmware node of the GPIO
controller matched against &gdev->dev (which uses gc->fwnode when set),
and gpio_shared_dev_is_reset_gpio() expects the reset-gpio device's parent
to match that fwnode:
drivers/gpio/gpiolib-shared.c:gpio_shared_dev_is_reset_gpio() {
...
/*
* Parent of the reset-gpio auxiliary device is the GPIO chip whose
* fwnode we stored in the entry structure.
*/
if (!device_match_fwnode(parent, entry->fwnode))
return false;
...
}
On controllers where gc->fwnode differs from dev_fwnode(gc->parent) (such
as multi-bank pin controllers with per-bank child DT nodes),
device_match_fwnode() now checks gdev_dev->parent instead of gdev_dev and
returns false. When reset_gpio_probe() requests the shared reset GPIO,
gpio_shared_add_proxy_lookup() then hits WARN_ON(1) and fails the probe
with -ENOENT.
>
> /* Not freed on success, because it is persisent subsystem data. */
> rgpio_dev = kzalloc_obj(*rgpio_dev);
> @@ -1097,6 +1108,17 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
> if (ret)
> goto err_del_swnode;
[Severity: High]
This problem wasn't introduced by this patch, but if
reset_create_gpio_aux_device() fails in __auxiliary_device_add() after
auxiliary_device_init() has succeeded, can error cleanup trigger a
spurious WARN and a use-after-free [1]?
drivers/reset/core.c:reset_create_gpio_aux_device() {
...
adev->dev.release = reset_gpio_aux_device_release;
...
ret = auxiliary_device_init(adev);
if (ret) {
ida_free(&reset_gpio_ida, id);
return ret;
}
ret = __auxiliary_device_add(adev, "reset");
if (ret) {
auxiliary_device_uninit(adev);
ida_free(&reset_gpio_ida, id);
return ret;
}
}
auxiliary_device_uninit() calls put_device(), which invokes
reset_gpio_aux_device_release() and triggers its unconditional WARN(1,
...) without freeing rgpio_dev. __reset_add_reset_gpio_device() then
jumps to err_del_swnode and runs kfree(rgpio_dev) outside the device
release callback, causing a use-after-free in kobject_delayed_cleanup()
when CONFIG_DEBUG_KOBJECT_RELEASE is enabled.
[1] https://sashiko.dev/#/bug/linux-c613c5b7-1804-46c9-9911-ed5179103296
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-reset-gpio-parent-devlink-v1-1-5195e8b377c4@pm.me?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] reset: gpio: Keep reset-gpio device under the GPIO controller device
2026-12-01 16:28 ` Birk Skyum via B4 Relay
(?)
(?)
@ 2026-12-01 16:57 ` Philipp Zabel
-1 siblings, 0 replies; 4+ messages in thread
From: Philipp Zabel @ 2026-12-01 16:57 UTC (permalink / raw)
To: birk.skyum
Cc: linux-kernel, Bartosz Golaszewski, Krzysztof Kozlowski,
linux-gpio, linux-arm-msm
On Di, 2026-12-01 at 17:28 +0100, Birk Skyum via B4 Relay wrote:
> From: Birk Skyum <birk.skyum@pm.me>
>
> reset-gpio auxiliary devices are persistent subsystem devices that are
> never removed, but they are created as children of the GPIO device
> (gpiochipN). That GPIO device is unregistered whenever the GPIO
> controller's driver unbinds and recreated when it binds again.
>
> On a Lenovo Yoga Slim 7x (X1E80100), the WSA884x speaker amplifiers
> share reset GPIOs on the LPASS LPI pin controller. Because that
> controller depends on clocks supplied by the audio DSP, it unbinds and
> rebinds whenever the ADSP restarts (such as after crash recovery,
> driver reload, or resuming from hibernation). The reset-gpio auxiliary
> devices are then left attached to the deleted GPIO device, subsequent
> probes fail with "really_probe: driver_sysfs_add failed", the speakers
> never acquire their reset line, and the sound card cannot return.
>
> Parent the reset-gpio auxiliary device under the GPIO device's parent
> (the GPIO controller device, which persists across driver unbind/rebind)
> when available, and add a DL_FLAG_AUTOPROBE_CONSUMER device link to it
> so the reset-gpio driver unbinds with the controller and probes again
> once it returns. Tested on a Lenovo Yoga Slim 7x across ADSP reloads
> and five consecutive hibernation cycles.
>
> Fixes: 46dae84a90f9 ("reset: make the provider of reset-gpios the parent of the reset device")
> Signed-off-by: Birk Skyum <birk.skyum@pm.me>
> ---
> drivers/reset/core.c | 28 +++++++++++++++++++++++++---
> 1 file changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> index 38e189d04..09bb7784c 100644
> --- a/drivers/reset/core.c
> +++ b/drivers/reset/core.c
> @@ -1015,7 +1015,7 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
> struct property_entry properties[3] = { };
> unsigned int offset, flags, lflags;
> struct reset_gpio_lookup *rgpio_dev;
> - struct device *parent;
> + struct device *gdev_dev, *parent;
> int ret, prop = 0;
>
> /*
> @@ -1070,9 +1070,20 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
> }
>
> lflags = GPIO_PERSISTENT | (flags & GPIO_ACTIVE_LOW);
> - parent = gpio_device_to_device(gdev);
> + gdev_dev = gpio_device_to_device(gdev);
> properties[prop++] = PROPERTY_ENTRY_STRING("compatible", "reset-gpio");
> - properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags);
> + properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", gdev_dev->fwnode, offset, lflags);
> +
> + /*
> + * The reset-gpio device is never removed, but the GPIO device goes
> + * away whenever the GPIO controller's driver unbinds, for example the
> + * LPASS pin controller when the audio DSP restarts. A reset-gpio
> + * device left under the old GPIO device can never bind again
> + * ("driver_sysfs_add failed"). Put it under the device that provides
> + * the GPIO controller instead, which stays, and link it to that
> + * device below so it follows the controller's driver.
> + */
> + parent = gdev_dev->parent ?: gdev_dev;
>
> /* Not freed on success, because it is persisent subsystem data. */
> rgpio_dev = kzalloc_obj(*rgpio_dev);
This part is already covered by [1].
[1] https://lore.kernel.org/all/20261026-b4-reset-gpio-parent-to-gpio-controller-v1-1-11549e6ea930@oss.qualcomm.com/
Could you test if that fixes your issue?
> @@ -1097,6 +1108,17 @@ static int __reset_add_reset_gpio_device(struct fwnode_handle *fwnode,
> if (ret)
> goto err_del_swnode;
>
> + /*
> + * Unbind when the GPIO controller's driver unbinds and probe again
> + * when it is back, so the reset controller never holds GPIO
The comment above says reset-gpio is never removed. How can this be
true at the same time?
regards
Philipp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-01 16:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 16:28 [PATCH] reset: gpio: Keep reset-gpio device under the GPIO controller device Birk Skyum
2026-12-01 16:28 ` Birk Skyum via B4 Relay
2026-12-01 16:50 ` sashiko-bot
2026-12-01 16:57 ` Philipp Zabel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.