[PATCH v2] usb: typec: anx7411 - stop the IRQ before destroying the workqueue

Linkai Gong posted 1 patch 2 weeks, 3 days ago
There is a newer version of this series
drivers/usb/typec/anx7411.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH v2] usb: typec: anx7411 - stop the IRQ before destroying the workqueue
Posted by Linkai Gong 2 weeks, 3 days ago
The IRQ is devm-managed, so it can still queue plat->work while
remove() is tearing the queue down. Disable it first.

Fixes: fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")
Signed-off-by: Linkai Gong <gonglinkai@kylinos.cn>
---
v2:
- keep the minimal remove() race fix; drop the workqueue later if wanted

 drivers/usb/typec/anx7411.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
index 41df115912b9..c3d36da692e4 100644
--- a/drivers/usb/typec/anx7411.c
+++ b/drivers/usb/typec/anx7411.c
@@ -1566,8 +1566,11 @@ static void anx7411_i2c_remove(struct i2c_client *client)
 	anx7411_partner_unregister_altmode(plat);
 	anx7411_unregister_partner(plat);
 
-	if (plat->workqueue)
+	if (plat->workqueue) {
+		disable_irq(plat->intp_irq);
+		cancel_work_sync(&plat->work);
 		destroy_workqueue(plat->workqueue);
+	}
 
 	i2c_unregister_device(plat->spi_client);
 
-- 
2.25.1
Re: [PATCH v2] usb: typec: anx7411 - stop the IRQ before destroying the workqueue
Posted by Heikki Krogerus 2 weeks, 2 days ago
On Tue, Sep 08, 2026 at 02:03:33PM +0800, Linkai Gong wrote:
> The IRQ is devm-managed, so it can still queue plat->work while
> remove() is tearing the queue down. Disable it first.
> 
> Fixes: fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")

Not for stable?

> Signed-off-by: Linkai Gong <gonglinkai@kylinos.cn>
> ---
> v2:
> - keep the minimal remove() race fix; drop the workqueue later if wanted

I don't see any difference compared to v1?

thanks,

>  drivers/usb/typec/anx7411.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
> index 41df115912b9..c3d36da692e4 100644
> --- a/drivers/usb/typec/anx7411.c
> +++ b/drivers/usb/typec/anx7411.c
> @@ -1566,8 +1566,11 @@ static void anx7411_i2c_remove(struct i2c_client *client)
>  	anx7411_partner_unregister_altmode(plat);
>  	anx7411_unregister_partner(plat);
>  
> -	if (plat->workqueue)
> +	if (plat->workqueue) {
> +		disable_irq(plat->intp_irq);
> +		cancel_work_sync(&plat->work);
>  		destroy_workqueue(plat->workqueue);
> +	}
>  
>  	i2c_unregister_device(plat->spi_client);
>  
> -- 
> 2.25.1

-- 
heikki
Re: [PATCH v2] usb: typec: anx7411 - stop the IRQ before destroying the workqueue
Posted by Linkai Gong 2 weeks, 1 day ago
On Wed, Sep 09, 2026 at 04:23:14PM +0200, Heikki Krogerus wrote:
> Not for stable?

Yes, it should go to stable. The race has been there since the driver
was added. I will send a v3 with Cc: stable.

> I don't see any difference compared to v1?

Correct, the code is the same as v1. After your question about the
workqueue I only wanted to say I am keeping this minimal remove()
fix for now; I should have replied without posting an identical
patch. Sorry for the noise.

Thanks,
Linkai
[PATCH v3] usb: typec: anx7411 - stop the IRQ before destroying the workqueue
Posted by Linkai Gong 2 weeks, 1 day ago
The IRQ is devm-managed, so it can still queue plat->work while
remove() is tearing the queue down. Disable it first.

Fixes: fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")
Cc: stable@vger.kernel.org
Signed-off-by: Linkai Gong <gonglinkai@kylinos.cn>
---
v3:
- add Cc: stable (Heikki)

v2:
- keep the minimal remove() race fix; drop the workqueue later if wanted
  (code unchanged from v1)

 drivers/usb/typec/anx7411.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
index 41df115912b9..c3d36da692e4 100644
--- a/drivers/usb/typec/anx7411.c
+++ b/drivers/usb/typec/anx7411.c
@@ -1566,8 +1566,11 @@ static void anx7411_i2c_remove(struct i2c_client *client)
 	anx7411_partner_unregister_altmode(plat);
 	anx7411_unregister_partner(plat);
 
-	if (plat->workqueue)
+	if (plat->workqueue) {
+		disable_irq(plat->intp_irq);
+		cancel_work_sync(&plat->work);
 		destroy_workqueue(plat->workqueue);
+	}
 
 	i2c_unregister_device(plat->spi_client);
 
-- 
2.25.1
Re: [PATCH v3] usb: typec: anx7411 - stop the IRQ before destroying the workqueue
Posted by Heikki Krogerus 1 week, 4 days ago
On Thu, Sep 10, 2026 at 09:11:50AM +0800, Linkai Gong wrote:
> The IRQ is devm-managed, so it can still queue plat->work while
> remove() is tearing the queue down. Disable it first.
> 
> Fixes: fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Linkai Gong <gonglinkai@kylinos.cn>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> v3:
> - add Cc: stable (Heikki)
> 
> v2:
> - keep the minimal remove() race fix; drop the workqueue later if wanted
>   (code unchanged from v1)
> 
>  drivers/usb/typec/anx7411.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
> index 41df115912b9..c3d36da692e4 100644
> --- a/drivers/usb/typec/anx7411.c
> +++ b/drivers/usb/typec/anx7411.c
> @@ -1566,8 +1566,11 @@ static void anx7411_i2c_remove(struct i2c_client *client)
>  	anx7411_partner_unregister_altmode(plat);
>  	anx7411_unregister_partner(plat);
>  
> -	if (plat->workqueue)
> +	if (plat->workqueue) {
> +		disable_irq(plat->intp_irq);
> +		cancel_work_sync(&plat->work);
>  		destroy_workqueue(plat->workqueue);
> +	}
>  
>  	i2c_unregister_device(plat->spi_client);
>  
> -- 
> 2.25.1

-- 
heikki