[PATCH 6/9] w1: netlink: drop the slave after the bus is unlocked
From: Greg Kroah-Hartman
Date: Tue Oct 27 2026 - 12:06:55 EST
From: Josef Bacik <josef@xxxxxxxxxxxxxx>
w1_process_cb() executes the commands of a netlink message with bus_mutex
held, and drops the reference to the slave which the message was
addressed to before it unlocks the mutex. If the slave has been detached
in the meantime, this is the last reference, and w1_unref_slave() tears
the slave down on the spot. That waits
- in device_unregister(), for the sysfs callbacks of the slave which are
running, and
- in w1_therm_remove_slave(), for the readers which have taken a
reference to the family data,
and both kinds take bus_mutex to talk to the slave. Whoever is waiting
for the mutex at that moment is never going to finish, and neither is the
thread of the bus master.
Unlock the bus first. The reference keeps the slave, and with it the
master, alive until then.
Fixes: d3a8a9dbb903 ("w1: hold bus_mutex in netlink and search")
Cc: stable <stable@xxxxxxxxxx>
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/w1/w1_netlink.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c
index e6b59d921076..40fbb96a793e 100644
--- a/drivers/w1/w1_netlink.c
+++ b/drivers/w1/w1_netlink.c
@@ -478,15 +478,17 @@ static void w1_process_cb(struct w1_master *dev, struct w1_async_cmd *async_cmd)
if (!cmd || err)
w1_netlink_queue_status(node->block, node->msg, cmd, err);
+ dev->priv = NULL;
+ mutex_unlock(&dev->bus_mutex);
+
/* ref taken in w1_search_slave or w1_search_master_id when building
- * the block
+ * the block. If it is the last one, the slave is removed, which waits
+ * for users of the bus.
*/
if (sl)
w1_unref_slave(sl);
else
atomic_dec(&dev->refcnt);
- dev->priv = NULL;
- mutex_unlock(&dev->bus_mutex);
mutex_lock(&dev->list_mutex);
list_del(&async_cmd->async_entry);
--
2.56.0