mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 3/3] auxdisplay: img-ascii-lcd: Silence 2 uninitialized warnings
@ 2018-02-19 16:09 Miguel Ojeda
  2018-02-19 18:40 ` Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: Miguel Ojeda @ 2018-02-19 16:09 UTC (permalink / raw)
  To: linux-kernel, paul.burton, geert

The warnings are:

  drivers/auxdisplay/img-ascii-lcd.c: warning: 'err' may be used
  uninitialized in this function [-Wuninitialized]

At lines 109 and 207. Reported by Geert using the build service
several times, e.g.:

  https://lkml.org/lkml/2018/2/19/303

They are two false positives, since num_chars > 0 in the three present
configurations (boston, malta, sead3). Initializing to an error state by
default silences the warning and makes the code print an error in case a
num_chars == 0 happens in the future (unlikely, since it does not make
sense currently).

The warnings seem to disappear starting with gcc >= 4.9

Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Paul Burton <paul.burton@mips.com>
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
---
I will queue it up for 4.17.

drivers/auxdisplay/img-ascii-lcd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/auxdisplay/img-ascii-lcd.c b/drivers/auxdisplay/img-ascii-lcd.c
index d8133024fd5d..bd5ebb5c516c 100644
--- a/drivers/auxdisplay/img-ascii-lcd.c
+++ b/drivers/auxdisplay/img-ascii-lcd.c
@@ -97,7 +97,7 @@ static struct img_ascii_lcd_config boston_config = {
 static void malta_update(struct img_ascii_lcd_ctx *ctx)
 {
 	unsigned int i;
-	int err;
+	int err = 1;
 
 	for (i = 0; i < ctx->cfg->num_chars; i++) {
 		err = regmap_write(ctx->regmap,
@@ -180,7 +180,7 @@ static int sead3_wait_lcd_idle(struct img_ascii_lcd_ctx *ctx)
 static void sead3_update(struct img_ascii_lcd_ctx *ctx)
 {
 	unsigned int i;
-	int err;
+	int err = 1;
 
 	for (i = 0; i < ctx->cfg->num_chars; i++) {
 		err = sead3_wait_lcd_idle(ctx);
-- 
2.14.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 3/3] auxdisplay: img-ascii-lcd: Silence 2 uninitialized warnings
  2018-02-19 16:09 [PATCH 3/3] auxdisplay: img-ascii-lcd: Silence 2 uninitialized warnings Miguel Ojeda
@ 2018-02-19 18:40 ` Geert Uytterhoeven
  2018-02-23  9:39   ` Miguel Ojeda
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2018-02-19 18:40 UTC (permalink / raw)
  To: Miguel Ojeda; +Cc: Linux Kernel Mailing List, Paul Burton

Hi Miguel,

On Mon, Feb 19, 2018 at 5:09 PM, Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
> The warnings are:
>
>   drivers/auxdisplay/img-ascii-lcd.c: warning: 'err' may be used
>   uninitialized in this function [-Wuninitialized]
>
> At lines 109 and 207. Reported by Geert using the build service
> several times, e.g.:
>
>   https://lkml.org/lkml/2018/2/19/303
>
> They are two false positives, since num_chars > 0 in the three present
> configurations (boston, malta, sead3). Initializing to an error state by
> default silences the warning and makes the code print an error in case a
> num_chars == 0 happens in the future (unlikely, since it does not make
> sense currently).
>
> The warnings seem to disappear starting with gcc >= 4.9
>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Paul Burton <paul.burton@mips.com>
> Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>

Thanks for your patch!

I would initialize err to zero, though, as there is no real error condition if
called with num_char == 0.

> ---
> I will queue it up for 4.17.
>
> drivers/auxdisplay/img-ascii-lcd.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/auxdisplay/img-ascii-lcd.c b/drivers/auxdisplay/img-ascii-lcd.c
> index d8133024fd5d..bd5ebb5c516c 100644
> --- a/drivers/auxdisplay/img-ascii-lcd.c
> +++ b/drivers/auxdisplay/img-ascii-lcd.c
> @@ -97,7 +97,7 @@ static struct img_ascii_lcd_config boston_config = {
>  static void malta_update(struct img_ascii_lcd_ctx *ctx)
>  {
>         unsigned int i;
> -       int err;
> +       int err = 1;
>
>         for (i = 0; i < ctx->cfg->num_chars; i++) {
>                 err = regmap_write(ctx->regmap,
> @@ -180,7 +180,7 @@ static int sead3_wait_lcd_idle(struct img_ascii_lcd_ctx *ctx)
>  static void sead3_update(struct img_ascii_lcd_ctx *ctx)
>  {
>         unsigned int i;
> -       int err;
> +       int err = 1;
>
>         for (i = 0; i < ctx->cfg->num_chars; i++) {
>                 err = sead3_wait_lcd_idle(ctx);

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 3/3] auxdisplay: img-ascii-lcd: Silence 2 uninitialized warnings
  2018-02-19 18:40 ` Geert Uytterhoeven
