Re: [PATCH 2/2 v2] usb:gadget:dummy_hcd : Detect port and link state correctly to avoid unreachable code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 30 Aug 2013, Philippe De Swert wrote:

> Since USB_SS_PORT_LS_U0 is 0x0000 the & operation with the port state would
> always be 0. Thus the if would never be true. Moreover USB_PORT_STAT_ENABLE
> is 0x0002 and as such would never equal to 1. What we actually look for is a
> port that is in U0/link active state.

No, what we actually look for is an _enabled_ port in the U0 state.

> Thanks to Alan Stern for suggesting the correct test in this case.
> 
> Found with coverity: CID 744367, CID 145679
> 
> Signed-off-by: Philippe De Swert <philippe.deswert@xxxxxxxxxxxxxxx>
> ---
>  drivers/usb/gadget/dummy_hcd.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
> index 2e16c9a..f5c03dd 100644
> --- a/drivers/usb/gadget/dummy_hcd.c
> +++ b/drivers/usb/gadget/dummy_hcd.c
> @@ -311,10 +311,8 @@ static void set_link_state_by_speed(struct dummy_hcd *dum_hcd)
>  			     USB_PORT_STAT_CONNECTION) == 0)
>  				dum_hcd->port_status |=
>  					(USB_PORT_STAT_C_CONNECTION << 16);
> -			if ((dum_hcd->port_status &
> -			     USB_PORT_STAT_ENABLE) == 1 &&
> -				(dum_hcd->port_status &
> -				 USB_SS_PORT_LS_U0) == 1 &&
> +			if ((dum_hcd->port_status & USB_PORT_STAT_LINK_STATE) 
> +				== USB_SS_PORT_LS_U0 &&
>  				dum_hcd->rh_state != DUMMY_RH_SUSPENDED)
>  				dum_hcd->active = 1;
>  		}

Do not remove the test for USB_PORT_STAT_ENABLE; correct it.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux