lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87k1iblval.fsf@linux.intel.com>
Date:   Thu, 07 Feb 2019 12:58:26 +0200
From:   Felipe Balbi <felipe.balbi@...ux.intel.com>
To:     Mathias Nyman <mathias.nyman@...el.com>,
        Mathias Nyman <mathias.nyman@...ux.intel.com>,
        Andrey Smirnov <andrew.smirnov@...il.com>,
        linux-usb@...r.kernel.org
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] xhci: Use ffs() to find page size in xhci_mem_init()


Hi,

Mathias Nyman <mathias.nyman@...el.com> writes:
>>>> Get page size order using ffs() instead of open coding it with a loop.
>>>>
>>>> Signed-off-by: Andrey Smirnov <andrew.smirnov@...il.com>
>>>> Cc: Mathias Nyman <mathias.nyman@...el.com>
>>>> Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
>>>> Cc: linux-usb@...r.kernel.org
>>>> Cc: linux-kernel@...r.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?

-- 
balbi

Download attachment "signature.asc" of type "application/pgp-signature" (833 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