Message ID | 20200923090519.361-2-himadrispandya@gmail.com |
---|---|
State | New |
Headers | show |
Series | [1/4] net: usbnet: use usb_control_msg_recv() and usb_control_msg_send() | expand |
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
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; } static int __usbnet_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, u16 value, u16 index, const void *data, u16 size) { - void *buf = NULL; - int err = -ENOMEM; - netdev_dbg(dev->net, "usbnet_write_cmd cmd=0x%02x reqtype=%02x" " value=0x%04x index=0x%04x size=%d\n", cmd, reqtype, value, index, size); - if (data) { - buf = kmemdup(data, size, GFP_KERNEL); - if (!buf) - goto out; - } else { - if (size) { - WARN_ON_ONCE(1); - err = -EINVAL; - goto out; - } - } - - err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), - cmd, reqtype, value, index, buf, size, + return usb_control_msg_send(dev->udev, 0, + cmd, reqtype, value, index, data, size, USB_CTRL_SET_TIMEOUT); - kfree(buf); - -out: - return err; } /*
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(-)