diff options
| author | Richard Fitzgerald <rf@opensource.cirrus.com> | 2026-08-31 12:29:39 +0100 |
|---|---|---|
| committer | Vinod Koul <vkoul@kernel.org> | 2026-09-01 22:41:22 +0530 |
| commit | bb22b81339cb97d2eb7ec666bf03f985fe64d6cb (patch) | |
| tree | e6ec3eab6607917973f204057fe60995231636d5 /drivers | |
| parent | c3133906d5bda343bd5c1d8ad63074a14506ad72 (diff) | |
| download | linux-next-bb22b81339cb97d2eb7ec666bf03f985fe64d6cb.tar.gz linux-next-bb22b81339cb97d2eb7ec666bf03f985fe64d6cb.zip | |
soundwire: bus_type: Use devres to free slave IDA
Create a devres cleanup action to call ida_free(). This ensures that it
is freed after anything that is cleaned up by devres and might have been
using the allocated ID. It also avoids mixing devres and manual cleanup
during sdw_bus_probe().
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20260831112939.126708-1-rf@opensource.cirrus.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/soundwire/bus_type.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/soundwire/bus_type.c b/drivers/soundwire/bus_type.c index d61a97c5b41e..fea15107cd9b 100644 --- a/drivers/soundwire/bus_type.c +++ b/drivers/soundwire/bus_type.c @@ -71,6 +71,13 @@ int sdw_slave_uevent(const struct device *dev, struct kobj_uevent_env *env) return 0; } +static void sdw_slave_ida_free(void *data) +{ + struct sdw_slave *slave = data; + + ida_free(&slave->bus->slave_ida, slave->index); +} + static int sdw_bus_probe(struct device *dev) { struct sdw_slave *slave = dev_to_sdw_dev(dev); @@ -104,15 +111,16 @@ static int sdw_bus_probe(struct device *dev) return ret; } slave->index = ret; + ret = devm_add_action_or_reset(dev, sdw_slave_ida_free, slave); + if (ret) + return ret; /* Create IRQ mapping now so the driver can get it in probe() */ sdw_irq_create_mapping(slave); ret = drv->probe(slave, id); - if (ret) { - ida_free(&slave->bus->slave_ida, slave->index); + if (ret) return ret; - } mutex_lock(&slave->sdw_dev_lock); @@ -170,8 +178,6 @@ static void sdw_bus_remove(struct device *dev) if (drv->remove) drv->remove(slave); - - ida_free(&slave->bus->slave_ida, slave->index); } static void sdw_bus_shutdown(struct device *dev) |
