* [PATCH v2 0/2] extcon: synchronize all-connector removal and fix Lenovo fastcharger teardown @ 2026-11-15 11:47 Hongyan Xu 2026-11-15 11:47 ` [PATCH v2 1/2] extcon: synchronize all-connector notifier removal Hongyan Xu 2026-11-15 11:47 ` [PATCH v2 2/2] platform/x86: lenovo: cancel fastcharger work on detach Hongyan Xu 0 siblings, 2 replies; 4+ messages in thread From: Hongyan Xu @ 2026-11-15 11:47 UTC (permalink / raw) To: Ilpo J鐩瞨vinen, Hans de Goede Cc: MyungJoo Ham, Chanwoo Choi, Derek J. Clark, Mark Pearson, Rong Zhang, platform-driver-x86, linux-kernel, stable The Lenovo Yoga Tab 2 fastcharger driver releases managed serdev, pinctrl and GPIO resources while its extcon callback can still publish work. Ordering the devres actions alone is not enough because the all-connector raw notifier does not wait for an in-flight callback. Patch 1 converts only the all-connector notifier chain to an atomic chain so unregister waits for callbacks and is safe from interrupt context. The per-ID chains stay raw because some current callbacks perform sleeping regulator operations. Patch 2 then installs the managed work cancellation before the notifier, so reverse devres order stops the producer before releasing the resources it uses. Hongyan Xu (2): extcon: synchronize all-connector notifier removal platform/x86: lenovo: cancel fastcharger work on detach Documentation/driver-api/extcon.rst | 2 +- drivers/extcon/extcon.c | 28 ++++++------------- drivers/extcon/extcon.h | 2 +- .../lenovo/yoga-tab2-pro-1380-fastcharger.c | 6 +++- include/linux/extcon.h | 4 +++ 5 files changed, 20 insertions(+), 22 deletions(-) -- 2.50.1.windows.1 Discovery: found by the author's in-house static analysis tool. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] extcon: synchronize all-connector notifier removal 2026-11-15 11:47 [PATCH v2 0/2] extcon: synchronize all-connector removal and fix Lenovo fastcharger teardown Hongyan Xu @ 2026-11-15 11:47 ` Hongyan Xu 2026-11-16 11:28 ` Ilpo Järvinen 2026-11-15 11:47 ` [PATCH v2 2/2] platform/x86: lenovo: cancel fastcharger work on detach Hongyan Xu 1 sibling, 1 reply; 4+ messages in thread From: Hongyan Xu @ 2026-11-15 11:47 UTC (permalink / raw) To: Ilpo J鐩瞨vinen, Hans de Goede Cc: MyungJoo Ham, Chanwoo Choi, Derek J. Clark, Mark Pearson, Rong Zhang, platform-driver-x86, linux-kernel, stable extcon_sync() invokes the all-connector raw notifier chain after dropping edev->lock. Unregister unlinks a block under that lock but does not wait for an in-flight callback, so managed consumers can release their state while a callback still publishes work. Use an atomic notifier chain for the all-connector notifications. Its RCU read section and synchronized unregister provide the required callback quiescence. Use the notifier implementation's own writer lock and perform its grace-period wait outside edev's spinlock. Document callback and unregister context requirements. The current all-connector consumers defer their operations to work items and their callbacks do not sleep. Per-ID raw chains retain their existing behavior: some OMAP callbacks perform regulator operations and need a separate context-compatible repair. Found by the author's in-house static analysis tool. Fixes: 815429b39d94 ("extcon: Add new extcon_register_notifier_all() to monitor all external connectors") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/2ef4ad43-497f-c40f-b18a-f5b75799d95d@linux.intel.com/ Signed-off-by: Hongyan Xu <getshell@seu.edu.cn> Signed-off-by: Zehao Gao <gaozehao@iie.ac.cn> --- Discovery: found by the author's in-house static analysis tool. Documentation/driver-api/extcon.rst | 2 +- drivers/extcon/extcon.c | 28 +++++++++------------------- drivers/extcon/extcon.h | 2 +- include/linux/extcon.h | 4 ++++ 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Documentation/driver-api/extcon.rst b/Documentation/driver-api/extcon.rst index d3217b9..384d743 100644 --- a/Documentation/driver-api/extcon.rst +++ b/Documentation/driver-api/extcon.rst @@ -70,7 +70,7 @@ The core structure representing an Extcon device:: /* Internal data */ struct device dev; unsigned int id; - struct raw_notifier_head nh_all; + struct atomic_notifier_head nh_all; struct raw_notifier_head *nh; struct list_head entry; int max_supported; diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 98d85cc..b8d8c2a 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -456,10 +456,10 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id) raw_notifier_call_chain(&edev->nh[index], state, edev); /* - * Call functions in a raw notifier chain for the all supported + * Call functions in the atomic notifier chain for all supported * external connectors. */ - raw_notifier_call_chain(&edev->nh_all, state, edev); + atomic_notifier_call_chain(&edev->nh_all, state, edev); spin_lock_irqsave(&edev->lock, flags); /* This could be in interrupt handler */ @@ -967,6 +967,7 @@ EXPORT_SYMBOL_GPL(extcon_unregister_notifier); * * Note that this function registers a notifier block in order to receive * the state change of all supported external connectors from extcon device. + * Callbacks run under the RCU read-side critical section and must not sleep. * And the second parameter given to the callback of nb (val) is * the current state and the third pameter is the pointer of extcon device. * @@ -975,17 +976,10 @@ EXPORT_SYMBOL_GPL(extcon_unregister_notifier); int extcon_register_notifier_all(struct extcon_dev *edev, struct notifier_block *nb) { - unsigned long flags; - int ret; - if (!edev || !nb) return -EINVAL; - spin_lock_irqsave(&edev->lock, flags); - ret = raw_notifier_chain_register(&edev->nh_all, nb); - spin_unlock_irqrestore(&edev->lock, flags); - - return ret; + return atomic_notifier_chain_register(&edev->nh_all, nb); } EXPORT_SYMBOL_GPL(extcon_register_notifier_all); @@ -995,21 +989,17 @@ EXPORT_SYMBOL_GPL(extcon_register_notifier_all); * @nb: a notifier block to be registered * * Returns 0 if success or error number if fail. + * + * Waits for in-flight callbacks. Must be called from process context and + * outside a notifier callback. */ int extcon_unregister_notifier_all(struct extcon_dev *edev, struct notifier_block *nb) { - unsigned long flags; - int ret; - if (!edev || !nb) return -EINVAL; - spin_lock_irqsave(&edev->lock, flags); - ret = raw_notifier_chain_unregister(&edev->nh_all, nb); - spin_unlock_irqrestore(&edev->lock, flags); - - return ret; + return atomic_notifier_chain_unregister(&edev->nh_all, nb); } EXPORT_SYMBOL_GPL(extcon_unregister_notifier_all); @@ -1300,7 +1290,7 @@ int extcon_dev_register(struct extcon_dev *edev) for (index = 0; index < edev->max_supported; index++) RAW_INIT_NOTIFIER_HEAD(&edev->nh[index]); - RAW_INIT_NOTIFIER_HEAD(&edev->nh_all); + ATOMIC_INIT_NOTIFIER_HEAD(&edev->nh_all); dev_set_drvdata(&edev->dev, edev); dev_set_name(&edev->dev, "extcon%d", edev->id); diff --git a/drivers/extcon/extcon.h b/drivers/extcon/extcon.h index 9461826..5a3f0c4 100644 --- a/drivers/extcon/extcon.h +++ b/drivers/extcon/extcon.h @@ -48,7 +48,7 @@ struct extcon_dev { /* Internal data. Please do not set. */ struct device dev; unsigned int id; - struct raw_notifier_head nh_all; + struct atomic_notifier_head nh_all; struct raw_notifier_head *nh; struct list_head entry; int max_supported; diff --git a/include/linux/extcon.h b/include/linux/extcon.h index e596a0a..869bac9 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -209,6 +209,10 @@ void devm_extcon_unregister_notifier(struct device *dev, struct extcon_dev *edev, unsigned int id, struct notifier_block *nb); +/* + * All-connector callbacks must not sleep. Unregister waits for callbacks and + * must be called from process context, outside a notifier callback. + */ int extcon_register_notifier_all(struct extcon_dev *edev, struct notifier_block *nb); int extcon_unregister_notifier_all(struct extcon_dev *edev, -- 2.50.1.windows.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] extcon: synchronize all-connector notifier removal 2026-11-15 11:47 ` [PATCH v2 1/2] extcon: synchronize all-connector notifier removal Hongyan Xu @ 2026-11-16 11:28 ` Ilpo Järvinen 0 siblings, 0 replies; 4+ messages in thread From: Ilpo Järvinen @ 2026-11-16 11:28 UTC (permalink / raw) To: Hongyan Xu Cc: Hans de Goede, MyungJoo Ham, Chanwoo Choi, Derek J. Clark, Mark Pearson, Rong Zhang, platform-driver-x86, LKML, stable On Sun, 15 Nov 2026, Hongyan Xu wrote: > extcon_sync() invokes the all-connector raw notifier chain after > dropping edev->lock. Unregister unlinks a block under that lock but > does not wait for an in-flight callback, so managed consumers can > release their state while a callback still publishes work. > > Use an atomic notifier chain for the all-connector notifications. > Its RCU read section and synchronized unregister provide the > required callback quiescence. Use the notifier implementation's > own writer lock and perform its grace-period wait outside edev's > spinlock. Document callback and unregister context requirements. > > The current all-connector consumers defer their operations to work > items and their callbacks do not sleep. Per-ID raw chains retain > their existing behavior: some OMAP callbacks perform regulator > operations and need a separate context-compatible repair. > > Found by the author's in-house static analysis tool. I think sashiko found this too: Reported-by: Sashiko <sashiko-bot@kernel.org> Closes: https://sashiko.dev/#/patchset/20260806060526.1189-1-getshell%40seu.edu.cn > Fixes: 815429b39d94 ("extcon: Add new extcon_register_notifier_all() to monitor all external connectors") > Cc: stable@vger.kernel.org > Link: https://lore.kernel.org/all/2ef4ad43-497f-c40f-b18a-f5b75799d95d@linux.intel.com/ > Signed-off-by: Hongyan Xu <getshell@seu.edu.cn> > Signed-off-by: Zehao Gao <gaozehao@iie.ac.cn> -- i. > --- > > Discovery: found by the author's in-house static analysis tool. > > Documentation/driver-api/extcon.rst | 2 +- > drivers/extcon/extcon.c | 28 +++++++++------------------- > drivers/extcon/extcon.h | 2 +- > include/linux/extcon.h | 4 ++++ > 4 files changed, 15 insertions(+), 21 deletions(-) > > diff --git a/Documentation/driver-api/extcon.rst b/Documentation/driver-api/extcon.rst > index d3217b9..384d743 100644 > --- a/Documentation/driver-api/extcon.rst > +++ b/Documentation/driver-api/extcon.rst > @@ -70,7 +70,7 @@ The core structure representing an Extcon device:: > /* Internal data */ > struct device dev; > unsigned int id; > - struct raw_notifier_head nh_all; > + struct atomic_notifier_head nh_all; > struct raw_notifier_head *nh; > struct list_head entry; > int max_supported; > diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c > index 98d85cc..b8d8c2a 100644 > --- a/drivers/extcon/extcon.c > +++ b/drivers/extcon/extcon.c > @@ -456,10 +456,10 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id) > raw_notifier_call_chain(&edev->nh[index], state, edev); > > /* > - * Call functions in a raw notifier chain for the all supported > + * Call functions in the atomic notifier chain for all supported > * external connectors. > */ > - raw_notifier_call_chain(&edev->nh_all, state, edev); > + atomic_notifier_call_chain(&edev->nh_all, state, edev); > > spin_lock_irqsave(&edev->lock, flags); > /* This could be in interrupt handler */ > @@ -967,6 +967,7 @@ EXPORT_SYMBOL_GPL(extcon_unregister_notifier); > * > * Note that this function registers a notifier block in order to receive > * the state change of all supported external connectors from extcon device. > + * Callbacks run under the RCU read-side critical section and must not sleep. > * And the second parameter given to the callback of nb (val) is > * the current state and the third pameter is the pointer of extcon device. > * > @@ -975,17 +976,10 @@ EXPORT_SYMBOL_GPL(extcon_unregister_notifier); > int extcon_register_notifier_all(struct extcon_dev *edev, > struct notifier_block *nb) > { > - unsigned long flags; > - int ret; > - > if (!edev || !nb) > return -EINVAL; > > - spin_lock_irqsave(&edev->lock, flags); > - ret = raw_notifier_chain_register(&edev->nh_all, nb); > - spin_unlock_irqrestore(&edev->lock, flags); > - > - return ret; > + return atomic_notifier_chain_register(&edev->nh_all, nb); > } > EXPORT_SYMBOL_GPL(extcon_register_notifier_all); > > @@ -995,21 +989,17 @@ EXPORT_SYMBOL_GPL(extcon_register_notifier_all); > * @nb: a notifier block to be registered > * > * Returns 0 if success or error number if fail. > + * > + * Waits for in-flight callbacks. Must be called from process context and > + * outside a notifier callback. > */ > int extcon_unregister_notifier_all(struct extcon_dev *edev, > struct notifier_block *nb) > { > - unsigned long flags; > - int ret; > - > if (!edev || !nb) > return -EINVAL; > > - spin_lock_irqsave(&edev->lock, flags); > - ret = raw_notifier_chain_unregister(&edev->nh_all, nb); > - spin_unlock_irqrestore(&edev->lock, flags); > - > - return ret; > + return atomic_notifier_chain_unregister(&edev->nh_all, nb); > } > EXPORT_SYMBOL_GPL(extcon_unregister_notifier_all); > > @@ -1300,7 +1290,7 @@ int extcon_dev_register(struct extcon_dev *edev) > for (index = 0; index < edev->max_supported; index++) > RAW_INIT_NOTIFIER_HEAD(&edev->nh[index]); > > - RAW_INIT_NOTIFIER_HEAD(&edev->nh_all); > + ATOMIC_INIT_NOTIFIER_HEAD(&edev->nh_all); > > dev_set_drvdata(&edev->dev, edev); > dev_set_name(&edev->dev, "extcon%d", edev->id); > diff --git a/drivers/extcon/extcon.h b/drivers/extcon/extcon.h > index 9461826..5a3f0c4 100644 > --- a/drivers/extcon/extcon.h > +++ b/drivers/extcon/extcon.h > @@ -48,7 +48,7 @@ struct extcon_dev { > /* Internal data. Please do not set. */ > struct device dev; > unsigned int id; > - struct raw_notifier_head nh_all; > + struct atomic_notifier_head nh_all; > struct raw_notifier_head *nh; > struct list_head entry; > int max_supported; > diff --git a/include/linux/extcon.h b/include/linux/extcon.h > index e596a0a..869bac9 100644 > --- a/include/linux/extcon.h > +++ b/include/linux/extcon.h > @@ -209,6 +209,10 @@ void devm_extcon_unregister_notifier(struct device *dev, > struct extcon_dev *edev, unsigned int id, > struct notifier_block *nb); > > +/* > + * All-connector callbacks must not sleep. Unregister waits for callbacks and > + * must be called from process context, outside a notifier callback. > + */ > int extcon_register_notifier_all(struct extcon_dev *edev, > struct notifier_block *nb); > int extcon_unregister_notifier_all(struct extcon_dev *edev, > ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] platform/x86: lenovo: cancel fastcharger work on detach 2026-11-15 11:47 [PATCH v2 0/2] extcon: synchronize all-connector removal and fix Lenovo fastcharger teardown Hongyan Xu 2026-11-15 11:47 ` [PATCH v2 1/2] extcon: synchronize all-connector notifier removal Hongyan Xu @ 2026-11-15 11:47 ` Hongyan Xu 1 sibling, 0 replies; 4+ messages in thread From: Hongyan Xu @ 2026-11-15 11:47 UTC (permalink / raw) To: Ilpo J鐩瞨vinen, Hans de Goede Cc: MyungJoo Ham, Chanwoo Choi, Derek J. Clark, Mark Pearson, Rong Zhang, platform-driver-x86, linux-kernel, stable 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@vger.kernel.org Link: https://lore.kernel.org/all/20260806060526.1189-1-getshell@seu.edu.cn/ Signed-off-by: Hongyan Xu <getshell@seu.edu.cn> Signed-off-by: Zehao Gao <gaozehao@iie.ac.cn> --- 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"); -- 2.50.1.windows.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-16 11:28 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-15 11:47 [PATCH v2 0/2] extcon: synchronize all-connector removal and fix Lenovo fastcharger teardown Hongyan Xu 2026-11-15 11:47 ` [PATCH v2 1/2] extcon: synchronize all-connector notifier removal Hongyan Xu 2026-11-16 11:28 ` Ilpo Järvinen 2026-11-15 11:47 ` [PATCH v2 2/2] platform/x86: lenovo: cancel fastcharger work on detach Hongyan Xu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox