[PATCH] power: supply: Reset err after not finding static battery

Yassine Oudjana posted 1 patch 4 years, 2 months ago
drivers/power/supply/power_supply_core.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] power: supply: Reset err after not finding static battery
Posted by Yassine Oudjana 4 years, 2 months ago
Otherwise power_supply_get_battery_info always returns -ENODEV
on devices that do not have a static battery, even when a simple
battery is found.

Fixes: c8aee3f41cb8 ("power: supply: Static data for Samsung batteries")
Signed-off-by: Yassine Oudjana <y.oudjana@protonmail.com>
---
 drivers/power/supply/power_supply_core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index ea02c8dcd748..d925cb137e12 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -604,6 +604,12 @@ int power_supply_get_battery_info(struct power_supply *psy,
 	err = samsung_sdi_battery_get_info(&psy->dev, value, &info);
 	if (!err)
 		goto out_ret_pointer;
+	else if (err == -ENODEV)
+		/*
+		 * Device does not have a static battery.
+		 * Proceed to look for a simple battery.
+		 */
+		err = 0;
 
 	if (strcmp("simple-battery", value)) {
 		err = -ENODEV;
-- 
2.35.1
Re: [PATCH] power: supply: Reset err after not finding static battery
Posted by Linus Walleij 4 years, 2 months ago
On Tue, Mar 29, 2022 at 5:34 AM Yassine Oudjana
<y.oudjana@protonmail.com> wrote:

> Otherwise power_supply_get_battery_info always returns -ENODEV
> on devices that do not have a static battery, even when a simple
> battery is found.
>
> Fixes: c8aee3f41cb8 ("power: supply: Static data for Samsung batteries")
> Signed-off-by: Yassine Oudjana <y.oudjana@protonmail.com>

Quick and nice fix, thanks a lot!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij