[PATCH] power: supply: bq25890: Fix secondary_chrg leak in bq25890_fw_probe()

Wentao Liang posted 1 patch 1 week ago
drivers/power/supply/bq25890_charger.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] power: supply: bq25890: Fix secondary_chrg leak in bq25890_fw_probe()
Posted by Wentao Liang 1 week ago
bq25890_fw_probe() takes a reference on the secondary charger power
supply with power_supply_get_by_name(), but returns without releasing
it when linux,iinlim-percentage is out of range or when
bq25890_fw_read_u32_props() fails. Drop the reference on both error
paths to avoid leaking it.

Fixes: d54bf877fd87 ("power: supply: bq25890: Add support for having a secondary charger IC")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/power/supply/bq25890_charger.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index 868e86e1749b..0e8ebab1723e 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -1411,6 +1411,7 @@ static int bq25890_fw_probe(struct bq25890_device *bq)
 	if (ret == 0) {
 		if (val > 100) {
 			dev_err(bq->dev, "Error linux,iinlim-percentage %u > 100\n", val);
+			power_supply_put(bq->secondary_chrg);
 			return -EINVAL;
 		}
 		bq->iinlim_percentage = val;
@@ -1425,8 +1426,10 @@ static int bq25890_fw_probe(struct bq25890_device *bq)
 		return 0;
 
 	ret = bq25890_fw_read_u32_props(bq);
-	if (ret < 0)
+	if (ret < 0) {
+		power_supply_put(bq->secondary_chrg);
 		return ret;
+	}
 
 	init->ilim_en = device_property_read_bool(bq->dev, "ti,use-ilim-pin");
 	init->boostf = device_property_read_bool(bq->dev, "ti,boost-low-freq");
-- 
2.34.1