[PATCH 0/4] software node: fix lookup of swnode in release path
From: Peng Fan (OSS)
Date: Wed Nov 04 2026 - 11:02:40 EST
This series fixes a software node lifetime bug where a lookup can find an
swnode whose kobject refcount has already reached zero.
The kset list keeps an swnode linked until kobject_cleanup() calls
kobj_kset_leave(), which happens after the last kobject_put() has already
dropped the refcount to zero. A lookup that does not check whether the
object is still referenceable can therefore call kobject_get() on a dead
object, triggering:
refcount_t: addition on 0; use-after-free
refcount_t: saturated; leaking memory
refcount_t: underflow; use-after-free
The problem is easily reproduced on i.MX95 with dwc3-imx when
dwc3_core_probe() returns -EPROBE_DEFER. dwc3_imx_probe() removes its
static software node from the device and the deferred probe retry
immediately adds the same node again. With
CONFIG_DEBUG_KOBJECT_RELEASE the old swnode stays on the kset list for
some time after its refcount reaches zero, so the retry reliably finds
it.
The first patch fixes the pointer-based kset lookup by using
kobject_get_unless_zero() and skipping entries that are already in their
release path. It also makes registration return the newly created swnode
reference so that device_add_software_node() does not have to look the
node up again after registering it. Reference-owning callers get a
reference from the lookup, while software_node_fwnode() keeps its
borrowed-pointer semantics by dropping the temporary lookup reference.
The remaining patches harden related weak lookups for the same class of
problem. The series is organized as follows:
1. Fix the pointer-based kset lookup and avoid the second lookup after
registration.
2. Harden software_node_find_by_name() against dying entries.
3. Check the result of software_node_fwnode() in the graph
remote-endpoint path.
4. Skip dying children when walking the parent's children list.
Signed-off-by: Peng Fan <peng.fan@xxxxxxx>
---
Peng Fan (4):
software node: do not resurrect swnode being released
software node: use kobject_get_unless_zero() in software_node_find_by_name()
software node: handle missing remote endpoint node
software node: skip dying children during traversal
drivers/base/swnode.c | 143 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 100 insertions(+), 43 deletions(-)
---
base-commit: 2637bdec0535a2044cd830eba9a79363651d9043
change-id: 20261104-swnode-race-v1-b9f2dcc954c8
Best regards,
--
Peng Fan <peng.fan@xxxxxxx>