diff mbox series

power: supply: Fix uninitialized variable in ip5xxx_battery_set_property

Message ID 20241209212323.71228-1-karprzy7@gmail.com
State New
Headers show
Series power: supply: Fix uninitialized variable in ip5xxx_battery_set_property | expand

Commit Message

Karol P Dec. 9, 2024, 9:23 p.m. UTC
The variable vmax in the ip5xxx_battery_set_property function is used uninitialized when passed to switch/case statements.

This patch initializes vmax to 0 at declaration.

Issue discovered in coverity, CID 1602239

Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
---
 drivers/power/supply/ip5xxx_power.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Csókás Bence Dec. 9, 2024, 11:09 p.m. UTC | #1
Hi,

On 2024. 12. 09. 22:23, Karol Przybylski wrote:
> The variable vmax in the ip5xxx_battery_set_property function is used uninitialized when passed to switch/case statements.
> 
> This patch initializes vmax to 0 at declaration.
> 
> Issue discovered in coverity, CID 1602239
> 
> Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
> ---
>   drivers/power/supply/ip5xxx_power.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/ip5xxx_power.c b/drivers/power/supply/ip5xxx_power.c
> index 4bcf0ea0e..65d3266c3 100644
> --- a/drivers/power/supply/ip5xxx_power.c
> +++ b/drivers/power/supply/ip5xxx_power.c
> @@ -541,7 +541,7 @@ static int ip5xxx_battery_set_property(struct power_supply *psy,
>   {
>   	struct ip5xxx *ip5xxx = power_supply_get_drvdata(psy);
>   	unsigned int rval;
> -	int ret, vmax;
> +	int ret, vmax = 0;
>   
>   	ret = ip5xxx_initialize(psy);
>   	if (ret)

This is not the proper way to fix this. See my patch below.
Link: 
https://lore.kernel.org/linux-kernel/20241208131532.1028581-1-csokas.bence@prolan.hu/

Bence
diff mbox series

Patch

diff --git a/drivers/power/supply/ip5xxx_power.c b/drivers/power/supply/ip5xxx_power.c
index 4bcf0ea0e..65d3266c3 100644
--- a/drivers/power/supply/ip5xxx_power.c
+++ b/drivers/power/supply/ip5xxx_power.c
@@ -541,7 +541,7 @@  static int ip5xxx_battery_set_property(struct power_supply *psy,
 {
 	struct ip5xxx *ip5xxx = power_supply_get_drvdata(psy);
 	unsigned int rval;
-	int ret, vmax;
+	int ret, vmax = 0;
 
 	ret = ip5xxx_initialize(psy);
 	if (ret)