power: supply: cros_pchg: unregister EC notifier
PATCH 1/1 power: supply: cros_pchg: unregister EC notifier
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 <[email protected]>
--- drivers/power/supply/cros_peripheral_charger.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/power/supply/cros_peripheral_charger.c +15 -1
@@ -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 ; }
Signature · 1 line
2.50.1.windows.1