Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Justin Stitt and committed by
Jakub Kicinski
b6afeb87 1aea9d87

+2 -2
+2 -2
drivers/net/ethernet/qlogic/qed/qed_dev.c
··· 412 412 continue; 413 413 414 414 p_llh_info->ppfid_array[p_llh_info->num_ppfid] = i; 415 - DP_VERBOSE(cdev, QED_MSG_SP, "ppfid_array[%d] = %hhd\n", 415 + DP_VERBOSE(cdev, QED_MSG_SP, "ppfid_array[%d] = %u\n", 416 416 p_llh_info->num_ppfid, i); 417 417 p_llh_info->num_ppfid++; 418 418 } ··· 626 626 627 627 if (ppfid >= p_llh_info->num_ppfid) { 628 628 DP_NOTICE(cdev, 629 - "ppfid %d is not valid, available indices are 0..%hhd\n", 629 + "ppfid %d is not valid, available indices are 0..%d\n", 630 630 ppfid, p_llh_info->num_ppfid - 1); 631 631 *p_abs_ppfid = 0; 632 632 return -EINVAL;