Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1515561 > unrolled thread

[PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string

Started byHeinrich Schuchardt <xypron.glpk@gmx.de>
First post2016-11-05 16:00 +0100
Last post2016-11-06 17:20 +0100
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string Heinrich Schuchardt <xypron.glpk@gmx.de> - 2016-11-05 16:00 +0100
    Re: [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string Guenter Roeck <linux@roeck-us.net> - 2016-11-05 16:30 +0100
      Re: [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string Heinrich Schuchardt <xypron.glpk@gmx.de> - 2016-11-05 19:30 +0100
      Re: [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string Wim Van Sebroeck <wim@iguana.be> - 2016-11-06 17:20 +0100

#1515561 — [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string

FromHeinrich Schuchardt <xypron.glpk@gmx.de>
Date2016-11-05 16:00 +0100
Subject[PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string
Message-ID<sAaBP-IS-1@gated-at.bofh.it>
fw_rev_major and fw_rev_minor are defined as int.
Use %d to print them.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 drivers/watchdog/pcwd_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/pcwd_pci.c b/drivers/watchdog/pcwd_pci.c
index c0d07ee..e1fbbf6 100644
--- a/drivers/watchdog/pcwd_pci.c
+++ b/drivers/watchdog/pcwd_pci.c
@@ -234,7 +234,7 @@ static void pcipcwd_show_card_info(void)
 	got_fw_rev = send_command(CMD_GET_FIRMWARE_VERSION, &fw_rev_major,
 								&fw_rev_minor);
 	if (got_fw_rev)
-		sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor);
+		sprintf(fw_ver_str, "%d.%02d", fw_rev_major, fw_rev_minor);
 	else
 		sprintf(fw_ver_str, "<card no answer>");
 
-- 
2.10.1

[toc] | [next] | [standalone]


#1515565

FromGuenter Roeck <linux@roeck-us.net>
Date2016-11-05 16:30 +0100
Message-ID<sAb4S-174-41@gated-at.bofh.it>
In reply to#1515561
On 11/05/2016 07:50 AM, Heinrich Schuchardt wrote:
> fw_rev_major and fw_rev_minor are defined as int.
> Use %d to print them.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  drivers/watchdog/pcwd_pci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/watchdog/pcwd_pci.c b/drivers/watchdog/pcwd_pci.c
> index c0d07ee..e1fbbf6 100644
> --- a/drivers/watchdog/pcwd_pci.c
> +++ b/drivers/watchdog/pcwd_pci.c
> @@ -234,7 +234,7 @@ static void pcipcwd_show_card_info(void)
>  	got_fw_rev = send_command(CMD_GET_FIRMWARE_VERSION, &fw_rev_major,
>  								&fw_rev_minor);
>  	if (got_fw_rev)
> -		sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor);
> +		sprintf(fw_ver_str, "%d.%02d", fw_rev_major, fw_rev_minor);
>  	else
>  		sprintf(fw_ver_str, "<card no answer>");
>
>
Hmm ... I don't think that a negative version number makes much sense.
Turns out inb() returns a char on some architectures, meaning it is signed,
meaning it _could_ return a negative number if the version number is 128
or above. I don't want to risk us reporting version number -128.-110 just
to make compilers happy.

Guenter

[toc] | [prev] | [next] | [standalone]


#1515602

FromHeinrich Schuchardt <xypron.glpk@gmx.de>
Date2016-11-05 19:30 +0100
Message-ID<sAdT4-2WL-9@gated-at.bofh.it>
In reply to#1515565
On 11/05/2016 04:29 PM, Guenter Roeck wrote:
> On 11/05/2016 07:50 AM, Heinrich Schuchardt wrote:
>> fw_rev_major and fw_rev_minor are defined as int.
>> Use %d to print them.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> ---
>>  drivers/watchdog/pcwd_pci.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/watchdog/pcwd_pci.c b/drivers/watchdog/pcwd_pci.c
>> index c0d07ee..e1fbbf6 100644
>> --- a/drivers/watchdog/pcwd_pci.c
>> +++ b/drivers/watchdog/pcwd_pci.c
>> @@ -234,7 +234,7 @@ static void pcipcwd_show_card_info(void)
>>      got_fw_rev = send_command(CMD_GET_FIRMWARE_VERSION, &fw_rev_major,
>>                                  &fw_rev_minor);
>>      if (got_fw_rev)
>> -        sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor);
>> +        sprintf(fw_ver_str, "%d.%02d", fw_rev_major, fw_rev_minor);
>>      else
>>          sprintf(fw_ver_str, "<card no answer>");
>>
>>
> Hmm ... I don't think that a negative version number makes much sense.
> Turns out inb() returns a char on some architectures, meaning it is signed,
> meaning it _could_ return a negative number if the version number is 128
> or above. I don't want to risk us reporting version number -128.-110 just
> to make compilers happy.

send_command uses inb_p to read single bytes.

The signature of inb_p is
u8 inb_p(unsigned long addr)

So fw_rev_major and fw_rev_minor should always be
in the range of 0..255.

Regards

Heinrich

[toc] | [prev] | [next] | [standalone]


#1515715

FromWim Van Sebroeck <wim@iguana.be>
Date2016-11-06 17:20 +0100
Message-ID<sAykN-7JC-1@gated-at.bofh.it>
In reply to#1515565
Hi All,

> On 11/05/2016 07:50 AM, Heinrich Schuchardt wrote:
> >fw_rev_major and fw_rev_minor are defined as int.
> >Use %d to print them.
> >
> >Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> >---
> > drivers/watchdog/pcwd_pci.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/drivers/watchdog/pcwd_pci.c b/drivers/watchdog/pcwd_pci.c
> >index c0d07ee..e1fbbf6 100644
> >--- a/drivers/watchdog/pcwd_pci.c
> >+++ b/drivers/watchdog/pcwd_pci.c
> >@@ -234,7 +234,7 @@ static void pcipcwd_show_card_info(void)
> > 	got_fw_rev = send_command(CMD_GET_FIRMWARE_VERSION, &fw_rev_major,
> > 								&fw_rev_minor);
> > 	if (got_fw_rev)
> >-		sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor);
> >+		sprintf(fw_ver_str, "%d.%02d", fw_rev_major, fw_rev_minor);
> > 	else
> > 		sprintf(fw_ver_str, "<card no answer>");
> >
> >
> Hmm ... I don't think that a negative version number makes much sense.
> Turns out inb() returns a char on some architectures, meaning it is signed,
> meaning it _could_ return a negative number if the version number is 128
> or above. I don't want to risk us reporting version number -128.-110 just
> to make compilers happy.

I couldn't have said this better myself :-) version info is indeed to be consider as an unsigned int.

Kind regards,
Wim.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web