Skip to content

Commit a44252d

Browse files
JustinStittjonmason
authored andcommitted
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: ClangBuiltLinux/linux#378 Signed-off-by: Justin Stitt <[email protected]> Acked-by: Serge Semin <[email protected]> Signed-off-by: Jon Mason <[email protected]>
1 parent 3d7cb6b commit a44252d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/ntb/hw/idt/ntb_hw_idt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,7 @@ static ssize_t idt_dbgfs_info_read(struct file *filp, char __user *ubuf,
24062406
"\t%hhu.\t", idx);
24072407
else
24082408
off += scnprintf(strbuf + off, size - off,
2409-
"\t%hhu-%hhu.\t", idx, idx + cnt - 1);
2409+
"\t%hhu-%d.\t", idx, idx + cnt - 1);
24102410

24112411
off += scnprintf(strbuf + off, size - off, "%s BAR%hhu, ",
24122412
idt_get_mw_name(data), ndev->mws[idx].bar);
@@ -2435,7 +2435,7 @@ static ssize_t idt_dbgfs_info_read(struct file *filp, char __user *ubuf,
24352435
"\t%hhu.\t", idx);
24362436
else
24372437
off += scnprintf(strbuf + off, size - off,
2438-
"\t%hhu-%hhu.\t", idx, idx + cnt - 1);
2438+
"\t%hhu-%d.\t", idx, idx + cnt - 1);
24392439

24402440
off += scnprintf(strbuf + off, size - off,
24412441
"%s BAR%hhu, ", idt_get_mw_name(data),
@@ -2480,7 +2480,7 @@ static ssize_t idt_dbgfs_info_read(struct file *filp, char __user *ubuf,
24802480
int src;
24812481
data = idt_ntb_msg_read(&ndev->ntb, &src, idx);
24822482
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",
24842484
idx, data, src, ndev->peers[src].port);
24852485
}
24862486
off += scnprintf(strbuf + off, size - off, "\n");

0 commit comments

Comments
 (0)