Re: [PATCH v2] software node: make swnodes hold their own references on parents
From: Johan Hovold
Date: Fri Nov 20 2026 - 07:56:37 EST
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@xxxxxxxxxxxxxxx
> 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@xxxxxxxxxxxxxxxx>
> ---
> 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@xxxxxxxxxxxxxxxx
Thanks for the update. Applied to driver-core-testing for 7.5.
Johan