@ 2018-02-23  9:39   ` Miguel Ojeda
  0 siblings, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2018-02-23  9:39 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Linux Kernel Mailing List, Paul Burton

Hi Geert,

On Mon, Feb 19, 2018 at 7:40 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> Hi Miguel,
>
> On Mon, Feb 19, 2018 at 5:09 PM, Miguel Ojeda
> <miguel.ojeda.sandonis@gmail.com> wrote:
>> The warnings are:
>>
>>   drivers/auxdisplay/img-ascii-lcd.c: warning: 'err' may be used
>>   uninitialized in this function [-Wuninitialized]
>>
>> At lines 109 and 207. Reported by Geert using the build service
>> several times, e.g.:
>>
>>   https://lkml.org/lkml/2018/2/19/303
>>
>> They are two false positives, since num_chars > 0 in the three present
>> configurations (boston, malta, sead3). Initializing to an error state by
>> default silences the warning and makes the code print an error in case a
>> num_chars == 0 happens in the future (unlikely, since it does not make
>> sense currently).
>>
>> The warnings seem to disappear starting with gcc >= 4.9
>>
>> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
>> Cc: Paul Burton <paul.burton@mips.com>
>> Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
>
> Thanks for your patch!
>
> I would initialize err to zero, though, as there is no real error condition if
> called with num_char == 0.

True, it also makes sense that way. Both are fine with me. I was
thinking more in the lines of "update() called for no reason (no
chars) is an error".

Since it will never happen anyway and = 0 is simpler to explain
(nothing to explain in the commit), I will change it for the queue.
Should I add your Ack?

Thanks for taking a look!
Miguel

>
>> ---
>> I will queue it up for 4.17.
>>
>> drivers/auxdisplay/img-ascii-lcd.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/auxdisplay/img-ascii-lcd.c b/drivers/auxdisplay/img-ascii-lcd.c
>> index d8133024fd5d..bd5ebb5c516c 100644
>> --- a/drivers/auxdisplay/img-ascii-lcd.c
>> +++ b/drivers/auxdisplay/img-ascii-lcd.c
>> @@ -97,7 +97,7 @@ static struct img_ascii_lcd_config boston_config = {
>>  static void malta_update(struct img_ascii_lcd_ctx *ctx)
>>  {
>>         unsigned int i;
>> -       int err;
>> +       int err = 1;
>>
>>         for (i = 0; i < ctx->cfg->num_chars; i++) {
>>                 err = regmap_write(ctx->regmap,
>> @@ -180,7 +180,7 @@ static int sead3_wait_lcd_idle(struct img_ascii_lcd_ctx *ctx)
>>  static void sead3_update(struct img_ascii_lcd_ctx *ctx)
>>  {
>>         unsigned int i;
>> -       int err;
>> +       int err = 1;
>>
>>         for (i = 0; i < ctx->cfg->num_chars; i++) {
>>                 err = sead3_wait_lcd_idle(ctx);
>
> Gr{oetje,eeting}s,
>
>                         Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-23  9:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-19 16:09 [PATCH 3/3] auxdisplay: img-ascii-lcd: Silence 2 uninitialized warnings Miguel Ojeda
2018-02-19 18:40 ` Geert Uytterhoeven
2018-02-23  9:39   ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®