diff mbox series

[v5,2/8] power: ip5xxx_power: Fix return value on ADC read errors

Message ID 20241119180741.2237692-2-csokas.bence@prolan.hu
State New
Headers show
Series [v5,1/8] power: ip5xxx_power: Use regmap_field API | expand

Commit Message

Bence Csókás Nov. 19, 2024, 6:07 p.m. UTC
If ADC read returns an error, the return value was silently ignored,
execution continued and an uninitialized value and a return code of 0
was passed back to userspace. The only exception was
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, which bailed out correctly.
Fix returns for the other cases as well.

Fixes: 75853406fa27 ("power: supply: Add a driver for Injoinic power bank ICs")

Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
---
 drivers/power/supply/ip5xxx_power.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Sebastian Reichel Dec. 5, 2024, 11 a.m. UTC | #1
Hi,

On Tue, Nov 19, 2024 at 07:07:34PM +0100, Csókás, Bence wrote:
> If ADC read returns an error, the return value was silently ignored,
> execution continued and an uninitialized value and a return code of 0
> was passed back to userspace. The only exception was
> POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, which bailed out correctly.
> Fix returns for the other cases as well.
> 
> Fixes: 75853406fa27 ("power: supply: Add a driver for Injoinic power bank ICs")
> 

No newline between Fixes and Signed-off-by.

> Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
> ---

Fixes should always be at the start of a patch series, so that they
can easily be backported. I fixed both things up when applying the
patch.

Greetings,

-- Sebastian

>  drivers/power/supply/ip5xxx_power.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/power/supply/ip5xxx_power.c b/drivers/power/supply/ip5xxx_power.c
> index 2d4435881a9e..41d91504eb32 100644
> --- a/drivers/power/supply/ip5xxx_power.c
> +++ b/drivers/power/supply/ip5xxx_power.c
> @@ -395,18 +395,24 @@ static int ip5xxx_battery_get_property(struct power_supply *psy,
>  
>  	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
>  		ret = ip5xxx_battery_read_adc(ip5xxx, &ip5xxx->regs.battery.adc.volt, &raw);
> +		if (ret)
> +			return ret;
>  
>  		val->intval = 2600000 + DIV_ROUND_CLOSEST(raw * 26855, 100);
>  		return 0;
>  
>  	case POWER_SUPPLY_PROP_VOLTAGE_OCV:
>  		ret = ip5xxx_battery_read_adc(ip5xxx, &ip5xxx->regs.battery.adc.open_volt, &raw);
> +		if (ret)
> +			return ret;
>  
>  		val->intval = 2600000 + DIV_ROUND_CLOSEST(raw * 26855, 100);
>  		return 0;
>  
>  	case POWER_SUPPLY_PROP_CURRENT_NOW:
>  		ret = ip5xxx_battery_read_adc(ip5xxx, &ip5xxx->regs.battery.adc.curr, &raw);
> +		if (ret)
> +			return ret;
>  
>  		val->intval = DIV_ROUND_CLOSEST(raw * 149197, 200);
>  		return 0;
> -- 
> 2.34.1
> 
> 
>
diff mbox series

Patch

diff --git a/drivers/power/supply/ip5xxx_power.c b/drivers/power/supply/ip5xxx_power.c
index 2d4435881a9e..41d91504eb32 100644
--- a/drivers/power/supply/ip5xxx_power.c
+++ b/drivers/power/supply/ip5xxx_power.c
@@ -395,18 +395,24 @@  static int ip5xxx_battery_get_property(struct power_supply *psy,
 
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
 		ret = ip5xxx_battery_read_adc(ip5xxx, &ip5xxx->regs.battery.adc.volt, &raw);
+		if (ret)
+			return ret;
 
 		val->intval = 2600000 + DIV_ROUND_CLOSEST(raw * 26855, 100);
 		return 0;
 
 	case POWER_SUPPLY_PROP_VOLTAGE_OCV:
 		ret = ip5xxx_battery_read_adc(ip5xxx, &ip5xxx->regs.battery.adc.open_volt, &raw);
+		if (ret)
+			return ret;
 
 		val->intval = 2600000 + DIV_ROUND_CLOSEST(raw * 26855, 100);
 		return 0;
 
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		ret = ip5xxx_battery_read_adc(ip5xxx, &ip5xxx->regs.battery.adc.curr, &raw);
+		if (ret)
+			return ret;
 
 		val->intval = DIV_ROUND_CLOSEST(raw * 149197, 200);
 		return 0;