[PATCH] platform/x86: lenovo: cancel fastcharger work on detach
Hongyan Xu <[email protected]>
| Newsgroups | org.kernel.vger.platform-driver-x86 |
|---|---|
| Message-ID | <[email protected]> |
The extcon notifier and probe queue yt2_1380_fc_worker(), which can sleep
for several seconds while accessing managed pinctrl, GPIO and serdev
resources. Driver detach does not drain this work before those resources
are released, allowing the worker to use freed state.
Use devm_work_autocancel() between opening the managed serdev device and
registering the managed notifier. Reverse devres release order then
unregisters the notifier, cancels the work and only afterwards closes and
releases the resources used by the worker.
Fixes: b2ed33e8d486 ("platform/x86: Add lenovo-yoga-tab2-pro-1380-fastcharger driver")
Signed-off-by: Hongyan Xu <[email protected]>
---
.../platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c b/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c
index 8551ab4d2c7d..cce677b5db48 100644
--- a/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c
+++ b/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c
@@ -8,6 +8,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/delay.h>
+#include <linux/devm-helpers.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/extcon.h>
@@ -160,7 +161,6 @@ static int yt2_1380_fc_serdev_probe(struct serdev_device *serdev)
fc->dev = dev;
fc->nb.notifier_call = yt2_1380_fc_extcon_evt;
- INIT_WORK(&fc->work, yt2_1380_fc_worker);
/*
* Do this first since it may return -EPROBE_DEFER.
@@ -209,6 +209,10 @@ static int yt2_1380_fc_serdev_probe(struct serdev_device *serdev)
serdev_device_set_baudrate(serdev, 600);
serdev_device_set_flow_control(serdev, false);
+ ret = devm_work_autocancel(dev, &fc->work, yt2_1380_fc_worker);
+ if (ret)
+ return ret;
+
ret = devm_extcon_register_notifier_all(dev, fc->extcon, &fc->nb);
if (ret)
return dev_err_probe(dev, ret, "registering extcon notifier\n");
--
2.50.1.windows.1