lkml.org 
[lkml]   [2022]   [Jul]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: wifi: mt7601u: fix clang -Wformat warning
From
Date
Justin Stitt <justinstitt@google.com> wrote:

> When building with Clang we encounter this warning:
> | drivers/net/wireless/mediatek/mt7601u/debugfs.c:92:6: error: format
> | specifies type 'unsigned char' but the argument has type 'int'
> | [-Werror,-Wformat] dev->ee->reg.start + dev->ee->reg.num - 1);
>
> The format specifier used is `%hhu` which describes a u8. Both
> `dev->ee->reg.start` and `.num` are u8 as well. However, the expression
> as a whole is promoted to an int as you cannot get smaller-than-int from
> addition. Therefore, to fix the warning, use the promoted-to-type's
> format specifier -- in this case `%d`.
>
> example:
> ```
> uint8_t a = 4, b = 7;
> int size = sizeof(a + b - 1);
> printf("%d\n", size);
> // output: 4
> ```
>
> See more:
> (https://wiki.sei.cmu.edu/confluence/display/c/INT02-C.+Understand+integer+conversion+rules)
> "Integer types smaller than int are promoted when an operation is
> performed on them. If all values of the original type can be represented
> as an int, the value of the smaller type is converted to an int;
> otherwise, it is converted to an unsigned int."
>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> Acked-by: Jakub Kicinski <kubakici@wp.pl>

Patch applied to wireless-next.git, thanks.

68204a696505 wifi: mt7601u: fix clang -Wformat warning

--
https://patchwork.kernel.org/project/linux-wireless/patch/20220711212932.1501592-1-justinstitt@google.com/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

\
 
 \ /
  Last update: 2022-07-18 13:55    [W:0.092 / U:0.376 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site