Re: [PATCH v2 1/3] soundwire: bus: Don't unassign dev_num before unregistering device

From: Vinod Koul

Date: Sat Oct 03 2026 - 04:19:21 EST


On 25-09-26, 16:42, Charles Keepax wrote:
> Don't mark dev_num as unassigned until after the driver remove has
> been called. The driver may want to communicate with the device
> as part of the driver remove operation, so the dev_num should
> remain assigned until that has completed. This requires moving from
> device_unregister() to manually calling device_del() and device_put()
> to ensure that the slave struct isn't freed too early.
>
> Signed-off-by: Charles Keepax <ckeepax@xxxxxxxxxxxxxxxxxxxxx>
> ---
>
> Changes since v1:
> - Split device_unregister into device_del and put_device
>
> drivers/soundwire/bus.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> index aeaae5a57c89d..1488b6540844c 100644
> --- a/drivers/soundwire/bus.c
> +++ b/drivers/soundwire/bus.c
> @@ -175,8 +175,9 @@ static int sdw_delete_slave(struct device *dev, void *data)
>
> sdw_slave_debugfs_exit(slave);
>
> - mutex_lock(&bus->bus_lock);
> + device_del(dev);
>
> + mutex_lock(&bus->bus_lock);
> if (slave->dev_num) { /* clear dev_num if assigned */
> clear_bit(slave->dev_num, bus->assigned);
> if (bus->ops && bus->ops->put_device_num)
> @@ -185,7 +186,8 @@ static int sdw_delete_slave(struct device *dev, void *data)
> list_del_init(&slave->node);
> mutex_unlock(&bus->bus_lock);
>
> - device_unregister(dev);
> + put_device(dev);

if we are doing this I would add code comments on why we split. We
invoke device_register so the expectation is that we always call
device_unregister. I understand this is being done but this needs to be
well documented here

--
~Vinod