* [PATCH] power: supply: cros_pchg: unregister EC notifier
@ 2026-07-28 12:33 Hongyan Xu
0 siblings, 0 replies; only message in thread
From: Hongyan Xu @ 2026-07-28 12:33 UTC (permalink / raw)
To: sre; +Cc: Hongyan Xu, linux-pm, linux-kernel, jianhao.xu
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-28 12:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28 12:33 [PATCH] power: supply: cros_pchg: unregister EC notifier Hongyan Xu
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.