All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hongyan Xu <getshell@seu.edu.cn>
To: sre@kernel.org
Cc: Hongyan Xu <getshell@seu.edu.cn>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	jianhao.xu@seu.edu.cn
Subject: [PATCH] power: supply: cros_pchg: unregister EC notifier
Date: Tue, 28 Jul 2026 20:33:38 +0800	[thread overview]
Message-ID: <20260728123423.781-4-getshell@seu.edu.cn> (raw)

cros_pchg_probe() registers charger->notifier on the EC event notifier
chain. The driver has no remove hook, so the notifier can outlive the
devm-allocated charger.

Use devm_add_action_or_reset() to unregister the notifier on detach, and
fail probe if notifier registration fails.

This issue was found by a static analysis tool.

Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
---
 drivers/power/supply/cros_peripheral_charger.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c
index 962a6fd29..219cd13d6 100644
--- a/drivers/power/supply/cros_peripheral_charger.c
+++ b/drivers/power/supply/cros_peripheral_charger.c
@@ -259,6 +259,14 @@ static int cros_ec_notify(struct notifier_block *nb,
 	return cros_pchg_event(charger);
 }
 
+static void cros_pchg_unregister_notifier(void *data)
+{
+	struct charger_data *charger = data;
+
+	blocking_notifier_chain_unregister(&charger->ec_dev->ec_dev->event_notifier,
+					   &charger->notifier);
+}
+
 static int cros_pchg_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -346,7 +354,13 @@ static int cros_pchg_probe(struct platform_device *pdev)
 	ret = blocking_notifier_chain_register(&ec_dev->ec_dev->event_notifier,
 					       nb);
 	if (ret < 0)
-		dev_err(dev, "Failed to register notifier (err:%d)\n", ret);
+		return dev_err_probe(dev, ret,
+				     "Failed to register notifier\n");
+
+	ret = devm_add_action_or_reset(dev, cros_pchg_unregister_notifier,
+				       charger);
+	if (ret)
+		return ret;
 
 	return 0;
 }
-- 
2.50.1.windows.1

                 reply	other threads:[~2026-07-28 12:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260728123423.781-4-getshell@seu.edu.cn \
    --to=getshell@seu.edu.cn \
    --cc=jianhao.xu@seu.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.