[PATCH] power: supply: cros_pchg: unregister EC notifier

From: Hongyan Xu

Date: Tue Jul 28 2026 - 08:43:29 EST


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@xxxxxxxxxx>
---
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