Re: [PATCH v2 2/2] platform/x86: lenovo: cancel fastcharger work on detach

From: Rong Zhang

Date: Mon Nov 16 2026 - 08:06:15 EST


Hi Hongyan,

On Sun, 2026-11-15 at 19:47 +0800, Hongyan Xu wrote:
> The extcon callback schedules a worker which uses managed serdev,
> pinctrl and GPIO resources. Releasing those resources while the
> worker remains pending or running can access invalid state.
>
> Install managed work cancellation after the UART is opened and
> before registering the managed notifier. Reverse devres order
> then unregisters and waits for notifier callbacks, drains the
> worker and only afterwards closes the UART and frees its pin
> resources. This depends on the preceding all-connector notifier
> synchronization patch; resource order alone is insufficient.
>
> The actual lc824206xa supplier notifies from work context, and
> this consumer callback only schedules work. The callback must not
> outlive synchronized unregister or republish after cancellation.
>
> Found by the author's in-house static analysis tool.
>
> Fixes: b2ed33e8d486 ("platform/x86: Add lenovo-yoga-tab2-pro-1380-fastcharger driver")
> Cc: stable@xxxxxxxxxxxxxxx
> Link: https://lore.kernel.org/all/20260806060526.1189-1-getshell@xxxxxxxxxx/
> Signed-off-by: Hongyan Xu <getshell@xxxxxxxxxx>
> Signed-off-by: Zehao Gao <gaozehao@xxxxxxxxx>

The submitter's S-o-b should be placed at last.

(+CC Zehao)

And how did Zehao contribute to the series? You didn't even CC them!

(+CC Hyunjung)

Hyunjung is also working on this. See
https://msgid.link/20261116122001.3096223-1-hj351016@xxxxxxxxx

Thanks,
Rong

> ---
>
> Discovery: found by the author's in-house static analysis tool.
>
> .../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 9e2ac80..51ff383 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");