* [PATCH] soundwire: fail slave probe if IRQ cleanup cannot be registered
@ 2026-11-29 12:48 Jiawen Liu
2026-11-30 10:18 ` Pierre-Louis Bossart
0 siblings, 1 reply; 4+ messages in thread
From: Jiawen Liu @ 2026-11-29 12:48 UTC (permalink / raw)
To: Vinod Koul, Bard Liao; +Cc: Pierre-Louis Bossart, linux-sound, linux-kernel
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@qq.com>
---
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 */
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] soundwire: fail slave probe if IRQ cleanup cannot be registered
2026-11-29 12:48 [PATCH] soundwire: fail slave probe if IRQ cleanup cannot be registered Jiawen Liu
@ 2026-11-30 10:18 ` Pierre-Louis Bossart
2026-11-30 15:50 ` Charles Keepax
0 siblings, 1 reply; 4+ messages in thread
From: Pierre-Louis Bossart @ 2026-11-30 10:18 UTC (permalink / raw)
To: Jiawen Liu, Vinod Koul, Bard Liao, Jizhou Tong, Charles Keepax
Cc: linux-sound, linux-kernel
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@qq.com>
The changes look ok to me, so here's a
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
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 */
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] soundwire: fail slave probe if IRQ cleanup cannot be registered
2026-11-30 10:18 ` Pierre-Louis Bossart
@ 2026-11-30 15:50 ` Charles Keepax
2026-11-30 19:54 ` Jiawen Liu
0 siblings, 1 reply; 4+ messages in thread
From: Charles Keepax @ 2026-11-30 15:50 UTC (permalink / raw)
To: Pierre-Louis Bossart
Cc: Jiawen Liu, Vinod Koul, Bard Liao, Jizhou Tong, linux-sound,
linux-kernel
On Mon, Nov 30, 2026 at 11:18:42AM +0100, Pierre-Louis Bossart wrote:
> 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@qq.com>
>
> The changes look ok to me, so here's a
>
> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
>
> 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.
Yeah not really convinced the locking was necessary in the RFC
one, was waiting on the response to your questions too.
> > + ret = devm_add_action(&slave->dev, sdw_irq_dispose_mapping, slave);
> > + if (ret) {
> > + irq_dispose_mapping(irq);
You don't need to free here, add_action calls the dispose if it
fails. But apart from that I think this looks ok.
Thanks,
Charles
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] soundwire: fail slave probe if IRQ cleanup cannot be registered
2026-11-30 15:50 ` Charles Keepax
@ 2026-11-30 19:54 ` Jiawen Liu
0 siblings, 0 replies; 4+ messages in thread
From: Jiawen Liu @ 2026-11-30 19:54 UTC (permalink / raw)
To: Charles Keepax
Cc: Pierre-Louis Bossart, Vinod Koul, Bard Liao, Jizhou Tong,
linux-sound, linux-kernel
Hi Charles,
The original code used devm_add_action_or_reset(), which calls the
action if registration fails. This patch switches to devm_add_action().
If the devres allocation fails, that helper returns -ENOMEM without
calling the action.
At that point the new mapping is still in the local variable irq.
slave->irq is only set after registration succeeds. Dropping
irq_dispose_mapping(irq) here would leak the mapping, so I'd keep it.
Thanks, Pierre-Louis, for the review and the pointer to the earlier RFC.
This change covers the probe error path. The locking question during
alert dispatch is still open.
Thanks,
Jiawen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-30 19:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 12:48 [PATCH] soundwire: fail slave probe if IRQ cleanup cannot be registered Jiawen Liu
2026-11-30 10:18 ` Pierre-Louis Bossart
2026-11-30 15:50 ` Charles Keepax
2026-11-30 19:54 ` Jiawen Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®