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

ntb: idt: fix clang -Wformat warnings

When building with Clang we encounter these warnings:
| drivers/ntb/hw/idt/ntb_hw_idt.c:2409:28: error: format specifies type
| 'unsigned char' but the argument has type 'int' [-Werror,-Wformat]
| "\t%hhu-%hhu.\t", idx + cnt - 1);
-
| drivers/ntb/hw/idt/ntb_hw_idt.c:2438:29: error: format specifies type
| 'unsigned char' but the argument has type 'int' [-Werror,-Wformat]
| "\t%hhu-%hhu.\t", idx + cnt - 1);
-
| drivers/ntb/hw/idt/ntb_hw_idt.c:2484:15: error: format specifies type
| 'unsigned char' but the argument has type 'int' [-Werror,-Wformat], src);

For the first two warnings the format specifier used is `%hhu` which
describes a u8. Both `idx` and `cnt` 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
```

For the last warning, src is of type `int` while the format specifier
describes a u8. The fix here is just to use the proper specifier `%d`.

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>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Signed-off-by: Jon Mason <jdmason@kudzu.us>

authored by

Justin Stitt and committed by
Jon Mason
a44252d5 3d7cb6b0

+3 -3
+3 -3
drivers/ntb/hw/idt/ntb_hw_idt.c
··· 2406 2406 "\t%hhu.\t", idx); 2407 2407 else 2408 2408 off += scnprintf(strbuf + off, size - off, 2409 - "\t%hhu-%hhu.\t", idx, idx + cnt - 1); 2409 + "\t%hhu-%d.\t", idx, idx + cnt - 1); 2410 2410 2411 2411 off += scnprintf(strbuf + off, size - off, "%s BAR%hhu, ", 2412 2412 idt_get_mw_name(data), ndev->mws[idx].bar); ··· 2435 2435 "\t%hhu.\t", idx); 2436 2436 else 2437 2437 off += scnprintf(strbuf + off, size - off, 2438 - "\t%hhu-%hhu.\t", idx, idx + cnt - 1); 2438 + "\t%hhu-%d.\t", idx, idx + cnt - 1); 2439 2439 2440 2440 off += scnprintf(strbuf + off, size - off, 2441 2441 "%s BAR%hhu, ", idt_get_mw_name(data), ··· 2480 2480 int src; 2481 2481 data = idt_ntb_msg_read(&ndev->ntb, &src, idx); 2482 2482 off += scnprintf(strbuf + off, size - off, 2483 - "\t%hhu. 0x%08x from peer %hhu (Port %hhu)\n", 2483 + "\t%hhu. 0x%08x from peer %d (Port %hhu)\n", 2484 2484 idx, data, src, ndev->peers[src].port); 2485 2485 } 2486 2486 off += scnprintf(strbuf + off, size - off, "\n");