linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] usb: serial: simplify the ark3116_write_reg()
@ 2020-12-09  9:29 Zheng Yongjun
  2020-12-09 10:55 ` Johan Hovold
  0 siblings, 1 reply; 2+ messages in thread
From: Zheng Yongjun @ 2020-12-09  9:29 UTC (permalink / raw)
  To: johan, gregkh, linux-usb, linux-kernel; +Cc: Zheng Yongjun

Simplify the return expression.

Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
---
 drivers/usb/serial/ark3116.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 71a9206ea1e2..0f9fa0e7c50e 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -77,16 +77,11 @@ struct ark3116_private {
 static int ark3116_write_reg(struct usb_serial *serial,
 			     unsigned reg, __u8 val)
 {
-	int result;
 	 /* 0xfe 0x40 are magic values taken from original driver */
-	result = usb_control_msg(serial->dev,
-				 usb_sndctrlpipe(serial->dev, 0),
-				 0xfe, 0x40, val, reg,
-				 NULL, 0, ARK_TIMEOUT);
-	if (result)
-		return result;
-
-	return 0;
+	return usb_control_msg(serial->dev,
+			       usb_sndctrlpipe(serial->dev, 0),
+			       0xfe, 0x40, val, reg,
+			       NULL, 0, ARK_TIMEOUT);
 }
 
 static int ark3116_read_reg(struct usb_serial *serial,
-- 
2.22.0


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

* Re: [PATCH -next] usb: serial: simplify the ark3116_write_reg()
  2020-12-09  9:29 [PATCH -next] usb: serial: simplify the ark3116_write_reg() Zheng Yongjun
@ 2020-12-09 10:55 ` Johan Hovold
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2020-12-09 10:55 UTC (permalink / raw)
  To: Zheng Yongjun; +Cc: johan, gregkh, linux-usb, linux-kernel

On Wed, Dec 09, 2020 at 05:29:17PM +0800, Zheng Yongjun wrote:
> Simplify the return expression.
> 
> Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
> ---
>  drivers/usb/serial/ark3116.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
> index 71a9206ea1e2..0f9fa0e7c50e 100644
> --- a/drivers/usb/serial/ark3116.c
> +++ b/drivers/usb/serial/ark3116.c
> @@ -77,16 +77,11 @@ struct ark3116_private {
>  static int ark3116_write_reg(struct usb_serial *serial,
>  			     unsigned reg, __u8 val)
>  {
> -	int result;
>  	 /* 0xfe 0x40 are magic values taken from original driver */
> -	result = usb_control_msg(serial->dev,
> -				 usb_sndctrlpipe(serial->dev, 0),
> -				 0xfe, 0x40, val, reg,
> -				 NULL, 0, ARK_TIMEOUT);
> -	if (result)
> -		return result;

Since none of the callers bother to check for errors, how about you add
a dev_err() here similar to the one in ark3116_read_reg() instead?

> -
> -	return 0;

Keeping the explicit zero-return on success has the benefit of allowing
the casual developer to know what to expect when using this helper
without having to read the documentation (or implementation) of
usb_control_msg().

> +	return usb_control_msg(serial->dev,
> +			       usb_sndctrlpipe(serial->dev, 0),
> +			       0xfe, 0x40, val, reg,
> +			       NULL, 0, ARK_TIMEOUT);
>  }
>  
>  static int ark3116_read_reg(struct usb_serial *serial,

Johan

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

end of thread, other threads:[~2020-12-09 10:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-09  9:29 [PATCH -next] usb: serial: simplify the ark3116_write_reg() Zheng Yongjun
2020-12-09 10:55 ` Johan Hovold

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