linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string
@ 2016-11-05 14:50 Heinrich Schuchardt
  2016-11-05 15:29 ` Guenter Roeck
  0 siblings, 1 reply; 4+ messages in thread
From: Heinrich Schuchardt @ 2016-11-05 14:50 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: Guenter Roeck, linux-watchdog, linux-kernel, Heinrich Schuchardt

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

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

* Re: [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string
  2016-11-05 14:50 [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string Heinrich Schuchardt
@ 2016-11-05 15:29 ` Guenter Roeck
  2016-11-05 18:19   ` Heinrich Schuchardt
  2016-11-06 16:12   ` Wim Van Sebroeck
  0 siblings, 2 replies; 4+ messages in thread
From: Guenter Roeck @ 2016-11-05 15:29 UTC (permalink / raw)
  To: Heinrich Schuchardt, Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel

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

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

* Re: [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string
  2016-11-05 15:29 ` Guenter Roeck
@ 2016-11-05 18:19   ` Heinrich Schuchardt
  2016-11-06 16:12   ` Wim Van Sebroeck
  1 sibling, 0 replies; 4+ messages in thread
From: Heinrich Schuchardt @ 2016-11-05 18:19 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel

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

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

* Re: [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string
  2016-11-05 15:29 ` Guenter Roeck
  2016-11-05 18:19   ` Heinrich Schuchardt
@ 2016-11-06 16:12   ` Wim Van Sebroeck
  1 sibling, 0 replies; 4+ messages in thread
From: Wim Van Sebroeck @ 2016-11-06 16:12 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Heinrich Schuchardt, linux-watchdog, linux-kernel

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.

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

end of thread, other threads:[~2016-11-06 16:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-05 14:50 [PATCH 1/1] watchdog: pcipcwd_show_card_info: wrong format string Heinrich Schuchardt
2016-11-05 15:29 ` Guenter Roeck
2016-11-05 18:19   ` Heinrich Schuchardt
2016-11-06 16:12   ` Wim Van Sebroeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).