* xhci: Use ffs() to find page size in xhci_mem_init()
@ 2019-02-07 0:03 Andrey Smirnov
0 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2019-02-07 0:03 UTC (permalink / raw)
To: linux-usb; +Cc: Andrey Smirnov, Mathias Nyman, Greg Kroah-Hartman, linux-kernel
Get page size order using ffs() instead of open coding it with a loop.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/usb/host/xhci-mem.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 36a3eb8849f1..44b43c3d819f 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -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);
^ permalink raw reply related [flat|nested] 7+ messages in thread
* xhci: Use ffs() to find page size in xhci_mem_init()
@ 2019-02-07 9:04 Mathias Nyman
0 siblings, 0 replies; 7+ messages in thread
From: Mathias Nyman @ 2019-02-07 9:04 UTC (permalink / raw)
To: Andrey Smirnov, linux-usb; +Cc: Mathias Nyman, Greg Kroah-Hartman, linux-kernel
On 07.02.2019 02:03, Andrey Smirnov wrote:
> Get page size order using ffs() instead of open coding it with a loop.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: Mathias Nyman <mathias.nyman@intel.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: linux-usb@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
> drivers/usb/host/xhci-mem.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index 36a3eb8849f1..44b43c3d819f 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -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);
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* xhci: Use ffs() to find page size in xhci_mem_init()
@ 2019-02-07 9:06 Felipe Balbi
0 siblings, 0 replies; 7+ messages in thread
From: Felipe Balbi @ 2019-02-07 9:06 UTC (permalink / raw)
To: Mathias Nyman, Andrey Smirnov, linux-usb
Cc: Mathias Nyman, Greg Kroah-Hartman, linux-kernel
Hi,
Mathias Nyman <mathias.nyman@linux.intel.com> writes:
> On 07.02.2019 02:03, Andrey Smirnov wrote:
>> Get page size order using ffs() instead of open coding it with a loop.
>>
>> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
>> Cc: Mathias Nyman <mathias.nyman@intel.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: linux-usb@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> ---
>> drivers/usb/host/xhci-mem.c | 6 +-----
>> 1 file changed, 1 insertion(+), 5 deletions(-)
>>
>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
>> index 36a3eb8849f1..44b43c3d819f 100644
>> --- a/drivers/usb/host/xhci-mem.c
>> +++ b/drivers/usb/host/xhci-mem.c
>> @@ -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);
>
> 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
off-by-one, just use i = ffs() - 1. Or use __ffs().
^ permalink raw reply [flat|nested] 7+ messages in thread
* xhci: Use ffs() to find page size in xhci_mem_init()
@ 2019-02-07 10:46 Mathias Nyman
0 siblings, 0 replies; 7+ messages in thread
From: Mathias Nyman @ 2019-02-07 10:46 UTC (permalink / raw)
To: Felipe Balbi, Mathias Nyman, Andrey Smirnov, linux-usb
Cc: Greg Kroah-Hartman, linux-kernel
On 07.02.2019 11:06, Felipe Balbi wrote:
>
> Hi,
>
> Mathias Nyman <mathias.nyman@linux.intel.com> writes:
>> On 07.02.2019 02:03, Andrey Smirnov wrote:
>>> Get page size order using ffs() instead of open coding it with a loop.
>>>
>>> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
>>> Cc: Mathias Nyman <mathias.nyman@intel.com>
>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>> Cc: linux-usb@vger.kernel.org
>>> Cc: linux-kernel@vger.kernel.org
>>> ---
>>> drivers/usb/host/xhci-mem.c | 6 +-----
>>> 1 file changed, 1 insertion(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
>>> index 36a3eb8849f1..44b43c3d819f 100644
>>> --- a/drivers/usb/host/xhci-mem.c
>>> +++ b/drivers/usb/host/xhci-mem.c
>>> @@ -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);
>>
>> 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
>
> off-by-one, just use i = ffs() - 1. Or use __ffs().
>
and handle the page_size == 0 case.
-Mathias
^ permalink raw reply [flat|nested] 7+ messages in thread
* xhci: Use ffs() to find page size in xhci_mem_init()
@ 2019-02-07 10:58 Felipe Balbi
0 siblings, 0 replies; 7+ messages in thread
From: Felipe Balbi @ 2019-02-07 10:58 UTC (permalink / raw)
To: Mathias Nyman, Mathias Nyman, Andrey Smirnov, linux-usb
Cc: Greg Kroah-Hartman, linux-kernel
Hi,
Mathias Nyman <mathias.nyman@intel.com> writes:
>>>> Get page size order using ffs() instead of open coding it with a loop.
>>>>
>>>> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
>>>> Cc: Mathias Nyman <mathias.nyman@intel.com>
>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>>> Cc: linux-usb@vger.kernel.org
>>>> Cc: linux-kernel@vger.kernel.org
>>>> ---
>>>> drivers/usb/host/xhci-mem.c | 6 +-----
>>>> 1 file changed, 1 insertion(+), 5 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
>>>> index 36a3eb8849f1..44b43c3d819f 100644
>>>> --- a/drivers/usb/host/xhci-mem.c
>>>> +++ b/drivers/usb/host/xhci-mem.c
>>>> @@ -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);
>>>
>>> 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
>>
>> 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?
^ permalink raw reply [flat|nested] 7+ messages in thread
* xhci: Use ffs() to find page size in xhci_mem_init()
@ 2019-02-07 11:54 Mathias Nyman
0 siblings, 0 replies; 7+ messages in thread
From: Mathias Nyman @ 2019-02-07 11:54 UTC (permalink / raw)
To: Felipe Balbi, Mathias Nyman, Andrey Smirnov, linux-usb
Cc: Greg Kroah-Hartman, linux-kernel
On 07.02.2019 12:58, Felipe Balbi wrote:
>
> Hi,
>
> Mathias Nyman <mathias.nyman@intel.com> writes:
>>>>> Get page size order using ffs() instead of open coding it with a loop.
>>>>>
>>>>> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
>>>>> Cc: Mathias Nyman <mathias.nyman@intel.com>
>>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>>>> Cc: linux-usb@vger.kernel.org
>>>>> Cc: linux-kernel@vger.kernel.org
>>>>> ---
>>>>> drivers/usb/host/xhci-mem.c | 6 +-----
>>>>> 1 file changed, 1 insertion(+), 5 deletions(-)
>>>>>
>>>>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
>>>>> index 36a3eb8849f1..44b43c3d819f 100644
>>>>> --- a/drivers/usb/host/xhci-mem.c
>>>>> +++ b/drivers/usb/host/xhci-mem.c
>>>>> @@ -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);
>>>>
>>>> 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
>>>
>>> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* xhci: Use ffs() to find page size in xhci_mem_init()
@ 2019-02-07 21:06 Andrey Smirnov
0 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2019-02-07 21:06 UTC (permalink / raw)
To: Mathias Nyman; +Cc: linux-usb, Mathias Nyman, Greg Kroah-Hartman, linux-kernel
On Thu, Feb 7, 2019 at 1:00 AM Mathias Nyman
<mathias.nyman@linux.intel.com> wrote:
>
> On 07.02.2019 02:03, Andrey Smirnov wrote:
> > Get page size order using ffs() instead of open coding it with a loop.
> >
> > Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> > Cc: Mathias Nyman <mathias.nyman@intel.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: linux-usb@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > ---
> > drivers/usb/host/xhci-mem.c | 6 +-----
> > 1 file changed, 1 insertion(+), 5 deletions(-)
> >
> > diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> > index 36a3eb8849f1..44b43c3d819f 100644
> > --- a/drivers/usb/host/xhci-mem.c
> > +++ b/drivers/usb/host/xhci-mem.c
> > @@ -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);
>
> 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
>
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-02-07 21:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-07 10:58 xhci: Use ffs() to find page size in xhci_mem_init() Felipe Balbi
-- strict thread matches above, loose matches on Subject: below --
2019-02-07 21:06 Andrey Smirnov
2019-02-07 11:54 Mathias Nyman
2019-02-07 10:46 Mathias Nyman
2019-02-07 9:06 Felipe Balbi
2019-02-07 9:04 Mathias Nyman
2019-02-07 0:03 Andrey Smirnov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).