All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: serial: Correct return value on read
@ 2017-11-26 16:18 Gimcuan Hui
  2017-11-27 10:21 ` Johan Hovold
  0 siblings, 1 reply; 3+ messages in thread
From: Gimcuan Hui @ 2017-11-26 16:18 UTC (permalink / raw)
  To: Johan Hovold; +Cc: gregkh, linux-usb, linux-kernel

It's meaningless to return buf[0] on read. Because the caller of this
interface checks the return value negative or not. Instead, we should
return the result variable.

Signed-off-by: Gimcuan Hui <gimcuan@gmail.com>
---
 drivers/usb/serial/ark3116.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 3c544782f60b..bfdbc7164e7b 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -101,11 +101,9 @@ static int ark3116_read_reg(struct usb_serial *serial,
 				reg, result);
 		if (result >= 0)
 			result = -EIO;
-
-		return result;
 	}
 
-	return buf[0];
+	return result;
 }
 
 static inline int calc_divisor(int bps)
-- 
2.11.0

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

* Re: [PATCH] USB: serial: Correct return value on read
  2017-11-26 16:18 [PATCH] USB: serial: Correct return value on read Gimcuan Hui
@ 2017-11-27 10:21 ` Johan Hovold
  2017-11-27 14:21   ` saks cuso
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2017-11-27 10:21 UTC (permalink / raw)
  To: Gimcuan Hui; +Cc: Johan Hovold, gregkh, linux-usb, linux-kernel

On Sun, Nov 26, 2017 at 04:18:51PM +0000, Gimcuan Hui wrote:
> It's meaningless to return buf[0] on read. Because the caller of this
> interface checks the return value negative or not. Instead, we should
> return the result variable.

It's not really meaningless, it's just that the return value is no
longer being used the way it was originally intended. I think
"redundant" and/or "confusing" would be a more appropriate description.

> Signed-off-by: Gimcuan Hui <gimcuan@gmail.com>
> ---
>  drivers/usb/serial/ark3116.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
> index 3c544782f60b..bfdbc7164e7b 100644
> --- a/drivers/usb/serial/ark3116.c
> +++ b/drivers/usb/serial/ark3116.c
> @@ -101,11 +101,9 @@ static int ark3116_read_reg(struct usb_serial *serial,
>  				reg, result);
>  		if (result >= 0)
>  			result = -EIO;
> -
> -		return result;
>  	}
>  
> -	return buf[0];
> +	return result;

Also we do not want to return the value of result on success as that
would always be 1 (i.e. the buffer size).

You could change this function, and also the write_reg one, to return 0
on success since this is a more common pattern.

Please also rephrase your commit summary (Subject) since you're not
really "correcting" (as in fixing) anything here. This is more a of nice
clean up, even if it could potentially also prevent future bugs.

Thanks,
Johan

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

* Re: [PATCH] USB: serial: Correct return value on read
  2017-11-27 10:21 ` Johan Hovold
@ 2017-11-27 14:21   ` saks cuso
  0 siblings, 0 replies; 3+ messages in thread
From: saks cuso @ 2017-11-27 14:21 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On 27 November 2017 at 10:21, Johan Hovold <johan@kernel.org> wrote:
> On Sun, Nov 26, 2017 at 04:18:51PM +0000, Gimcuan Hui wrote:
>> It's meaningless to return buf[0] on read. Because the caller of this
>> interface checks the return value negative or not. Instead, we should
>> return the result variable.
>
> It's not really meaningless, it's just that the return value is no
> longer being used the way it was originally intended. I think
> "redundant" and/or "confusing" would be a more appropriate description.
>

yes,  i will use "confusing" instead.

>> Signed-off-by: Gimcuan Hui <gimcuan@gmail.com>
>> ---
>>  drivers/usb/serial/ark3116.c | 4 +---
>>  1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
>> index 3c544782f60b..bfdbc7164e7b 100644
>> --- a/drivers/usb/serial/ark3116.c
>> +++ b/drivers/usb/serial/ark3116.c
>> @@ -101,11 +101,9 @@ static int ark3116_read_reg(struct usb_serial *serial,
>>                               reg, result);
>>               if (result >= 0)
>>                       result = -EIO;
>> -
>> -             return result;
>>       }
>>
>> -     return buf[0];
>> +     return result;
>
> Also we do not want to return the value of result on success as that
> would always be 1 (i.e. the buffer size).
>
> You could change this function, and also the write_reg one, to return 0
> on success since this is a more common pattern.
>
> Please also rephrase your commit summary (Subject) since you're not
> really "correcting" (as in fixing) anything here. This is more a of nice
> clean up, even if it could potentially also prevent future bugs.
>
> Thanks,
> Johan

agree, v2 will be post soon.

thank you for correcting.

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

end of thread, other threads:[~2017-11-27 14:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-26 16:18 [PATCH] USB: serial: Correct return value on read Gimcuan Hui
2017-11-27 10:21 ` Johan Hovold
2017-11-27 14:21   ` saks cuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.