Skip to contentSkip to conversation

extcon: lc824206xa: cancel work on driver detach

PATCH New Hongyan Xu 1 participant 1 message Aug 6 External connector subsystem (extcon)

lore
Share & tools
lore

Hongyan Xu

author
#0 lore raw

PATCH 1/1 extcon: lc824206xa: cancel work on driver detach

The IRQ handler and probe both queue lc824206xa_work(). The worker accesses driver data and managed extcon, power supply and regulator resources. Without cancellation, it can run after those resources are released on driver detach.

Use devm_work_autocancel() after registering the resources used by the worker and before requesting the managed IRQ. Reverse devres release order then frees the IRQ first, cancels the work next and releases its dependencies last.

Fixes 9e1897cb9568 ("extcon: Add LC824206XA microUSB switch driver")
---
 drivers/extcon/extcon-lc824206xa.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/extcon/extcon-lc824206xa.c +5 -1
index 56938748aea8..f4da4942e6fe 100644
@@ -18,6 +18,7 @@
 
 #include <linux/bits.h>
 #include <linux/delay.h>
+#include <linux/devm-helpers.h>
 #include <linux/device.h>
 #include <linux/extcon-provider.h>
 #include <linux/i2c.h>
@@ -424,7 +425,6 @@ static int lc824206xa_probe(struct i2c_client *client)
 		return -ENOMEM;
 
 	data->client = client;
-	INIT_WORK(&data->work, lc824206xa_work);
 	data->cable = EXTCON_NONE;
 	data->previous_cable = EXTCON_NONE;
 	data->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN;
@@ -463,6 +463,10 @@ static int lc824206xa_probe(struct i2c_client *client)
 	if (IS_ERR(data->psy))
 		return dev_err_probe(dev, PTR_ERR(data->psy), "registering power supply\n");
 
+	ret = devm_work_autocancel(dev, &data->work, lc824206xa_work);
+	if (ret)
+		return ret;
+
 	ret = devm_request_threaded_irq(dev, client->irq, NULL, lc824206xa_irq,
 					IRQF_TRIGGER_LOW | IRQF_ONESHOT,
 					KBUILD_MODNAME, data);
Signature · 1 line
2.50.1.windows.1