mirror of
https://github.com/torvalds/linux.git
synced 2026-09-26 10:02:02 +02:00
power: supply: bq25890: Fix power_supply reference leak
bq25890_fw_probe() acquires a reference to a secondary charger using
power_supply_get_by_name(), but the reference is not released on later
probe failures or on driver detach.
In particular, failures after bq25890_fw_probe() returns successfully,
such as a failure in bq25890_hw_init(), also leak the reference.
Register a device-managed cleanup action immediately after acquiring
the secondary charger. This releases the reference on all subsequent
probe failures and on driver detach.
Found by code review.
Signed-off-by: Ma Ke <make_ruc2021@163.com>
Cc: stable@vger.kernel.org
Fixes: d54bf877fd ("power: supply: bq25890: Add support for having a secondary charger IC")
Link: https://patch.msgid.link/20260722044416.1623621-1-make_ruc2021@163.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
af4ee48a09
commit
863c32a83e
|
|
@ -1389,6 +1389,14 @@ static int bq25890_fw_read_u32_props(struct bq25890_device *bq)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void bq25890_release_secondary_chrg(void *data)
|
||||
{
|
||||
struct bq25890_device *bq = data;
|
||||
|
||||
power_supply_put(bq->secondary_chrg);
|
||||
bq->secondary_chrg = NULL;
|
||||
}
|
||||
|
||||
static int bq25890_fw_probe(struct bq25890_device *bq)
|
||||
{
|
||||
int ret;
|
||||
|
|
@ -1401,6 +1409,10 @@ static int bq25890_fw_probe(struct bq25890_device *bq)
|
|||
bq->secondary_chrg = power_supply_get_by_name(str);
|
||||
if (!bq->secondary_chrg)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
ret = devm_add_action_or_reset(bq->dev, bq25890_release_secondary_chrg, bq);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Optional, left at 0 if property is not present */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user