xhci: Use ffs() to find page size in xhci_mem_init()
Subsystems (2)
PATCH 1/1 xhci: Use ffs() to find page size in xhci_mem_init()
Get page size order using ffs() instead of open coding it with a loop.
--- drivers/usb/host/xhci-mem.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/usb/host/xhci-mem.c +1 -5
@@ -2362,11 +2362,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) page_size =readl (&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 ; - } + i =ffs (page_size);if (i <16 )xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Supported page size of %iK" , (1 << (i+12 )) /1024 );
Quoted 18 lines · Andrey Smirnov
Get page size order using
ffs()instead of open coding it with a loop.Signed-off-by Andrey Smirnov <[email protected]>Cc Mathias Nyman <[email protected]>Cc Greg Kroah-Hartman <[email protected]>--- drivers/usb/host/xhci-mem.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/usb/host/xhci-mem.c +0
-0@@ -2362,11 +2362,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) page_size =readl (&xhci->op_regs->page_size); xhci_dbg_trace(xhci, trace_xhci_dbg_init,
drivers/usb/host/xhci-mem.c int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) · line 2368
Quoted 10 lines
drivers/usb/host/xhci-mem.c +1
-5"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 ; - } + i =ffs (page_size);if (i <16 )xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Supported page size of %iK" , (1 << (i+12 )) /1024 );
Hi
using ffs() is a welcome change, but it will give different a result than the loop.
*old loop
valid page_size value if i < 16*ffs()
valid page_size value if i >= 1 and i < 17
-Mathias
Hi,
Quoted 32 lines · Mathias Nyman
Quoted 18 lines · Andrey Smirnov
Get page size order using
ffs()instead of open coding it with a loop.Signed-off-by Andrey Smirnov <[email protected]>Cc Mathias Nyman <[email protected]>Cc Greg Kroah-Hartman <[email protected]>--- drivers/usb/host/xhci-mem.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/usb/host/xhci-mem.c +0
-0@@ -2362,11 +2362,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) page_size =readl (&xhci->op_regs->page_size); xhci_dbg_trace(xhci, trace_xhci_dbg_init,drivers/usb/host/xhci-mem.c int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) · line 2368
Quoted 10 lines
drivers/usb/host/xhci-mem.c +1
-5"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 ; - } + i =ffs (page_size);if (i <16 )xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Supported page size of %iK" , (1 << (i+12 )) /1024 );Hi
Quoted 6 lines
using
ffs()is a welcome change, but it will give different a result than the loop.*old loop
validpage_sizevalue if i < 16*ffs()
validpage_sizevalue if i >= 1 and i < 17
off-by-one, just use i = ffs() - 1. Or use __ffs().
Mathias Nyman
maintainerQuoted 36 lines · Felipe Balbi
Hi,
Quoted 32 lines · Mathias Nyman
Quoted 18 lines · Andrey Smirnov
Get page size order using
ffs()instead of open coding it with a loop.Signed-off-by Andrey Smirnov <[email protected]>Cc Mathias Nyman <[email protected]>Cc Greg Kroah-Hartman <[email protected]>--- drivers/usb/host/xhci-mem.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/usb/host/xhci-mem.c +0
-0@@ -2362,11 +2362,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) page_size =readl (&xhci->op_regs->page_size); xhci_dbg_trace(xhci, trace_xhci_dbg_init,drivers/usb/host/xhci-mem.c int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) · line 2368
Quoted 10 lines
drivers/usb/host/xhci-mem.c +1
-5"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 ; - } + i =ffs (page_size);if (i <16 )xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Supported page size of %iK" , (1 << (i+12 )) /1024 );Hi
Quoted 9 lines
Quoted 6 lines
using
ffs()is a welcome change, but it will give different a result than the loop.*old loop
validpage_sizevalue if i < 16*ffs()
validpage_sizevalue if i >= 1 and i < 17off-by-one, just use i =
ffs()- 1. Or use__ffs().
and handle the page_size == 0 case.
-Mathias
Hi,
Quoted 33 lines · Mathias Nyman
Quoted 33 lines
Quoted 33 lines
Quoted 18 lines
Get page size order using
ffs()instead of open coding it with a loop.Signed-off-by Andrey Smirnov <[email protected]>Cc Mathias Nyman <[email protected]>Cc Greg Kroah-Hartman <[email protected]>--- drivers/usb/host/xhci-mem.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/usb/host/xhci-mem.c +0
-0@@ -2362,11 +2362,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) page_size =readl (&xhci->op_regs->page_size); xhci_dbg_trace(xhci, trace_xhci_dbg_init,drivers/usb/host/xhci-mem.c int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) · line 2368
Quoted 10 lines
drivers/usb/host/xhci-mem.c +1
-5"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 ; - } + i =ffs (page_size);if (i <16 )xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Supported page size of %iK" , (1 << (i+12 )) /1024 );Hi
using
ffs()is a welcome change, but it will give different a result than the loop.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
*old loop
validpage_sizevalue if i < 16*ffs()
validpage_sizevalue if i >= 1 and i < 17off-by-one, just use i =
ffs()- 1. Or use__ffs().and handle the
page_size== 0 case.
Can it be zero in real life, or are you protecting against academic possibility that's never going to happen in HW?
Quoted 42 lines · Felipe Balbi
Hi,
Quoted 38 lines · Mathias Nyman
Quoted 38 lines
Quoted 37 lines
Quoted 18 lines
Get page size order using
ffs()instead of open coding it with a loop.Signed-off-by Andrey Smirnov <[email protected]>Cc Mathias Nyman <[email protected]>Cc Greg Kroah-Hartman <[email protected]>--- drivers/usb/host/xhci-mem.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/usb/host/xhci-mem.c +0
-0@@ -2362,11 +2362,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) page_size =readl (&xhci->op_regs->page_size); xhci_dbg_trace(xhci, trace_xhci_dbg_init,drivers/usb/host/xhci-mem.c int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) · line 2368
Quoted 10 lines
drivers/usb/host/xhci-mem.c +1
-5"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 ; - } + i =ffs (page_size);if (i <16 )xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Supported page size of %iK" , (1 << (i+12 )) /1024 );Hi
using
ffs()is a welcome change, but it will give different a result than the loop.*old loop
validpage_sizevalue if i < 16*ffs()
validpage_sizevalue if i >= 1 and i < 17
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
off-by-one, just use i =
ffs()- 1. Or use__ffs().and handle the
page_size== 0 case.Can it be zero in real life, or are you protecting against academic possibility that's never going to happen in HW?
whole page_size check is not really doing much, just printing out different debug messages.
-Mathias
Quoted 33 lines · Mathias Nyman
Quoted 18 lines · Andrey Smirnov
Get page size order using
ffs()instead of open coding it with a loop.Signed-off-by Andrey Smirnov <[email protected]>Cc Mathias Nyman <[email protected]>Cc Greg Kroah-Hartman <[email protected]>--- drivers/usb/host/xhci-mem.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)drivers/usb/host/xhci-mem.c +0
-0@@ -2362,11 +2362,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) page_size =readl (&xhci->op_regs->page_size); xhci_dbg_trace(xhci, trace_xhci_dbg_init,drivers/usb/host/xhci-mem.c int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) · line 2368
Quoted 10 lines
drivers/usb/host/xhci-mem.c +1
-5"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 ; - } + i =ffs (page_size);if (i <16 )xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Supported page size of %iK" , (1 << (i+12 )) /1024 );Hi
Quoted 7 lines
using
ffs()is a welcome change, but it will give different a result than the loop.*old loop
validpage_sizevalue if i < 16*ffs()
validpage_sizevalue if i >= 1 and i < 17
My bad, sorry about that, was using __fls() in the version I tested, but then switched it to ffs() at the last minute and forgot to double check. Will update in v2.
Thanks,
Andrey Smirnov