linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: usb251xb: Remove unnecessary comparison of unsigned integer with >= 0
@ 2019-03-18 14:50 Gustavo A. R. Silva
  2019-03-18 15:34 ` Marco Felsch
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2019-03-18 14:50 UTC (permalink / raw)
  To: Richard Leitner, Greg Kroah-Hartman, Marco Felsch
  Cc: linux-usb, linux-kernel, Gustavo A. R. Silva

There is no need to compare *port* with >= 0 because such comparison
of an unsigned value is always true.

Fix this by removing such comparison.

Addresses-Coverity-ID: 1443949 ("Unsigned compared against 0")
Fixes: 02a50b875046 ("usb: usb251xb: add usb data lane port swap feature")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/usb/misc/usb251xb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index 4d72b7d1d383..2c8e2cad7e10 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -547,7 +547,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
 	 */
 	hub->port_swap = USB251XB_DEF_PORT_SWAP;
 	of_property_for_each_u32(np, "swap-dx-lanes", prop, p, port) {
-		if ((port >= 0) && (port <= data->port_cnt))
+		if (port <= data->port_cnt)
 			hub->port_swap |= BIT(port);
 	}
 
-- 
2.21.0


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

* Re: [PATCH] usb: usb251xb: Remove unnecessary comparison of unsigned integer with >= 0
  2019-03-18 14:50 [PATCH] usb: usb251xb: Remove unnecessary comparison of unsigned integer with >= 0 Gustavo A. R. Silva
@ 2019-03-18 15:34 ` Marco Felsch
  2019-03-18 15:46   ` Richard Leitner
  0 siblings, 1 reply; 5+ messages in thread
From: Marco Felsch @ 2019-03-18 15:34 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Richard Leitner, Greg Kroah-Hartman, linux-usb, linux-kernel

Hi Silva,

On 19-03-18 09:50, Gustavo A. R. Silva wrote:
> There is no need to compare *port* with >= 0 because such comparison
> of an unsigned value is always true.

Absolutly.. It seems that it was an copy'n'paste failure. Thanks for
fixing that.

Regards,
Marco

> Fix this by removing such comparison.
> 
> Addresses-Coverity-ID: 1443949 ("Unsigned compared against 0")
> Fixes: 02a50b875046 ("usb: usb251xb: add usb data lane port swap feature")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/usb/misc/usb251xb.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> index 4d72b7d1d383..2c8e2cad7e10 100644
> --- a/drivers/usb/misc/usb251xb.c
> +++ b/drivers/usb/misc/usb251xb.c
> @@ -547,7 +547,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
>  	 */
>  	hub->port_swap = USB251XB_DEF_PORT_SWAP;
>  	of_property_for_each_u32(np, "swap-dx-lanes", prop, p, port) {
> -		if ((port >= 0) && (port <= data->port_cnt))
> +		if (port <= data->port_cnt)
>  			hub->port_swap |= BIT(port);
>  	}
>  
> -- 
> 2.21.0
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH] usb: usb251xb: Remove unnecessary comparison of unsigned integer with >= 0
  2019-03-18 15:34 ` Marco Felsch
@ 2019-03-18 15:46   ` Richard Leitner
  2019-03-18 16:48     ` Marco Felsch
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Leitner @ 2019-03-18 15:46 UTC (permalink / raw)
  To: Marco Felsch, Gustavo A. R. Silva
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

Hi Marco, Hi Gustavo,
thanks for the fix, please feel free to add

	Reviewed-by: Richard Leitner <richard.leitner@skidata.com>

On 18/03/2019 16:34, Marco Felsch wrote:
> Hi Silva,
> 
> On 19-03-18 09:50, Gustavo A. R. Silva wrote:
>> There is no need to compare *port* with >= 0 because such comparison
>> of an unsigned value is always true.
> 
> Absolutly.. It seems that it was an copy'n'paste failure. Thanks for
> fixing that.

A small note on further improvement from my side:

According the datasheet, when you set swap-dx-lanes to 0 (-> setting 
port to 0 -> setting bit 0 of PRTSP) "   the upstream port DP/DM is 
swapped".

IMHO this is not straight-forward, so maybe we want to additionally

	a) mention it somewhere in the documentation
	b) check on port >= 1
	c) something else?

Any opinions on that from your side? ... I'd prefer "a"...

regards;Richard.L

> 
> Regards,
> Marco
> 
>> Fix this by removing such comparison.
>>
>> Addresses-Coverity-ID: 1443949 ("Unsigned compared against 0")
>> Fixes: 02a50b875046 ("usb: usb251xb: add usb data lane port swap feature")
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
>>   drivers/usb/misc/usb251xb.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
>> index 4d72b7d1d383..2c8e2cad7e10 100644
>> --- a/drivers/usb/misc/usb251xb.c
>> +++ b/drivers/usb/misc/usb251xb.c
>> @@ -547,7 +547,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
>>   	 */
>>   	hub->port_swap = USB251XB_DEF_PORT_SWAP;
>>   	of_property_for_each_u32(np, "swap-dx-lanes", prop, p, port) {
>> -		if ((port >= 0) && (port <= data->port_cnt))
>> +		if (port <= data->port_cnt)
>>   			hub->port_swap |= BIT(port);
>>   	}
>>   
>> -- 
>> 2.21.0
>>
>>
> 

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

