From: Michael Hennerich <michael.hennerich@analog.com>
To: linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] backlight: adp88x0: fix uninitialized variable use
Date: Mon, 23 Nov 2015 13:53:11 +0000 [thread overview]
Message-ID: <56531A47.5000508@analog.com> (raw)
In-Reply-To: <3850346.cL1ocQLBvP@wuerfel>
On 11/23/2015 02:44 PM, Arnd Bergmann wrote:
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
>
> diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c
> index 98ffe71e8af2..f0d4c0324580 100644
> --- a/drivers/video/backlight/adp8860_bl.c
> +++ b/drivers/video/backlight/adp8860_bl.c
> @@ -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);
> }
>
> diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c
> index 9d738352d7d4..21acac90fd77 100644
> --- a/drivers/video/backlight/adp8870_bl.c
> +++ b/drivers/video/backlight/adp8870_bl.c
> @@ -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);
> }
>
>
--
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
WARNING: multiple messages have this Message-ID (diff)
From: michael.hennerich@analog.com (Michael Hennerich)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] backlight: adp88x0: fix uninitialized variable use
Date: Mon, 23 Nov 2015 14:53:11 +0100 [thread overview]
Message-ID: <56531A47.5000508@analog.com> (raw)
In-Reply-To: <3850346.cL1ocQLBvP@wuerfel>
On 11/23/2015 02:44 PM, Arnd Bergmann wrote:
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
>
> diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c
> index 98ffe71e8af2..f0d4c0324580 100644
> --- a/drivers/video/backlight/adp8860_bl.c
> +++ b/drivers/video/backlight/adp8860_bl.c
> @@ -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);
> }
>
> diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c
> index 9d738352d7d4..21acac90fd77 100644
> --- a/drivers/video/backlight/adp8870_bl.c
> +++ b/drivers/video/backlight/adp8870_bl.c
> @@ -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);
> }
>
>
--
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
WARNING: multiple messages have this Message-ID (diff)
From: Michael Hennerich <michael.hennerich@analog.com>
To: Arnd Bergmann <arnd@arndb.de>, Jingoo Han <jingoohan1@gmail.com>,
"Lee Jones" <lee.jones@linaro.org>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>,
Tomi Valkeinen <tomi.valkeinen@ti.com>,
<linux-fbdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] backlight: adp88x0: fix uninitialized variable use
Date: Mon, 23 Nov 2015 14:53:11 +0100 [thread overview]
Message-ID: <56531A47.5000508@analog.com> (raw)
In-Reply-To: <3850346.cL1ocQLBvP@wuerfel>
On 11/23/2015 02:44 PM, Arnd Bergmann wrote:
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
>
> diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c
> index 98ffe71e8af2..f0d4c0324580 100644
> --- a/drivers/video/backlight/adp8860_bl.c
> +++ b/drivers/video/backlight/adp8860_bl.c
> @@ -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);
> }
>
> diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c
> index 9d738352d7d4..21acac90fd77 100644
> --- a/drivers/video/backlight/adp8870_bl.c
> +++ b/drivers/video/backlight/adp8870_bl.c
> @@ -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);
> }
>
>
--
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
next prev parent reply other threads:[~2015-11-23 13:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-23 13:44 [PATCH] backlight: adp88x0: fix uninitialized variable use Arnd Bergmann
2015-11-23 13:44 ` Arnd Bergmann
2015-11-23 13:44 ` Arnd Bergmann
2015-11-23 13:53 ` Michael Hennerich [this message]
2015-11-23 13:53 ` Michael Hennerich
2015-11-23 13:53 ` Michael Hennerich
2015-11-23 14:39 ` Lee Jones
2015-11-23 14:39 ` Lee Jones
2015-11-23 14:39 ` Lee Jones
2015-11-23 16:22 ` Lee Jones
2015-11-23 16:22 ` Lee Jones
2015-11-23 16:22 ` Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56531A47.5000508@analog.com \
--to=michael.hennerich@analog.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.