[PATCH 0/3] driver core: fix unbalanced reference counting for software nodes

From: Bartosz Golaszewski

Date: Thu Oct 15 2026 - 11:25:44 EST


Eduardo reported an issue with reference underflow when setting a
software node with set_secondary_fwnode() and then repeatedly destroying
and re-creating a device. This is caused by the fact that
software_node_notify() takes a reference to the software node which is
unconditionally dropped in software_node_notify_remove(). However the
software node can be assigned after device_add() so the latter should
only do it if it was bumped by the former.

This series proposes a fix in driver core. The first two patches extend
the device flag API with a new accessor and value. The third is the
actual fix in swnode.c and should be backported to stable (along the
first two as dependencies).

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
Bartosz Golaszewski (3):
driver core: provide a test-and-clear device flag accessor
driver core: provide new device flag - DEV_FLAG_SWNODE_NOTIFIER
software node: fix unbalanced reference counting

drivers/base/swnode.c | 5 ++++-
include/linux/device.h | 10 ++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
---
base-commit: d419d682257d813f6cb7a28e42b35d0edf4ad038
change-id: 20261015-swnode-dev-notify-balance-e6f56fb9a469

Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>