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

Configure Feed

Select the types of activity you want to include in your feed.

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: 81720ec5320c ("usb: host: xhci: use ffs() in xhci_mem_init()")
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20250306144954.3507700-9-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Niklas Neronin and committed by
Greg Kroah-Hartman
55741c72 fe1ccba5

+3 -3
+3 -3
drivers/usb/host/xhci-mem.c
··· 2391 2391 page_size = readl(&xhci->op_regs->page_size); 2392 2392 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2393 2393 "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) 2396 2396 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); 2398 2398 else 2399 2399 xhci_warn(xhci, "WARN: no supported page size\n"); 2400 2400 /* Use 4K pages, since that's common and the minimum the HC supports */