Re: [PATCH] soundwire: fail slave probe if IRQ cleanup cannot be registered
From: Pierre-Louis Bossart
Date: Mon Nov 30 2026 - 09:31:01 EST
On 11/29/26 13:48, Jiawen Liu wrote:
> sdw_irq_create_mapping() publishes the new virtual IRQ in slave->irq
> before registering its devres cleanup action. If action registration
> fails, the reset helper disposes the mapping but the cached IRQ remains
> nonzero, so the peripheral driver probe receives an invalid IRQ number.
>
> Keep the mapping local until cleanup registration succeeds, clear the
> cached IRQ when the mapping is disposed, and return registration failures
> to the bus probe path before invoking the peripheral driver.
>
> Fixes: a5fef9baa87f ("soundwire: bus: Move irq mapping cleanup into devres")
> Signed-off-by: Jiawen Liu <1298662399@xxxxxx>
The changes look ok to me, so here's a
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@xxxxxxxxx>
The only problem is that there was already a similar submission in "[RFC
PATCH] soundwire: protect the slave IRQ mapping during alert dispatch",
with additional locking suggested but no answer provided to my feedback.
Adding the initial contributor and Charles in the To: list, not sure all
the interrupt handling problems are solved.
> ---
> drivers/soundwire/bus_type.c | 4 +++-
> drivers/soundwire/irq.c | 22 ++++++++++++++++++----
> drivers/soundwire/irq.h | 5 +++--
> 3 files changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/soundwire/bus_type.c b/drivers/soundwire/bus_type.c
> index fea15107cd9b9..f832065745981 100644
> --- a/drivers/soundwire/bus_type.c
> +++ b/drivers/soundwire/bus_type.c
> @@ -116,7 +116,9 @@ static int sdw_bus_probe(struct device *dev)
> return ret;
>
> /* Create IRQ mapping now so the driver can get it in probe() */
> - sdw_irq_create_mapping(slave);
> + ret = sdw_irq_create_mapping(slave);
> + if (ret)
> + return ret;
>
> ret = drv->probe(slave, id);
> if (ret)
> diff --git a/drivers/soundwire/irq.c b/drivers/soundwire/irq.c
> index f18be37efef8e..9618c10ddacca 100644
> --- a/drivers/soundwire/irq.c
> +++ b/drivers/soundwire/irq.c
> @@ -51,13 +51,27 @@ static void sdw_irq_dispose_mapping(void *data)
> struct sdw_slave *slave = data;
>
> irq_dispose_mapping(slave->irq);
> + slave->irq = 0;
> }
>
> -void sdw_irq_create_mapping(struct sdw_slave *slave)
> +int sdw_irq_create_mapping(struct sdw_slave *slave)
> {
> - slave->irq = irq_create_mapping(slave->bus->domain, slave->index);
> - if (!slave->irq)
> + unsigned int irq;
> + int ret;
> +
> + irq = irq_create_mapping(slave->bus->domain, slave->index);
> + if (!irq) {
> dev_warn(&slave->dev, "Failed to map IRQ\n");
> + return 0;
> + }
> +
> + ret = devm_add_action(&slave->dev, sdw_irq_dispose_mapping, slave);
> + if (ret) {
> + irq_dispose_mapping(irq);
> + return ret;
> + }
> +
> + slave->irq = irq;
>
> - devm_add_action_or_reset(&slave->dev, sdw_irq_dispose_mapping, slave);
> + return 0;
> }
> diff --git a/drivers/soundwire/irq.h b/drivers/soundwire/irq.h
> index 86e2318409dab..224c5aad22817 100644
> --- a/drivers/soundwire/irq.h
> +++ b/drivers/soundwire/irq.h
> @@ -15,7 +15,7 @@
> int sdw_irq_create(struct sdw_bus *bus,
> struct fwnode_handle *fwnode);
> void sdw_irq_delete(struct sdw_bus *bus);
> -void sdw_irq_create_mapping(struct sdw_slave *slave);
> +int sdw_irq_create_mapping(struct sdw_slave *slave);
>
> #else /* CONFIG_IRQ_DOMAIN */
>
> @@ -29,8 +29,9 @@ static inline void sdw_irq_delete(struct sdw_bus *bus)
> {
> }
>
> -static inline void sdw_irq_create_mapping(struct sdw_slave *slave)
> +static inline int sdw_irq_create_mapping(struct sdw_slave *slave)
> {
> + return 0;
> }
>
> #endif /* CONFIG_IRQ_DOMAIN */