* [PATCH v2] software node: make swnodes hold their own references on parents
@ 2026-11-19 10:57 Bartosz Golaszewski
2026-11-20 12:44 ` Rafael J. Wysocki (Intel)
2026-11-20 12:56 ` Johan Hovold
0 siblings, 2 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2026-11-19 10:57 UTC (permalink / raw)
To: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
Bartosz Golaszewski, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich, Johan Hovold, Linus Walleij
Cc: Rafael J. Wysocki, linux-acpi, driver-core, linux-kernel, stable,
Bartosz Golaszewski
In swnode_register(), swnode->parent is assigned before calling
kobject_init_and_add(), which normally acquires a reference on
parent->kobj via kobject_add_internal() that is held until after
software_node_release() completes. However, if kobject_init_and_add()
fails before acquiring the parent reference or drops it on error in
kobject_add_internal(), swnode->kobj holds no reference on parent->kobj
while swnode->parent remains set.
With CONFIG_DEBUG_KOBJECT_RELEASE enabled, the random delay in
kobject_delayed_cleanup() may create a situation where - when
unregistering the child node and then the parent - the parent object
gets released before the child who's left with a dangling pointer.
Acquire a refernce to the parent swnode when registering the child and
drop it on child's release.
Cc: stable@vger.kernel.org
Fixes: 59abd83672f7 ("drivers: base: Introducing software nodes to the firmware node framework")
Closes: https://sashiko.dev/#/bug/linux-82933c14-d212-49f1-bd2f-d4ab1e16fed7
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
Changes in v2:
- Simplify the code by folding the swnode_put() call into the existing
conditional branch
- Link to v1: https://patch.msgid.link/20261106-swnode-kobject-parent-ref-v1-1-77dbd7213dd0@oss.qualcomm.com
---
drivers/base/swnode.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 65e9388af8651f9d9602ff82e1761e5870284f26..f7b53e966b183cec1bfba6535ccdba308b0be68e 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -850,6 +850,7 @@ static void software_node_release(struct kobject *kobj)
if (swnode->parent) {
ida_free(&swnode->parent->child_ids, swnode->id);
list_del(&swnode->entry);
+ swnode_put(swnode->parent);
} else {
ida_free(&swnode_root_ids, swnode->id);
}
@@ -886,7 +887,7 @@ swnode_register(const struct software_node *node, struct swnode *parent,
swnode->id = ret;
swnode->node = node;
- swnode->parent = parent;
+ swnode->parent = parent ? swnode_get(parent) : NULL;
swnode->kobj.kset = swnode_kset;
fwnode_init(&swnode->fwnode, &software_node_ops);
---
base-commit: e8017d29067fd1310a65c3494ce1a1b492adbac6
change-id: 20261106-swnode-kobject-parent-ref-3bd9b9b75aeb
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] software node: make swnodes hold their own references on parents
2026-11-19 10:57 [PATCH v2] software node: make swnodes hold their own references on parents Bartosz Golaszewski
@ 2026-11-20 12:44 ` Rafael J. Wysocki (Intel)
2026-11-20 12:56 ` Johan Hovold
1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-20 12:44 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
Bartosz Golaszewski, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich, Johan Hovold, Linus Walleij, Rafael J. Wysocki,
linux-acpi, driver-core, linux-kernel, stable
On Thu, Nov 19, 2026 at 11:57 AM Bartosz Golaszewski
<bartosz.golaszewski@oss.qualcomm.com> wrote:
>
> In swnode_register(), swnode->parent is assigned before calling
> kobject_init_and_add(), which normally acquires a reference on
> parent->kobj via kobject_add_internal() that is held until after
> software_node_release() completes. However, if kobject_init_and_add()
> fails before acquiring the parent reference or drops it on error in
> kobject_add_internal(), swnode->kobj holds no reference on parent->kobj
> while swnode->parent remains set.
>
> With CONFIG_DEBUG_KOBJECT_RELEASE enabled, the random delay in
> kobject_delayed_cleanup() may create a situation where - when
> unregistering the child node and then the parent - the parent object
> gets released before the child who's left with a dangling pointer.
>
> Acquire a refernce to the parent swnode when registering the child and
> drop it on child's release.
>
> Cc: stable@vger.kernel.org
> Fixes: 59abd83672f7 ("drivers: base: Introducing software nodes to the firmware node framework")
> Closes: https://sashiko.dev/#/bug/linux-82933c14-d212-49f1-bd2f-d4ab1e16fed7
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
> ---
> Changes in v2:
> - Simplify the code by folding the swnode_put() call into the existing
> conditional branch
> - Link to v1: https://patch.msgid.link/20261106-swnode-kobject-parent-ref-v1-1-77dbd7213dd0@oss.qualcomm.com
> ---
> drivers/base/swnode.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index 65e9388af8651f9d9602ff82e1761e5870284f26..f7b53e966b183cec1bfba6535ccdba308b0be68e 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -850,6 +850,7 @@ static void software_node_release(struct kobject *kobj)
> if (swnode->parent) {
> ida_free(&swnode->parent->child_ids, swnode->id);
> list_del(&swnode->entry);
> + swnode_put(swnode->parent);
> } else {
> ida_free(&swnode_root_ids, swnode->id);
> }
> @@ -886,7 +887,7 @@ swnode_register(const struct software_node *node, struct swnode *parent,
>
> swnode->id = ret;
> swnode->node = node;
> - swnode->parent = parent;
> + swnode->parent = parent ? swnode_get(parent) : NULL;
> swnode->kobj.kset = swnode_kset;
> fwnode_init(&swnode->fwnode, &software_node_ops);
>
>
> ---
> base-commit: e8017d29067fd1310a65c3494ce1a1b492adbac6
> change-id: 20261106-swnode-kobject-parent-ref-3bd9b9b75aeb
>
> Best regards,
> --
> Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] software node: make swnodes hold their own references on parents
2026-11-19 10:57 [PATCH v2] software node: make swnodes hold their own references on parents Bartosz Golaszewski
2026-11-20 12:44 ` Rafael J. Wysocki (Intel)
@ 2026-11-20 12:56 ` Johan Hovold
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2026-11-20 12:56 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
Bartosz Golaszewski, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich, Linus Walleij, Rafael J. Wysocki, linux-acpi,
driver-core, linux-kernel, stable
On Thu, Nov 19, 2026 at 11:57:19AM +0100, Bartosz Golaszewski wrote:
> In swnode_register(), swnode->parent is assigned before calling
> kobject_init_and_add(), which normally acquires a reference on
> parent->kobj via kobject_add_internal() that is held until after
> software_node_release() completes. However, if kobject_init_and_add()
> fails before acquiring the parent reference or drops it on error in
> kobject_add_internal(), swnode->kobj holds no reference on parent->kobj
> while swnode->parent remains set.
>
> With CONFIG_DEBUG_KOBJECT_RELEASE enabled, the random delay in
> kobject_delayed_cleanup() may create a situation where - when
> unregistering the child node and then the parent - the parent object
> gets released before the child who's left with a dangling pointer.
>
> Acquire a refernce to the parent swnode when registering the child and
> drop it on child's release.
>
> Cc: stable@vger.kernel.org
> Fixes: 59abd83672f7 ("drivers: base: Introducing software nodes to the firmware node framework")
> Closes: https://sashiko.dev/#/bug/linux-82933c14-d212-49f1-bd2f-d4ab1e16fed7
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> ---
> Changes in v2:
> - Simplify the code by folding the swnode_put() call into the existing
> conditional branch
> - Link to v1: https://patch.msgid.link/20261106-swnode-kobject-parent-ref-v1-1-77dbd7213dd0@oss.qualcomm.com
Thanks for the update. Applied to driver-core-testing for 7.5.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-20 12:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 10:57 [PATCH v2] software node: make swnodes hold their own references on parents Bartosz Golaszewski
2026-11-20 12:44 ` Rafael J. Wysocki (Intel)
2026-11-20 12:56 ` Johan Hovold
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®