mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Himadri Pandya <himadrispandya@gmail.com>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] USB: serial: cp210x: use usb_control_msg_recv() and usb_control_msg_send()
Date: Wed, 27 Oct 2021 15:17:50 +0200	[thread overview]
Message-ID: <YXlRfsv6L53ZaaA7@hovoldconsulting.com> (raw)
In-Reply-To: <20211001065720.21330-3-himadrispandya@gmail.com>

On Fri, Oct 01, 2021 at 08:57:20AM +0200, Himadri Pandya wrote:
> The new wrapper functions for usb_control_msg() can accept data from
> stack and treat short reads as error. Hence use the wrappers functions.
> Please note that because of this change, cp210x_read_reg_block() will no
> longer log the length of short reads.
> 
> Signed-off-by: Himadri Pandya <himadrispandya@gmail.com>
> ---
> Changes in v3:
>  - Rephrase the commit message
>  - Explicitly mention that short reads don't log length now
> 
> Changes in v2:
>  - Drop unrelated style fixes

This looks good now, but I did do some minor style changes described
below.

> ---
>  drivers/usb/serial/cp210x.c | 106 ++++++++++--------------------------
>  1 file changed, 30 insertions(+), 76 deletions(-)
> 
> diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> index 189279869a8b..3c3ca46b0b82 100644
> --- a/drivers/usb/serial/cp210x.c
> +++ b/drivers/usb/serial/cp210x.c
> @@ -631,29 +631,19 @@ static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req,
>  {
>  	struct usb_serial *serial = port->serial;
>  	struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
> -	void *dmabuf;
>  	int result;
>  
> -	dmabuf = kmalloc(bufsize, GFP_KERNEL);
> -	if (!dmabuf)
> -		return -ENOMEM;
>  
> -	result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
> -			req, REQTYPE_INTERFACE_TO_HOST, 0,
> -			port_priv->bInterfaceNumber, dmabuf, bufsize,
> -			USB_CTRL_GET_TIMEOUT);
> -	if (result == bufsize) {
> -		memcpy(buf, dmabuf, bufsize);
> -		result = 0;
> -	} else {
> +	result = usb_control_msg_recv(serial->dev, 0, req,
> +				      REQTYPE_INTERFACE_TO_HOST, 0,
> +				      port_priv->bInterfaceNumber, buf,
> +				      bufsize, USB_CTRL_SET_TIMEOUT,
> +				      GFP_KERNEL);

The indentation style of this driver is a bit inconsistent but there's
no need to change to the open-parenthesis alignment style when you can
avoid it (it's mostly just "checkpacth.pl --subjective" that insists on
it).

Indenting continuation lines two tabs is just fine and avoids excessive
indentation and having to realign arguments when symbol names change.

> +	if (result) {
>  		dev_err(&port->dev, "failed get req 0x%x size %d status: %d\n",
>  				req, bufsize, result);
> -		if (result >= 0)
> -			result = -EIO;
>  	}
>  
> -	kfree(dmabuf);
> -
>  	return result;

I changed this to explicit zero and return an error above instead.

> @@ -952,27 +915,18 @@ static int cp210x_get_tx_queue_byte_count(struct usb_serial_port *port,
>  {
>  	struct usb_serial *serial = port->serial;
>  	struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
> -	struct cp210x_comm_status *sts;
> +	struct cp210x_comm_status sts;
>  	int result;
>  
> -	sts = kmalloc(sizeof(*sts), GFP_KERNEL);
> -	if (!sts)
> -		return -ENOMEM;
> -
> -	result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
> -			CP210X_GET_COMM_STATUS, REQTYPE_INTERFACE_TO_HOST,
> -			0, port_priv->bInterfaceNumber, sts, sizeof(*sts),
> -			USB_CTRL_GET_TIMEOUT);
> -	if (result == sizeof(*sts)) {
> -		*count = le32_to_cpu(sts->ulAmountInOutQueue);
> -		result = 0;
> -	} else {
> +	result = usb_control_msg_recv(serial->dev, 0, CP210X_GET_COMM_STATUS,
> +				      REQTYPE_INTERFACE_TO_HOST, 0,
> +				      port_priv->bInterfaceNumber, &sts,
> +				      sizeof(sts), USB_CTRL_GET_TIMEOUT,
> +				      GFP_KERNEL);
> +	if (result == 0)
> +		*count = le32_to_cpu(sts.ulAmountInOutQueue);
> +	else
>  		dev_err(&port->dev, "failed to get comm status: %d\n", result);
> -		if (result >= 0)
> -			result = -EIO;
> -	}
> -
> -	kfree(sts);

The above is now also better handled with an explicit error check and
early return and the doing the *count assignment in the success path.

>  
>  	return result;
>  }

Now applied with the above changes. The result is here:

	https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git/commit/?h=usb-next&id=f5cfbecb0a162319464c9408420282d22ed69721

Johan

  reply	other threads:[~2021-10-27 13:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01  6:57 [PATCH v3 0/2] USB: serial: use wrappers for usb_control_msg() Himadri Pandya
2021-10-01  6:57 ` [PATCH v3 1/2] USB: serial: ch314: use usb_control_msg_recv() and usb_control_msg_send() Himadri Pandya
2021-10-27 13:04   ` Johan Hovold
2021-10-27 13:28     ` Himadri Pandya
2021-10-27 13:37       ` Johan Hovold
2021-10-27 13:47         ` Himadri Pandya
2021-10-01  6:57 ` [PATCH v3 2/2] USB: serial: cp210x: " Himadri Pandya
2021-10-27 13:17   ` Johan Hovold [this message]
2021-10-27 13:34     ` Himadri Pandya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YXlRfsv6L53ZaaA7@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=himadrispandya@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome