linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int
@ 2020-05-15 16:54 Colin King
  2020-05-15 17:21 ` Alan Stern
  0 siblings, 1 reply; 8+ messages in thread
From: Colin King @ 2020-05-15 16:54 UTC (permalink / raw)
  To: Alan Stern, Greg Kroah-Hartman, Zhang Shengju, Tang Bin, linux-usb
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The comparison of hcd->irq to less than zero for an error check will
never be true because hcd->irq is an unsigned int.  Fix this by
assigning the int retval to the return of platform_get_irq and checking
this for the -ve error condition and assigning hcd->irq to retval.

Addresses-Coverity: ("Unsigned compared against 0")
Fixes: c856b4b0fdb5 ("USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe()")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/usb/host/ehci-mv.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index 0d61f43c29dc..cffdc8d01b2a 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -166,11 +166,10 @@ static int mv_ehci_probe(struct platform_device *pdev)
 	hcd->rsrc_len = resource_size(r);
 	hcd->regs = ehci_mv->op_regs;
 
-	hcd->irq = platform_get_irq(pdev, 0);
-	if (hcd->irq < 0) {
-		retval = hcd->irq;
+	retval = platform_get_irq(pdev, 0);
+	if (retval < 0)
 		goto err_disable_clk;
-	}
+	hcd->irq = retval;
 
 	ehci = hcd_to_ehci(hcd);
 	ehci->caps = (struct ehci_caps __iomem *) ehci_mv->cap_regs;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int
  2020-05-15 16:54 [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int Colin King
@ 2020-05-15 17:21 ` Alan Stern
  2020-05-15 17:26   ` Colin Ian King
                     ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Alan Stern @ 2020-05-15 17:21 UTC (permalink / raw)
  To: Colin King
  Cc: Greg Kroah-Hartman, Zhang Shengju, Tang Bin, linux-usb,
	kernel-janitors, linux-kernel

On Fri, May 15, 2020 at 05:54:53PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The comparison of hcd->irq to less than zero for an error check will
> never be true because hcd->irq is an unsigned int.  Fix this by
> assigning the int retval to the return of platform_get_irq and checking
> this for the -ve error condition and assigning hcd->irq to retval.
> 
> Addresses-Coverity: ("Unsigned compared against 0")
> Fixes: c856b4b0fdb5 ("USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe()")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---

Thanks to Coverity for spotting this.  Any reason why it didn't spot 
exactly the same mistake in the ohci-da8xx.c driver?

Also, why wasn't the patch CC'ed for the stable series?

Alan Stern

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int
  2020-05-15 17:21 ` Alan Stern
