]> git.baikalelectronics.ru Git - kernel.git/commit
qlogic: qed: fix clang -Wformat warnings
authorJustin Stitt <justinstitt@google.com>
Mon, 11 Jul 2022 23:24:04 +0000 (16:24 -0700)
committerJakub Kicinski <kuba@kernel.org>
Wed, 13 Jul 2022 03:36:41 +0000 (20:36 -0700)
commit0d7eb8fa1023b49d1e7cd7b28181e8fb673ae5ef
treefa1a029249fb4c404ece9472df1707cb935c3f4d
parent5add39136275addf57915a8508b3b4b91e65e2f4
qlogic: qed: fix clang -Wformat warnings

When building with Clang we encounter these warnings:
| drivers/net/ethernet/qlogic/qed/qed_dev.c:416:30: error: format
| specifies type 'char' but the argument has type 'u32' (aka 'unsigned
| int') [-Werror,-Wformat] i);
-
| drivers/net/ethernet/qlogic/qed/qed_dev.c:630:13: error: format
| specifies type 'char' but the argument has type 'int' [-Werror,-Wformat]
| p_llh_info->num_ppfid - 1);

For the first warning, `i` is a u32 which is much wider than the format
specifier `%hhd` describes. This results in a loss of bits after 2^7.

The second warning involves implicit integer promotion as the resulting
type of addition cannot be smaller than an int.

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."

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20220711232404.2189257-1-justinstitt@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/qlogic/qed/qed_dev.c