From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Hongyan Xu <getshell@seu.edu.cn>
Cc: Hans de Goede <hansg@kernel.org>,
MyungJoo Ham <myungjoo.ham@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
"Derek J. Clark" <derekjohn.clark@gmail.com>,
Mark Pearson <mpearson-lenovo@squebb.ca>,
Rong Zhang <i@rong.moe>,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH v2 1/2] extcon: synchronize all-connector notifier removal
Date: Mon, 16 Nov 2026 13:28:00 +0200 (EET) [thread overview]
Message-ID: <4f3601df-029b-0ee9-41ea-c0ec29c5f80d@linux.intel.com> (raw)
In-Reply-To: <179474326273.103840.4798359664806814358@seu.edu.cn>
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,
>
next prev parent reply other threads:[~2026-11-16 11:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-15 11:47 ` [PATCH v2 2/2] platform/x86: lenovo: cancel fastcharger work on detach Hongyan Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f3601df-029b-0ee9-41ea-c0ec29c5f80d@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=cw00.choi@samsung.com \
--cc=derekjohn.clark@gmail.com \
--cc=getshell@seu.edu.cn \
--cc=hansg@kernel.org \
--cc=i@rong.moe \
--cc=linux-kernel@vger.kernel.org \
--cc=mpearson-lenovo@squebb.ca \
--cc=myungjoo.ham@samsung.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox