[PATCH 5/5] extcon: sm5502: cancel wq_detcable on driver unbind
From: Tristan Madani
Date: Tue Oct 20 2026 - 11:46:12 EST
From: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
sm5502_muic_i2c_probe() schedules a delayed work (wq_detcable) for
post-boot cable state detection but the driver has no .remove callback
and never cancels it. If the device is unbound before the work fires,
the callback dereferences freed memory.
Use devm_delayed_work_autocancel() so the work is automatically
cancelled when the device is removed.
Fixes: e1954452f500 ("extcon: sm5502: Detect cable state after completing platform booting")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
---
drivers/extcon/extcon-sm5502.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c
index c8c4b9ef72aa1..5257cb3ca2266 100644
--- a/drivers/extcon/extcon-sm5502.c
+++ b/drivers/extcon/extcon-sm5502.c
@@ -6,6 +6,7 @@
* Author: Chanwoo Choi <cw00.choi@xxxxxxxxxxx>
*/
+#include <linux/devm-helpers.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
@@ -763,7 +764,10 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c)
* After completing the booting of platform, the extcon provider
* driver should notify cable state to upper layer.
*/
- INIT_DELAYED_WORK(&info->wq_detcable, sm5502_muic_detect_cable_wq);
+ ret = devm_delayed_work_autocancel(&i2c->dev, &info->wq_detcable,
+ sm5502_muic_detect_cable_wq);
+ if (ret)
+ return ret;
queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
msecs_to_jiffies(DELAY_MS_DEFAULT));
--
2.47.3