mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 05:04:02 +02:00
power: supply: cros_pchg: unregister EC notifier
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> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Link: https://patch.msgid.link/20260615063105.39152-1-pengpeng@iscas.ac.cn Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
402684c39c
commit
631adfa035
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user