Re: [PATCH] software node: make swnodes hold their own references on parents
From: Bartosz Golaszewski
Date: Tue Nov 10 2026 - 03:58:02 EST
On Mon, Nov 09, 2026 at 09:52:12PM +0200, Andy Shevchenko wrote:
> On Fri, Nov 06, 2026 at 12:13:28PM +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.
>
> ...
>
> > + if (parent)
> > + swnode_put(parent);
>
> This will be the second case of potentially NULL being passed to swnode_put().
> Since it's a static internal API, I would just add a check there and hope that
> compiler will inline and that will be optimized away on the cases when the
> parameter is known not to be NULL.
>
> Maybe in a separate change.
>
Yes, I actually added it to my TODO list but this is clearly a fix, so I
wanted to keep it small.
Bart