* Re: [PATCH] usb: usb251xb: Remove unnecessary comparison of unsigned integer with >= 0
  2019-03-18 15:46   ` Richard Leitner
@ 2019-03-18 16:48     ` Marco Felsch
  2019-03-19  9:33       ` Richard Leitner
  0 siblings, 1 reply; 5+ messages in thread
From: Marco Felsch @ 2019-03-18 16:48 UTC (permalink / raw)
  To: Richard Leitner
  Cc: Gustavo A. R. Silva, Greg Kroah-Hartman, linux-usb, linux-kernel

Hi Richard,

On 19-03-18 16:46, Richard Leitner wrote:
> Hi Marco, Hi Gustavo,
> thanks for the fix, please feel free to add
> 
> 	Reviewed-by: Richard Leitner <richard.leitner@skidata.com>
> 
> On 18/03/2019 16:34, Marco Felsch wrote:
> > Hi Silva,
> > 
> > On 19-03-18 09:50, Gustavo A. R. Silva wrote:
> > > There is no need to compare *port* with >= 0 because such comparison
> > > of an unsigned value is always true.
> > 
> > Absolutly.. It seems that it was an copy'n'paste failure. Thanks for
> > fixing that.
> 
> A small note on further improvement from my side:
> 
> According the datasheet, when you set swap-dx-lanes to 0 (-> setting port to
> 0 -> setting bit 0 of PRTSP) "   the upstream port DP/DM is swapped".

Yes I know that's not intuitve and may confuses the users.

> IMHO this is not straight-forward, so maybe we want to additionally
> 
> 	a) mention it somewhere in the documentation

IMHO this is the correct place.

> 	b) check on port >= 1

I think this isn't doable since we shouldn't break the existing dt.

Regards,
Marco

> 	c) something else?
> 
> Any opinions on that from your side? ... I'd prefer "a"...
> 
> regards;Richard.L
> 
> > 
> > Regards,
> > Marco
> > 
> > > Fix this by removing such comparison.
> > > 
> > > Addresses-Coverity-ID: 1443949 ("Unsigned compared against 0")
> > > Fixes: 02a50b875046 ("usb: usb251xb: add usb data lane port swap feature")
> > > Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> > > ---
> > >   drivers/usb/misc/usb251xb.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> > > index 4d72b7d1d383..2c8e2cad7e10 100644
> > > --- a/drivers/usb/misc/usb251xb.c
> > > +++ b/drivers/usb/misc/usb251xb.c
> > > @@ -547,7 +547,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
> > >   	 */
> > >   	hub->port_swap = USB251XB_DEF_PORT_SWAP;
> > >   	of_property_for_each_u32(np, "swap-dx-lanes", prop, p, port) {
> > > -		if ((port >= 0) && (port <= data->port_cnt))
> > > +		if (port <= data->port_cnt)
> > >   			hub->port_swap |= BIT(port);
> > >   	}
> > > -- 
> > > 2.21.0
> > > 
> > > 
> > 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH] usb: usb251xb: Remove unnecessary comparison of unsigned integer with >= 0
  2019-03-18 16:48     ` Marco Felsch
@ 2019-03-19  9:33       ` Richard Leitner
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Leitner @ 2019-03-19  9:33 UTC (permalink / raw)
  To: Marco Felsch
  Cc: Gustavo A. R. Silva, Greg Kroah-Hartman, linux-usb, linux-kernel


On 18/03/2019 17:48, Marco Felsch wrote:
> On 19-03-18 16:46, Richard Leitner wrote:
>> A small note on further improvement from my side:
>>
>> According the datasheet, when you set swap-dx-lanes to 0 (-> setting port to
>> 0 -> setting bit 0 of PRTSP) "   the upstream port DP/DM is swapped".
> 
> Yes I know that's not intuitve and may confuses the users.
> 
>> IMHO this is not straight-forward, so maybe we want to additionally
>>
>> 	a) mention it somewhere in the documentation
> 
> IMHO this is the correct place.
> 
>> 	b) check on port >= 1
> 
> I think this isn't doable since we shouldn't break the existing dt.

ACK.

@Marco/Gustavo: does one of you wants to provide a patch for this?

> 
> Regards,
> Marco
> 
>> 	c) something else?
>>
>> Any opinions on that from your side? ... I'd prefer "a"...

regards;Richard.L

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

end of thread, other threads:[~2019-03-19  9:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18 14:50 [PATCH] usb: usb251xb: Remove unnecessary comparison of unsigned integer with >= 0 Gustavo A. R. Silva
2019-03-18 15:34 ` Marco Felsch
2019-03-18 15:46   ` Richard Leitner
2019-03-18 16:48     ` Marco Felsch
2019-03-19  9:33       ` Richard Leitner

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