Skip to contentSkip to conversation

backlight: lp855x: fix unintialized function return

PATCH In review Arnd Bergmann 2 participants 2 messages Aug 11, 2023 – Aug 14, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backlight: lp855x: fix unintialized function return

From: Arnd Bergmann <[email protected]>

The function now returns an error code in some cases, but fails to initialize it in others:

drivers/video/backlight/lp855x_bl.c:252:11: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

        else if (lp->mode == REGISTER_BASED)
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/video/backlight/lp855x_bl.c:256:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/video/backlight/lp855x_bl.c:252:7: note: remove the 'if' if its condition is always true
        else if (lp->mode == REGISTER_BASED)
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Since this case should not actually happen, return the -EINVAL code.

Fixes 5145531be5fba ("backlight: lp855x: Catch errors when changing brightness")
---
 drivers/video/backlight/lp855x_bl.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/video/backlight/lp855x_bl.c +2 -0
index 61a7f45bfad84..ea4fa69e49a70 100644
@@ -252,6 +252,8 @@ static int lp855x_bl_update_status(struct backlight_device *bl)
 	else if (lp->mode == REGISTER_BASED)
 		ret = lp855x_write_byte(lp, lp->cfg->reg_brightness,
 					(u8)brightness);
+	else
+		ret = -EINVAL;
 
 	return ret;
 }
Signature · 1 line
2.39.2
#1 lore raw
Quoted 15 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The function now returns an error code in some cases, but fails to initialize it in others:

drivers/video/backlight/lp855x_bl.c:252:11: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

        else if (lp->mode == REGISTER_BASED)
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/video/backlight/lp855x_bl.c:256:9: note: uninitialized use occurs here
        return ret;
               ^~~
drivers/video/backlight/lp855x_bl.c:252:7: note: remove the 'if' if its condition is always true
        else if (lp->mode == REGISTER_BASED)
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 4 lines

Since this case should not actually happen, return the -EINVAL code.

Fixes 5145531be5fba ("backlight: lp855x: Catch errors when changing brightness")

I think we already received a patch for this:
https://lore.kernel.org/lkml/[email protected]/T/

Daniel.