* [PATCH 3/4] power: supply: rk817: Fix battery info memory leak on error paths
@ 2026-06-18 13:21 Uday Khare
2026-07-20 21:59 ` Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: Uday Khare @ 2026-06-18 13:21 UTC (permalink / raw)
To: sre; +Cc: linux-pm, linux-kernel, Uday Khare
In rk817_charger_probe(), power_supply_get_battery_info() is called to
retrieve battery info. However, if the sanity check for required battery
properties fails, or if rk817_battery_init() returns an error, the
function returns immediately without calling
power_supply_put_battery_info() to release the allocated battery info
structure, causing a memory leak.
Fix this by introducing an error label 'err_put_bat_info' that calls
power_supply_put_battery_info() before returning the error code, and
jumping to it from both error paths.
Fixes: 11cb8da0189b ("power: supply: Add charger driver for Rockchip RK817")
Signed-off-by: Uday Khare <udaykhare77@gmail.com>
---
drivers/power/supply/rk817_charger.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c
index 9436c6bbf51f..a2ca2b46b2f2 100644
--- a/drivers/power/supply/rk817_charger.c
+++ b/drivers/power/supply/rk817_charger.c
@@ -1156,8 +1156,10 @@ static int rk817_charger_probe(struct platform_device *pdev)
(bat_info->constant_charge_voltage_max_uv <= 0) ||
(bat_info->constant_charge_current_max_ua <= 0) ||
(bat_info->charge_term_current_ua <= 0)) {
- return dev_err_probe(dev, -EINVAL,
- "Required bat info missing or invalid\n");
+ dev_err_probe(dev, -EINVAL,
+ "Required bat info missing or invalid\n");
+ ret = -EINVAL;
+ goto err_put_bat_info;
}
charger->bat_charge_full_design_uah = bat_info->charge_full_design_uah;
@@ -1170,7 +1172,7 @@ static int rk817_charger_probe(struct platform_device *pdev)
*/
ret = rk817_battery_init(charger, bat_info);
if (ret)
- return ret;
+ goto err_put_bat_info;
power_supply_put_battery_info(charger->bat_ps, bat_info);
@@ -1209,6 +1211,10 @@ static int rk817_charger_probe(struct platform_device *pdev)
mod_delayed_work(system_percpu_wq, &charger->work, 0);
return 0;
+
+err_put_bat_info:
+ power_supply_put_battery_info(charger->bat_ps, bat_info);
+ return ret;
}
static int __maybe_unused rk817_suspend(struct device *dev)
--
2.54.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 3/4] power: supply: rk817: Fix battery info memory leak on error paths
2026-06-18 13:21 [PATCH 3/4] power: supply: rk817: Fix battery info memory leak on error paths Uday Khare
@ 2026-07-20 21:59 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2026-07-20 21:59 UTC (permalink / raw)
To: Uday Khare; +Cc: linux-pm, linux-kernel
Hi,
On Thu, Jun 18, 2026 at 06:51:51PM +0530, Uday Khare wrote:
> In rk817_charger_probe(), power_supply_get_battery_info() is called to
> retrieve battery info. However, if the sanity check for required battery
> properties fails, or if rk817_battery_init() returns an error, the
> function returns immediately without calling
> power_supply_put_battery_info() to release the allocated battery info
> structure, causing a memory leak.
>
> Fix this by introducing an error label 'err_put_bat_info' that calls
> power_supply_put_battery_info() before returning the error code, and
> jumping to it from both error paths.
>
> Fixes: 11cb8da0189b ("power: supply: Add charger driver for Rockchip RK817")
> Signed-off-by: Uday Khare <udaykhare77@gmail.com>
> ---
What is this patch 3/4 and why do you think memory is leaked even
though device managed resources are being used internally?
-- Sebastian
> drivers/power/supply/rk817_charger.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c
> index 9436c6bbf51f..a2ca2b46b2f2 100644
> --- a/drivers/power/supply/rk817_charger.c
> +++ b/drivers/power/supply/rk817_charger.c
> @@ -1156,8 +1156,10 @@ static int rk817_charger_probe(struct platform_device *pdev)
> (bat_info->constant_charge_voltage_max_uv <= 0) ||
> (bat_info->constant_charge_current_max_ua <= 0) ||
> (bat_info->charge_term_current_ua <= 0)) {
> - return dev_err_probe(dev, -EINVAL,
> - "Required bat info missing or invalid\n");
> + dev_err_probe(dev, -EINVAL,
> + "Required bat info missing or invalid\n");
> + ret = -EINVAL;
> + goto err_put_bat_info;
> }
>
> charger->bat_charge_full_design_uah = bat_info->charge_full_design_uah;
> @@ -1170,7 +1172,7 @@ static int rk817_charger_probe(struct platform_device *pdev)
> */
> ret = rk817_battery_init(charger, bat_info);
> if (ret)
> - return ret;
> + goto err_put_bat_info;
>
> power_supply_put_battery_info(charger->bat_ps, bat_info);
>
> @@ -1209,6 +1211,10 @@ static int rk817_charger_probe(struct platform_device *pdev)
> mod_delayed_work(system_percpu_wq, &charger->work, 0);
>
> return 0;
> +
> +err_put_bat_info:
> + power_supply_put_battery_info(charger->bat_ps, bat_info);
> + return ret;
> }
>
> static int __maybe_unused rk817_suspend(struct device *dev)
> --
> 2.54.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-20 22:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-18 13:21 [PATCH 3/4] power: supply: rk817: Fix battery info memory leak on error paths Uday Khare
2026-07-20 21:59 ` Sebastian Reichel
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.