[PATCH 0/2] w1: Fix the lifetime of slaves and their master

From: Suyuan Wang via B4 Relay

Date: Thu Nov 19 2026 - 15:12:43 EST


w1_unref_slave() frees a slave right after unregistering its device,
while the device's release callback still uses the slave and its
master. Since commit 9fcbbac5ded4 removing a slave no longer waits for
that callback, so a delayed release (or any late reference to the
slave device) runs on freed memory.

Patch 1 frees the slave from its release callback. Patch 2 makes the
slave hold a reference to the master until then, since the master can
otherwise be freed before the delayed release of its last slave.

Found with a static analysis tool and checked by hand. Both problems
reproduce under KASAN with CONFIG_DEBUG_KOBJECT_RELEASE and a test w1
master in QEMU; details below the --- line of each patch.

---
Suyuan Wang (2):
w1: Free the slave from its device release callback
w1: Keep the master alive until the slave is released

drivers/w1/w1.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)