[RFC 08/21] xhci: use ffs() for page size's calculation in xhci_mem_init()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The first 16 bits of Page Size Register report the page size supported by xHC.
If bit i is set, then xHC supports a page size of 2^(i+12).
This patch replaces the code that does the lookup for the first set bit with
a call to ffs() because using ffs() the code can benefit from architecture
specific instructions that implement this computation more efficiently.

Signed-off-by: Xenia Ragiadakou <burzalodowa@xxxxxxxxx>
---
 drivers/usb/host/xhci-mem.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 37ae98f..e1c4b79 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -25,6 +25,7 @@
 #include <linux/slab.h>
 #include <linux/dmapool.h>
 #include <linux/dma-mapping.h>
+#include <linux/bitops.h>
 
 #include "xhci.h"
 #include "xhci-trace.h"
@@ -2237,12 +2238,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	page_size = xhci_readl(xhci, &xhci->op_regs->page_size);
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
 			"Supported page size register = 0x%x", page_size);
-	for (i = 0; i < 16; i++) {
-		if ((0x1 & page_size) != 0)
-			break;
-		page_size = page_size >> 1;
-	}
-	if (i < 16)
+	i = ffs(page_size & 0xffff) - 1;
+	if (i > -1)
 		xhci_dbg_trace(xhci, trace_xhci_dbg_init,
 			"Supported page size of %iK", (1 << (i+12)) / 1024);
 	else
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux