diff mbox series

[-next] usb: ftdi-elan: Fix if == else warnings in ftdi_elan_respond_engine

Message ID 20190123123442.5256-1-yuehaibing@huawei.com (mailing list archive)
State New, archived
Headers show
Series [-next] usb: ftdi-elan: Fix if == else warnings in ftdi_elan_respond_engine | expand

Commit Message

Yue Haibing Jan. 23, 2019, 12:34 p.m. UTC
./drivers/usb/misc/ftdi-elan.c:972:10-12: WARNING: possible condition with no effect (if == else)
./drivers/usb/misc/ftdi-elan.c:983:9-11: WARNING: possible condition with no effect (if == else)
./drivers/usb/misc/ftdi-elan.c:2052:11-13: WARNING: possible condition with no effect (if == else)

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/usb/misc/ftdi-elan.c | 26 --------------------------
 1 file changed, 26 deletions(-)

Comments

Greg Kroah-Hartman Jan. 23, 2019, 12:43 p.m. UTC | #1
On Wed, Jan 23, 2019 at 08:34:42PM +0800, YueHaibing wrote:
> ./drivers/usb/misc/ftdi-elan.c:972:10-12: WARNING: possible condition with no effect (if == else)
> ./drivers/usb/misc/ftdi-elan.c:983:9-11: WARNING: possible condition with no effect (if == else)
> ./drivers/usb/misc/ftdi-elan.c:2052:11-13: WARNING: possible condition with no effect (if == else)
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

You can not just provide the output of a tool as a changelog text,
sorry.

Please explain what those lines mean, and why you are making the change
that you are.

> ---
>  drivers/usb/misc/ftdi-elan.c | 26 --------------------------
>  1 file changed, 26 deletions(-)
> 
> diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
> index 76c718a..257efac 100644
> --- a/drivers/usb/misc/ftdi-elan.c
> +++ b/drivers/usb/misc/ftdi-elan.c
> @@ -915,7 +915,6 @@ static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi)
>  	int bytes_read = 0;
>  	int retry_on_empty = 1;
>  	int retry_on_timeout = 3;
> -	int empty_packets = 0;
>  read:{
>  		int packet_bytes = 0;
>  		int retval = usb_bulk_msg(ftdi->udev,
> @@ -960,31 +959,6 @@ read:{
>  			dev_err(&ftdi->udev->dev, "error = %d with packet_bytes = %d with total %d bytes%s\n",
>  				retval, packet_bytes, bytes_read, diag);
>  			return retval;
> -		} else if (packet_bytes == 2) {
> -			unsigned char s0 = ftdi->bulk_in_buffer[0];
> -			unsigned char s1 = ftdi->bulk_in_buffer[1];
> -			empty_packets += 1;
> -			if (s0 == 0x31 && s1 == 0x60) {
> -				if (retry_on_empty-- > 0) {
> -					goto more;
> -				} else
> -					return 0;
> -			} else if (s0 == 0x31 && s1 == 0x00) {
> -				if (retry_on_empty-- > 0) {
> -					goto more;
> -				} else
> -					return 0;
> -			} else {
> -				if (retry_on_empty-- > 0) {
> -					goto more;
> -				} else
> -					return 0;
> -			}
> -		} else if (packet_bytes == 1) {
> -			if (retry_on_empty-- > 0) {
> -				goto more;
> -			} else
> -				return 0;

Are you _sure_ that these lines are not needed and that the compiler is
not really seeing them?  As it doesn't look that way to me, what am I
missing?

thanks,

greg k-h
Yue Haibing Jan. 23, 2019, 1:17 p.m. UTC | #2
On 2019/1/23 20:43, Greg KH wrote:
> On Wed, Jan 23, 2019 at 08:34:42PM +0800, YueHaibing wrote:
>> ./drivers/usb/misc/ftdi-elan.c:972:10-12: WARNING: possible condition with no effect (if == else)
>> ./drivers/usb/misc/ftdi-elan.c:983:9-11: WARNING: possible condition with no effect (if == else)
>> ./drivers/usb/misc/ftdi-elan.c:2052:11-13: WARNING: possible condition with no effect (if == else)
>>
>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> 
> You can not just provide the output of a tool as a changelog text,
> sorry.
> 
> Please explain what those lines mean, and why you are making the change
> that you are.

ok, will do that.

> 
>> ---
>>  drivers/usb/misc/ftdi-elan.c | 26 --------------------------
>>  1 file changed, 26 deletions(-)
>>
>> diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
>> index 76c718a..257efac 100644
>> --- a/drivers/usb/misc/ftdi-elan.c
>> +++ b/drivers/usb/misc/ftdi-elan.c
>> @@ -915,7 +915,6 @@ static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi)
>>  	int bytes_read = 0;
>>  	int retry_on_empty = 1;
>>  	int retry_on_timeout = 3;
>> -	int empty_packets = 0;
>>  read:{
>>  		int packet_bytes = 0;
>>  		int retval = usb_bulk_msg(ftdi->udev,
>> @@ -960,31 +959,6 @@ read:{
>>  			dev_err(&ftdi->udev->dev, "error = %d with packet_bytes = %d with total %d bytes%s\n",
>>  				retval, packet_bytes, bytes_read, diag);
>>  			return retval;
>> -		} else if (packet_bytes == 2) {
>> -			unsigned char s0 = ftdi->bulk_in_buffer[0];
>> -			unsigned char s1 = ftdi->bulk_in_buffer[1];
>> -			empty_packets += 1;
>> -			if (s0 == 0x31 && s1 == 0x60) {
>> -				if (retry_on_empty-- > 0) {
>> -					goto more;
>> -				} else
>> -					return 0;
>> -			} else if (s0 == 0x31 && s1 == 0x00) {
>> -				if (retry_on_empty-- > 0) {
>> -					goto more;
>> -				} else
>> -					return 0;
>> -			} else {
>> -				if (retry_on_empty-- > 0) {
>> -					goto more;
>> -				} else
>> -					return 0;
>> -			}
>> -		} else if (packet_bytes == 1) {
>> -			if (retry_on_empty-- > 0) {
>> -				goto more;
>> -			} else
>> -				return 0;
> 
> Are you _sure_ that these lines are not needed and that the compiler is
> not really seeing them?  As it doesn't look that way to me, what am I
> missing?

I checked and make sure that All these if/else if branch just do the same thing:

	if (retry_on_empty-- > 0) {
		goto more;
	} else
		return 0;

so it can be merged into the last else branch.

Also the variable 'empty_packets' doesn't use in any place, except for self increment

> 
> thanks,
> 
> greg k-h
> 
> .
>
Greg Kroah-Hartman Jan. 23, 2019, 1:41 p.m. UTC | #3
On Wed, Jan 23, 2019 at 09:17:38PM +0800, YueHaibing wrote:
> On 2019/1/23 20:43, Greg KH wrote:
> > On Wed, Jan 23, 2019 at 08:34:42PM +0800, YueHaibing wrote:
> >> ./drivers/usb/misc/ftdi-elan.c:972:10-12: WARNING: possible condition with no effect (if == else)
> >> ./drivers/usb/misc/ftdi-elan.c:983:9-11: WARNING: possible condition with no effect (if == else)
> >> ./drivers/usb/misc/ftdi-elan.c:2052:11-13: WARNING: possible condition with no effect (if == else)
> >>
> >> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> > 
> > You can not just provide the output of a tool as a changelog text,
> > sorry.
> > 
> > Please explain what those lines mean, and why you are making the change
> > that you are.
> 
> ok, will do that.
> 
> > 
> >> ---
> >>  drivers/usb/misc/ftdi-elan.c | 26 --------------------------
> >>  1 file changed, 26 deletions(-)
> >>
> >> diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
> >> index 76c718a..257efac 100644
> >> --- a/drivers/usb/misc/ftdi-elan.c
> >> +++ b/drivers/usb/misc/ftdi-elan.c
> >> @@ -915,7 +915,6 @@ static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi)
> >>  	int bytes_read = 0;
> >>  	int retry_on_empty = 1;
> >>  	int retry_on_timeout = 3;
> >> -	int empty_packets = 0;
> >>  read:{
> >>  		int packet_bytes = 0;
> >>  		int retval = usb_bulk_msg(ftdi->udev,
> >> @@ -960,31 +959,6 @@ read:{
> >>  			dev_err(&ftdi->udev->dev, "error = %d with packet_bytes = %d with total %d bytes%s\n",
> >>  				retval, packet_bytes, bytes_read, diag);
> >>  			return retval;
> >> -		} else if (packet_bytes == 2) {
> >> -			unsigned char s0 = ftdi->bulk_in_buffer[0];
> >> -			unsigned char s1 = ftdi->bulk_in_buffer[1];
> >> -			empty_packets += 1;
> >> -			if (s0 == 0x31 && s1 == 0x60) {
> >> -				if (retry_on_empty-- > 0) {
> >> -					goto more;
> >> -				} else
> >> -					return 0;
> >> -			} else if (s0 == 0x31 && s1 == 0x00) {
> >> -				if (retry_on_empty-- > 0) {
> >> -					goto more;
> >> -				} else
> >> -					return 0;
> >> -			} else {
> >> -				if (retry_on_empty-- > 0) {
> >> -					goto more;
> >> -				} else
> >> -					return 0;
> >> -			}
> >> -		} else if (packet_bytes == 1) {
> >> -			if (retry_on_empty-- > 0) {
> >> -				goto more;
> >> -			} else
> >> -				return 0;
> > 
> > Are you _sure_ that these lines are not needed and that the compiler is
> > not really seeing them?  As it doesn't look that way to me, what am I
> > missing?
> 
> I checked and make sure that All these if/else if branch just do the same thing:
> 
> 	if (retry_on_empty-- > 0) {
> 		goto more;
> 	} else
> 		return 0;
> 
> so it can be merged into the last else branch.
> 
> Also the variable 'empty_packets' doesn't use in any place, except for self increment

Don't do two different things in the same patch :)
Yue Haibing Jan. 23, 2019, 1:55 p.m. UTC | #4
On 2019/1/23 21:41, Greg KH wrote:
> On Wed, Jan 23, 2019 at 09:17:38PM +0800, YueHaibing wrote:
>> On 2019/1/23 20:43, Greg KH wrote:
>>> On Wed, Jan 23, 2019 at 08:34:42PM +0800, YueHaibing wrote:
>>>> ./drivers/usb/misc/ftdi-elan.c:972:10-12: WARNING: possible condition with no effect (if == else)
>>>> ./drivers/usb/misc/ftdi-elan.c:983:9-11: WARNING: possible condition with no effect (if == else)
>>>> ./drivers/usb/misc/ftdi-elan.c:2052:11-13: WARNING: possible condition with no effect (if == else)
>>>>
>>>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>>>
>>> You can not just provide the output of a tool as a changelog text,
>>> sorry.
>>>
>>> Please explain what those lines mean, and why you are making the change
>>> that you are.
>>
>> ok, will do that.
>>
>>>
>>>> ---
>>>>  drivers/usb/misc/ftdi-elan.c | 26 --------------------------
>>>>  1 file changed, 26 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
>>>> index 76c718a..257efac 100644
>>>> --- a/drivers/usb/misc/ftdi-elan.c
>>>> +++ b/drivers/usb/misc/ftdi-elan.c
>>>> @@ -915,7 +915,6 @@ static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi)
>>>>  	int bytes_read = 0;
>>>>  	int retry_on_empty = 1;
>>>>  	int retry_on_timeout = 3;
>>>> -	int empty_packets = 0;
>>>>  read:{
>>>>  		int packet_bytes = 0;
>>>>  		int retval = usb_bulk_msg(ftdi->udev,
>>>> @@ -960,31 +959,6 @@ read:{
>>>>  			dev_err(&ftdi->udev->dev, "error = %d with packet_bytes = %d with total %d bytes%s\n",
>>>>  				retval, packet_bytes, bytes_read, diag);
>>>>  			return retval;
>>>> -		} else if (packet_bytes == 2) {
>>>> -			unsigned char s0 = ftdi->bulk_in_buffer[0];
>>>> -			unsigned char s1 = ftdi->bulk_in_buffer[1];
>>>> -			empty_packets += 1;
>>>> -			if (s0 == 0x31 && s1 == 0x60) {
>>>> -				if (retry_on_empty-- > 0) {
>>>> -					goto more;
>>>> -				} else
>>>> -					return 0;
>>>> -			} else if (s0 == 0x31 && s1 == 0x00) {
>>>> -				if (retry_on_empty-- > 0) {
>>>> -					goto more;
>>>> -				} else
>>>> -					return 0;
>>>> -			} else {
>>>> -				if (retry_on_empty-- > 0) {
>>>> -					goto more;
>>>> -				} else
>>>> -					return 0;
>>>> -			}
>>>> -		} else if (packet_bytes == 1) {
>>>> -			if (retry_on_empty-- > 0) {
>>>> -				goto more;
>>>> -			} else
>>>> -				return 0;
>>>
>>> Are you _sure_ that these lines are not needed and that the compiler is
>>> not really seeing them?  As it doesn't look that way to me, what am I
>>> missing?
>>
>> I checked and make sure that All these if/else if branch just do the same thing:
>>
>> 	if (retry_on_empty-- > 0) {
>> 		goto more;
>> 	} else
>> 		return 0;
>>
>> so it can be merged into the last else branch.
>>
>> Also the variable 'empty_packets' doesn't use in any place, except for self increment
> 
> Don't do two different things in the same patch :)

Thanks, I will split it into two.

> 
> 
> .
>
diff mbox series

Patch

diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 76c718a..257efac 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -915,7 +915,6 @@  static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi)
 	int bytes_read = 0;
 	int retry_on_empty = 1;
 	int retry_on_timeout = 3;
-	int empty_packets = 0;
 read:{
 		int packet_bytes = 0;
 		int retval = usb_bulk_msg(ftdi->udev,
@@ -960,31 +959,6 @@  read:{
 			dev_err(&ftdi->udev->dev, "error = %d with packet_bytes = %d with total %d bytes%s\n",
 				retval, packet_bytes, bytes_read, diag);
 			return retval;
-		} else if (packet_bytes == 2) {
-			unsigned char s0 = ftdi->bulk_in_buffer[0];
-			unsigned char s1 = ftdi->bulk_in_buffer[1];
-			empty_packets += 1;
-			if (s0 == 0x31 && s1 == 0x60) {
-				if (retry_on_empty-- > 0) {
-					goto more;
-				} else
-					return 0;
-			} else if (s0 == 0x31 && s1 == 0x00) {
-				if (retry_on_empty-- > 0) {
-					goto more;
-				} else
-					return 0;
-			} else {
-				if (retry_on_empty-- > 0) {
-					goto more;
-				} else
-					return 0;
-			}
-		} else if (packet_bytes == 1) {
-			if (retry_on_empty-- > 0) {
-				goto more;
-			} else
-				return 0;
 		} else {
 			if (retry_on_empty-- > 0) {
 				goto more;