@ 2020-05-15 17:26   ` Colin Ian King
  2020-05-15 18:43     ` Alan Stern
  2020-05-15 23:23   ` [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparisonof " Tang Bin
  2020-05-16  6:30   ` [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of " Greg Kroah-Hartman
  2 siblings, 1 reply; 8+ messages in thread
From: Colin Ian King @ 2020-05-15 17:26 UTC (permalink / raw)
  To: Alan Stern
  Cc: Greg Kroah-Hartman, Zhang Shengju, Tang Bin, linux-usb,
	kernel-janitors, linux-kernel

On 15/05/2020 18:21, Alan Stern wrote:
> On Fri, May 15, 2020 at 05:54:53PM +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> The comparison of hcd->irq to less than zero for an error check will
>> never be true because hcd->irq is an unsigned int.  Fix this by
>> assigning the int retval to the return of platform_get_irq and checking
>> this for the -ve error condition and assigning hcd->irq to retval.
>>
>> Addresses-Coverity: ("Unsigned compared against 0")
>> Fixes: c856b4b0fdb5 ("USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe()")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
> 
> Thanks to Coverity for spotting this.  Any reason why it didn't spot 
> exactly the same mistake in the ohci-da8xx.c driver?

No idea, it is curious that it can spot one error but miss another.
Sometimes I see these issues on the next scan, so it maybe the database
diff'ing is awry.

> 
> Also, why wasn't the patch CC'ed for the stable series?

My bad on that. Human error

> 
> Alan Stern
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int
  2020-05-15 17:26   ` Colin Ian King
@ 2020-05-15 18:43     ` Alan Stern
  0 siblings, 0 replies; 8+ messages in thread
From: Alan Stern @ 2020-05-15 18:43 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Greg Kroah-Hartman, Zhang Shengju, Tang Bin, linux-usb,
	kernel-janitors, linux-kernel

On Fri, May 15, 2020 at 06:26:04PM +0100, Colin Ian King wrote:
> On 15/05/2020 18:21, Alan Stern wrote:
> > On Fri, May 15, 2020 at 05:54:53PM +0100, Colin King wrote:
> >> From: Colin Ian King <colin.king@canonical.com>
> >>
> >> The comparison of hcd->irq to less than zero for an error check will
> >> never be true because hcd->irq is an unsigned int.  Fix this by
> >> assigning the int retval to the return of platform_get_irq and checking
> >> this for the -ve error condition and assigning hcd->irq to retval.
> >>
> >> Addresses-Coverity: ("Unsigned compared against 0")
> >> Fixes: c856b4b0fdb5 ("USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe()")
> >> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> >> ---
> > 
> > Thanks to Coverity for spotting this.  Any reason why it didn't spot 
> > exactly the same mistake in the ohci-da8xx.c driver?
> 
> No idea, it is curious that it can spot one error but miss another.
> Sometimes I see these issues on the next scan, so it maybe the database
> diff'ing is awry.
> 
> > 
> > Also, why wasn't the patch CC'ed for the stable series?
> 
> My bad on that. Human error

Actually the question itself was my mistake.  I didn't notice that your 
patch was a fix to something that was just merged and hadn't been CC'ed 
to stable.

Alan Stern

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparisonof an unsigned int
  2020-05-15 17:21 ` Alan Stern
  2020-05-15 17:26   ` Colin Ian King
@ 2020-05-15 23:23   ` Tang Bin
  2020-05-16  1:17     ` Alan Stern
  2020-05-16  6:30   ` [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of " Greg Kroah-Hartman
  2 siblings, 1 reply; 8+ messages in thread
From: Tang Bin @ 2020-05-15 23:23 UTC (permalink / raw)
  To: Alan Stern, Colin King
  Cc: Greg Kroah-Hartman, Zhang Shengju, linux-usb, kernel-janitors,
	linux-kernel

Hi Alan & Colin:

On 2020/5/16 1:21, Alan Stern wrote:
> On Fri, May 15, 2020 at 05:54:53PM +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> The comparison of hcd->irq to less than zero for an error check will
>> never be true because hcd->irq is an unsigned int.  Fix this by
>> assigning the int retval to the return of platform_get_irq and checking
>> this for the -ve error condition and assigning hcd->irq to retval.
>>
>> Addresses-Coverity: ("Unsigned compared against 0")
>> Fixes: c856b4b0fdb5 ("USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe()")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
> Thanks to Coverity for spotting this.  Any reason why it didn't spot
> exactly the same mistake in the ohci-da8xx.c driver?

I just looked at the code and wondered whether it would be more 
appropriate to modify the header file "hcd.h".  Since 'irq' might be an 
negative, why not just modify the variables in the 'struct usb_hcd',  
'unsigned int  irq'--> 'int irq'? After all, it's a public one.

Thanks,

Tang Bin

>
>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparisonof an unsigned int
  2020-05-15 23:23   ` [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparisonof " Tang Bin
@ 2020-05-16  1:17     ` Alan Stern
  0 siblings, 0 replies; 8+ messages in thread
From: Alan Stern @ 2020-05-16  1:17 UTC (permalink / raw)
  To: Tang Bin
  Cc: Colin King, Greg Kroah-Hartman, Zhang Shengju, linux-usb,
	kernel-janitors, linux-kernel

On Sat, May 16, 2020 at 07:23:42AM +0800, Tang Bin wrote:
> Hi Alan & Colin:
> 
> On 2020/5/16 1:21, Alan Stern wrote:
> > On Fri, May 15, 2020 at 05:54:53PM +0100, Colin King wrote:
> > > From: Colin Ian King <colin.king@canonical.com>
> > > 
> > > The comparison of hcd->irq to less than zero for an error check will
> > > never be true because hcd->irq is an unsigned int.  Fix this by
> > > assigning the int retval to the return of platform_get_irq and checking
> > > this for the -ve error condition and assigning hcd->irq to retval.
> > > 
> > > Addresses-Coverity: ("Unsigned compared against 0")
> > > Fixes: c856b4b0fdb5 ("USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe()")
> > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > > ---
> > Thanks to Coverity for spotting this.  Any reason why it didn't spot
> > exactly the same mistake in the ohci-da8xx.c driver?
> 
> I just looked at the code and wondered whether it would be more appropriate
> to modify the header file "hcd.h".  Since 'irq' might be an negative, why
> not just modify the variables in the 'struct usb_hcd',  'unsigned int 
> irq'--> 'int irq'? After all, it's a public one.

I think the code in the drivers should be changed.  The reason is if 
platform_get_irq() returns a negative value, then that value should be 
what the probe function returns.

Alan Stern

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int
  2020-05-15 17:21 ` Alan Stern
  2020-05-15 17:26   ` Colin Ian King
  2020-05-15 23:23   ` [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparisonof " Tang Bin
@ 2020-05-16  6:30   ` Greg Kroah-Hartman
  2020-05-16  9:25     ` Colin Ian King
  2 siblings, 1 reply; 8+ messages in thread
From: Greg Kroah-Hartman @ 2020-05-16  6:30 UTC (permalink / raw)
  To: Alan Stern
  Cc: Colin King, Zhang Shengju, Tang Bin, linux-usb, kernel-janitors,
	linux-kernel

On Fri, May 15, 2020 at 01:21:21PM -0400, Alan Stern wrote:
> On Fri, May 15, 2020 at 05:54:53PM +0100, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > The comparison of hcd->irq to less than zero for an error check will
> > never be true because hcd->irq is an unsigned int.  Fix this by
> > assigning the int retval to the return of platform_get_irq and checking
> > this for the -ve error condition and assigning hcd->irq to retval.
> > 
> > Addresses-Coverity: ("Unsigned compared against 0")
> > Fixes: c856b4b0fdb5 ("USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe()")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> 
> Thanks to Coverity for spotting this.  Any reason why it didn't spot 
> exactly the same mistake in the ohci-da8xx.c driver?

I think Coverity only runs on a limited kernel configuration and does
not build everything :(

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int
  2020-05-16  6:30   ` [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of " Greg Kroah-Hartman
@ 2020-05-16  9:25     ` Colin Ian King
  0 siblings, 0 replies; 8+ messages in thread
From: Colin Ian King @ 2020-05-16  9:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Alan Stern
  Cc: Zhang Shengju, Tang Bin, linux-usb, kernel-janitors, linux-kernel

On 16/05/2020 07:30, Greg Kroah-Hartman wrote:
> On Fri, May 15, 2020 at 01:21:21PM -0400, Alan Stern wrote:
>> On Fri, May 15, 2020 at 05:54:53PM +0100, Colin King wrote:
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> The comparison of hcd->irq to less than zero for an error check will
>>> never be true because hcd->irq is an unsigned int.  Fix this by
>>> assigning the int retval to the return of platform_get_irq and checking
>>> this for the -ve error condition and assigning hcd->irq to retval.
>>>
>>> Addresses-Coverity: ("Unsigned compared against 0")
>>> Fixes: c856b4b0fdb5 ("USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe()")
>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>>> ---
>>
>> Thanks to Coverity for spotting this.  Any reason why it didn't spot 
>> exactly the same mistake in the ohci-da8xx.c driver?
> 
> I think Coverity only runs on a limited kernel configuration and does
> not build everything :(
> 
I do x86-64 make allmodconfig builds, so it does a fair amount of
coverage on the builds

Colin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-05-16  9:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 16:54 [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int Colin King
2020-05-15 17:21 ` Alan Stern
2020-05-15 17:26   ` Colin Ian King
2020-05-15 18:43     ` Alan Stern
2020-05-15 23:23   ` [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparisonof " Tang Bin
2020-05-16  1:17     ` Alan Stern
2020-05-16  6:30   ` [PATCH][next] USB: EHCI: ehci-mv: fix less than zero comparison of " Greg Kroah-Hartman
2020-05-16  9:25     ` Colin Ian King

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).