linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Himadri Pandya <himadrispandya@gmail.com>
Cc: linux-usb@vger.kernel.org, keescook@chromium.org,
	pankaj.laxminarayan.bharadiya@intel.com, oneukum@suse.com,
	yuehaibing@huawei.com, linux-kernel@vger.kernel.org,
	ogiannou@gmail.com, netdev@vger.kernel.org, kuba@kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	davem@davemloft.net, petkan@nucleusys.com
Subject: Re: [Linux-kernel-mentees] [PATCH 1/4] net: usbnet: use usb_control_msg_recv() and usb_control_msg_send()
Date: Wed, 23 Sep 2020 12:24:25 +0200	[thread overview]
Message-ID: <20200923102425.GC3154647@kroah.com> (raw)
In-Reply-To: <20200923090519.361-2-himadrispandya@gmail.com>

On Wed, Sep 23, 2020 at 02:35:16PM +0530, Himadri Pandya wrote:
> Potential incorrect use of usb_control_msg() has resulted in new wrapper
> functions to enforce its correct usage with proper error check. Hence
> use these new wrapper functions instead of calling usb_control_msg()
> directly.
> 
> Signed-off-by: Himadri Pandya <himadrispandya@gmail.com>
> ---
>  drivers/net/usb/usbnet.c | 46 ++++------------------------------------
>  1 file changed, 4 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> index 2b2a841cd938..a38a85bef46a 100644
> --- a/drivers/net/usb/usbnet.c
> +++ b/drivers/net/usb/usbnet.c
> @@ -1982,64 +1982,26 @@ EXPORT_SYMBOL(usbnet_link_change);
>  static int __usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
>  			     u16 value, u16 index, void *data, u16 size)
>  {
> -	void *buf = NULL;
> -	int err = -ENOMEM;
> -
>  	netdev_dbg(dev->net, "usbnet_read_cmd cmd=0x%02x reqtype=%02x"
>  		   " value=0x%04x index=0x%04x size=%d\n",
>  		   cmd, reqtype, value, index, size);
>  
> -	if (size) {
> -		buf = kmalloc(size, GFP_KERNEL);
> -		if (!buf)
> -			goto out;
> -	}
> -
> -	err = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
> -			      cmd, reqtype, value, index, buf, size,
> +	return usb_control_msg_recv(dev->udev, 0,
> +			      cmd, reqtype, value, index, data, size,
>  			      USB_CTRL_GET_TIMEOUT);
> -	if (err > 0 && err <= size) {
> -        if (data)
> -            memcpy(data, buf, err);
> -        else
> -            netdev_dbg(dev->net,
> -                "Huh? Data requested but thrown away.\n");
> -    }
> -	kfree(buf);
> -out:
> -	return err;
>  }

Now there is no real need for these wrapper functions at all, except for
the debugging which I doubt anyone needs anymore.

So how about just deleting these and calling the real function instead?

thanks,

greg k-h
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2020-09-23 10:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23  9:05 [Linux-kernel-mentees] [PATCH 0/4] net: usb: avoid using usb_control_msg() directly Himadri Pandya
2020-09-23  9:05 ` [Linux-kernel-mentees] [PATCH 1/4] net: usbnet: use usb_control_msg_recv() and usb_control_msg_send() Himadri Pandya
2020-09-23 10:24   ` Greg KH [this message]
2020-09-23 14:08     ` Himadri Pandya
2020-09-23  9:05 ` [Linux-kernel-mentees] [PATCH 2/4] net: sierra_net: use usb_control_msg_recv() Himadri Pandya
2020-09-23  9:05 ` [Linux-kernel-mentees] [PATCH 3/4] net: usb: rtl8150: use usb_control_msg_recv() and usb_control_msg_send() Himadri Pandya
2020-09-23 10:22   ` Oliver Neukum
2020-09-23 14:06     ` Himadri Pandya
2020-09-23 14:20       ` Oliver Neukum
2020-09-23 14:32         ` Himadri Pandya
2020-09-24 11:13           ` Oliver Neukum
2020-09-25 11:23             ` Himadri Pandya
2020-09-23 14:48     ` Petko Manolov
2020-09-24 11:09       ` Oliver Neukum
2020-09-24 15:40         ` Petko Manolov
2020-09-24 16:01           ` Greg KH
2020-09-23  9:05 ` [Linux-kernel-mentees] [PATCH 4/4] net: rndis_host: " Himadri Pandya
2020-09-23 10:22   ` Greg KH
2020-09-23 14:14     ` Himadri Pandya
2020-09-23 10:23 ` [Linux-kernel-mentees] [PATCH 0/4] net: usb: avoid using usb_control_msg() directly Greg KH

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=20200923102425.GC3154647@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=davem@davemloft.net \
    --cc=himadrispandya@gmail.com \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ogiannou@gmail.com \
    --cc=oneukum@suse.com \
    --cc=pankaj.laxminarayan.bharadiya@intel.com \
    --cc=petkan@nucleusys.com \
    --cc=yuehaibing@huawei.com \
    /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).