All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power: supply: cros_peripheral_charger: unregister EC notifier
@ 2026-06-15  6:31 Pengpeng Hou
  2026-06-16  5:59 ` Tzung-Bi Shih
  0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-06-15  6:31 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm, linux-kernel
  Cc: pengpeng, Benson Leung, Tzung-Bi Shih, Guenter Roeck,
	chrome-platform

cros_pchg_probe() registers an EC event notifier whose callback uses the
devm-allocated charger_data via container_of().  The driver has no
remove callback and does not unregister the notifier, so the notifier
chain can retain a pointer to freed driver state after unbind or probe
cleanup.

Register a devm cleanup action immediately after the notifier is
installed so the notifier is unregistered before the driver state is
released.  Also fail probe if the notifier cannot be registered, instead
of leaving a charger device that cannot receive EC events.

Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 drivers/power/supply/cros_peripheral_charger.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c
index f132fad288cb..155848da0e32 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_device->event_notifier,
+					   &charger->notifier);
+}
+
 static int cros_pchg_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -346,9 +354,10 @@ 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");
 
-	return 0;
+	return devm_add_action_or_reset(dev, cros_pchg_unregister_notifier,
+					charger);
 }
 
 #ifdef CONFIG_PM_SLEEP
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] power: supply: cros_peripheral_charger: unregister EC notifier
  2026-06-15  6:31 [PATCH] power: supply: cros_peripheral_charger: unregister EC notifier Pengpeng Hou
@ 2026-06-16  5:59 ` Tzung-Bi Shih
  0 siblings, 0 replies; 2+ messages in thread
From: Tzung-Bi Shih @ 2026-06-16  5:59 UTC (permalink / raw)
  To: Pengpeng Hou
  Cc: Sebastian Reichel, linux-pm, linux-kernel, Benson Leung,
	Guenter Roeck, chrome-platform

On Mon, Jun 15, 2026 at 02:31:05PM +0800, Pengpeng Hou wrote:
> cros_pchg_probe() registers an EC event notifier whose callback uses the
> devm-allocated charger_data via container_of().  The driver has no
> remove callback and does not unregister the notifier, so the notifier
> chain can retain a pointer to freed driver state after unbind or probe
> cleanup.
> 
> Register a devm cleanup action immediately after the notifier is
> installed so the notifier is unregistered before the driver state is
> released.  Also fail probe if the notifier cannot be registered, instead
> of leaving a charger device that cannot receive EC events.
> 
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>

A possible nit is to use s/cros_peripheral_charger/cros_pchg/ in the patch
subject to leave more space for the summary.

With or without this,
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-16  5:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-15  6:31 [PATCH] power: supply: cros_peripheral_charger: unregister EC notifier Pengpeng Hou
2026-06-16  5:59 ` Tzung-Bi Shih

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.