Skip to content

Commit 55741c7

Browse files
Epicuriusgregkh
authored andcommitted
usb: xhci: correct debug message page size calculation
The ffs() function returns the index of the first set bit, starting from 1. If no bits are set, it returns zero. This behavior causes an off-by-one page size in the debug message, as the page size calculation [1] is zero-based, while ffs() is one-based. Fix this by subtracting one from the result of ffs(). Note that since variable 'val' is unsigned, subtracting one from zero will result in the maximum unsigned integer value. Consequently, the condition 'if (val < 16)' will still function correctly. [1], Page size: (2^(n+12)), where 'n' is the set page size bit. Fixes: 81720ec ("usb: host: xhci: use ffs() in xhci_mem_init()") Signed-off-by: Niklas Neronin <[email protected]> Signed-off-by: Mathias Nyman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fe1ccba commit 55741c7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/usb/host/xhci-mem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,10 +2391,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
23912391
page_size = readl(&xhci->op_regs->page_size);
23922392
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
23932393
"Supported page size register = 0x%x", page_size);
2394-
i = ffs(page_size);
2395-
if (i < 16)
2394+
val = ffs(page_size) - 1;
2395+
if (val < 16)
23962396
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2397-
"Supported page size of %iK", (1 << (i+12)) / 1024);
2397+
"Supported page size of %iK", (1 << (val + 12)) / 1024);
23982398
else
23992399
xhci_warn(xhci, "WARN: no supported page size\n");
24002400
/* Use 4K pages, since that's common and the minimum the HC supports */

0 commit comments

Comments
 (0)