backlight: adp88x0: fix uninitialized variable use
Subsystems (3)
PATCH 1/1 backlight: adp88x0: fix uninitialized variable use
gcc correctly warns about both the adp8860 and adp8870 backlight drivers using an uninitialized variable in their error handling path:
drivers/video/backlight/adp8870_bl.c: In function 'adp8870_bl_ambient_light_zone_store':drivers/video/backlight/adp8870_bl.c:811:11: warning: 'reg_val' may be used uninitialized in this function
This changes the code to only write back the data if it was correctly read to start with.
As a side-note, the drivers are mostly identical, so I think they should really be merged into one file to avoid having to fix every bug twice.
drivers/video/backlight/adp8860_bl.c +6 -4
@@ -621,10 +621,12 @@ static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev,/* Set user supplied ambient light zone */ mutex_lock (&data->lock); -adp8860_read (data->client,ADP8860_CFGR , ®_val); - reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); - reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; -adp8860_write (data->client,ADP8860_CFGR , reg_val); + ret =adp8860_read (data->client,ADP8860_CFGR , ®_val); +if (!ret) { + reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); + reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; +adp8860_write (data->client,ADP8860_CFGR , reg_val); + }mutex_unlock (&data->lock); }
drivers/video/backlight/adp8870_bl.c +6 -4
@@ -807,10 +807,12 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,/* Set user supplied ambient light zone */ mutex_lock (&data->lock); -adp8870_read (data->client,ADP8870_CFGR , ®_val); - reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); - reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; -adp8870_write (data->client,ADP8870_CFGR , reg_val); + ret =adp8870_read (data->client,ADP8870_CFGR , ®_val); +if (!ret) { + reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); + reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; +adp8870_write (data->client,ADP8870_CFGR , reg_val); + }mutex_unlock (&data->lock); }
Quoted 7 lines · Arnd Bergmann
gcc correctly warns about both the adp8860 and adp8870 backlight drivers using an uninitialized variable in their error handling path:
drivers/video/backlight/adp8870_bl.c: In function 'adp8870_bl_ambient_light_zone_store':drivers/video/backlight/adp8870_bl.c:811:11: warning: 'reg_val' may be used uninitialized in this function
Quoted 8 lines
This changes the code to only write back the data if it was correctly read to start with.
As a side-note, the drivers are mostly identical, so I think they should really be merged into one file to avoid having to fix every bug twice.
Signed-off-by Arnd Bergmann <[email protected]>
Quoted 44 lines
drivers/video/backlight/adp8860_bl.c +6
-4@@ -621,10 +621,12 @@ static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev,/* Set user supplied ambient light zone */ mutex_lock (&data->lock); -adp8860_read (data->client,ADP8860_CFGR , ®_val); - reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); - reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; -adp8860_write (data->client,ADP8860_CFGR , reg_val); + ret =adp8860_read (data->client,ADP8860_CFGR , ®_val); +if (!ret) { + reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); + reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; +adp8860_write (data->client,ADP8860_CFGR , reg_val); + }mutex_unlock (&data->lock); }drivers/video/backlight/adp8870_bl.c +6
-4@@ -807,10 +807,12 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,/* Set user supplied ambient light zone */ mutex_lock (&data->lock); -adp8870_read (data->client,ADP8870_CFGR , ®_val); - reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); - reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; -adp8870_write (data->client,ADP8870_CFGR , reg_val); + ret =adp8870_read (data->client,ADP8870_CFGR , ®_val); +if (!ret) { + reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); + reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; +adp8870_write (data->client,ADP8870_CFGR , reg_val); + }mutex_unlock (&data->lock); }
Signature · 8 lines
Greetings, Michael -- Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif
Lee Jones
AppliedQuoted 7 lines · Arnd Bergmann
gcc correctly warns about both the adp8860 and adp8870 backlight drivers using an uninitialized variable in their error handling path:
drivers/video/backlight/adp8870_bl.c: In function 'adp8870_bl_ambient_light_zone_store':drivers/video/backlight/adp8870_bl.c:811:11: warning: 'reg_val' may be used uninitialized in this function
Quoted 8 lines
This changes the code to only write back the data if it was correctly read to start with.
As a side-note, the drivers are mostly identical, so I think they should really be merged into one file to avoid having to fix every bug twice.
Signed-off-by Arnd Bergmann <[email protected]>
Applied, thanks.
Quoted 43 lines
drivers/video/backlight/adp8860_bl.c +6
-4@@ -621,10 +621,12 @@ static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev,/* Set user supplied ambient light zone */ mutex_lock (&data->lock); -adp8860_read (data->client,ADP8860_CFGR , ®_val); - reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); - reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; -adp8860_write (data->client,ADP8860_CFGR , reg_val); + ret =adp8860_read (data->client,ADP8860_CFGR , ®_val); +if (!ret) { + reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); + reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; +adp8860_write (data->client,ADP8860_CFGR , reg_val); + }mutex_unlock (&data->lock); }drivers/video/backlight/adp8870_bl.c +6
-4@@ -807,10 +807,12 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,/* Set user supplied ambient light zone */ mutex_lock (&data->lock); -adp8870_read (data->client,ADP8870_CFGR , ®_val); - reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); - reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; -adp8870_write (data->client,ADP8870_CFGR , reg_val); + ret =adp8870_read (data->client,ADP8870_CFGR , ®_val); +if (!ret) { + reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); + reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; +adp8870_write (data->client,ADP8870_CFGR , reg_val); + }mutex_unlock (&data->lock); }
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Quoted 7 lines · Arnd Bergmann
gcc correctly warns about both the adp8860 and adp8870 backlight drivers using an uninitialized variable in their error handling path:
drivers/video/backlight/adp8870_bl.c: In function 'adp8870_bl_ambient_light_zone_store':drivers/video/backlight/adp8870_bl.c:811:11: warning: 'reg_val' may be used uninitialized in this function
Quoted 8 lines
This changes the code to only write back the data if it was correctly read to start with.
As a side-note, the drivers are mostly identical, so I think they should really be merged into one file to avoid having to fix every bug twice.
Signed-off-by Arnd Bergmann <[email protected]>
Applied with the $SUBJECT line fixed.
Quoted 43 lines
drivers/video/backlight/adp8860_bl.c +6
-4@@ -621,10 +621,12 @@ static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev,/* Set user supplied ambient light zone */ mutex_lock (&data->lock); -adp8860_read (data->client,ADP8860_CFGR , ®_val); - reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); - reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; -adp8860_write (data->client,ADP8860_CFGR , reg_val); + ret =adp8860_read (data->client,ADP8860_CFGR , ®_val); +if (!ret) { + reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); + reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; +adp8860_write (data->client,ADP8860_CFGR , reg_val); + }mutex_unlock (&data->lock); }drivers/video/backlight/adp8870_bl.c +6
-4@@ -807,10 +807,12 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev,/* Set user supplied ambient light zone */ mutex_lock (&data->lock); -adp8870_read (data->client,ADP8870_CFGR , ®_val); - reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); - reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; -adp8870_write (data->client,ADP8870_CFGR , reg_val); + ret =adp8870_read (data->client,ADP8870_CFGR , ®_val); +if (!ret) { + reg_val &= ~(CFGR_BLV_MASK <<CFGR_BLV_SHIFT ); + reg_val |= (val -1 ) <<CFGR_BLV_SHIFT ; +adp8870_write (data->client,ADP8870_CFGR , reg_val); + }mutex_unlock (&data->lock); }
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog