linux-usb.vger.kernel.org archive mirror
 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 v2 2/6] USB: serial: cp210x: use usb_control_msg_recv() and usb_control_msg_send()
Date: Tue, 21 Sep 2021 13:34:57 +0200	[thread overview]
Message-ID: <YUnDYWWhEUpnMq7R@hovoldconsulting.com> (raw)
In-Reply-To: <20210801203122.3515-3-himadrispandya@gmail.com>

On Mon, Aug 02, 2021 at 02:01:18AM +0530, Himadri Pandya wrote:
> The new wrapper functions for usb_control_msg() can accept data from
> stack with robust error checks.

Please rephrase the "robust error checks" along the lines of "treats
short reads as an error".

> Hence use the wrappers with stack
> variables for usb transfer buffers to save kernel memory.

Again, you're not saving memory here, just moving the allocation.

> Signed-off-by: Himadri Pandya <himadrispandya@gmail.com>
> ---
> Changes in v2:
>  - Drop unrelated style fixes
> ---
>  drivers/usb/serial/cp210x.c | 107 ++++++++++--------------------------
>  1 file changed, 30 insertions(+), 77 deletions(-)
> 
> diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> index 3c80bfbf3bec..b73581fc1768 100644
> --- a/drivers/usb/serial/cp210x.c
> +++ b/drivers/usb/serial/cp210x.c
> @@ -628,29 +628,18 @@ 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_SET_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);
> +	if (result) {
>  		dev_err(&port->dev, "failed get req 0x%x size %d status: %d\n",
>  				req, bufsize, result);

This will also no longer log the length of short reads. Please at least
mention it in the commit message.

> -		if (result >= 0)
> -			result = -EIO;
>  	}
>  
> -	kfree(dmabuf);
> -
>  	return result;
>  }

Johan

  reply	other threads:[~2021-09-21 11:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-01 20:31 [PATCH v2 0/6] USB: serial: use wrappers for usb_control_msg() Himadri Pandya
2021-08-01 20:31 ` [PATCH v2 1/6] USB: serial: ch314: use usb_control_msg_recv() and usb_control_msg_send() Himadri Pandya
2021-09-21 11:26   ` Johan Hovold
2021-08-01 20:31 ` [PATCH v2 2/6] USB: serial: cp210x: " Himadri Pandya
2021-09-21 11:34   ` Johan Hovold [this message]
2021-08-01 20:31 ` [PATCH v2 3/6] USB: serial: f81232: " Himadri Pandya
2021-09-21 12:06   ` Johan Hovold
2021-08-01 20:31 ` [PATCH v2 4/6] USB: serial: ftdi_sio: use usb_control_msg_recv() Himadri Pandya
2021-09-21 12:17   ` Johan Hovold
2021-08-01 20:31 ` [PATCH v2 5/6] USB: serial: keyspan_pda: " Himadri Pandya
2021-09-21 12:27   ` Johan Hovold
2021-08-01 20:31 ` [PATCH v2 6/6] USB: serial: kl5kusb105: use usb_control_msg_recv() and usb_control_msg_send() Himadri Pandya
2021-09-21 12:41   ` Johan Hovold
2021-09-26 13:00     ` Himadri Pandya
2021-09-21 11:10 ` [PATCH v2 0/6] USB: serial: use wrappers for usb_control_msg() Johan Hovold

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=YUnDYWWhEUpnMq7R@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;
as well as URLs for NNTP newsgroup(s).