Many usage of usb_control_msg() do not have proper error check on return
value leaving scope for bugs on short reads. New usb_control_msg_recv()
and usb_control_msg_send() nicely wraps usb_control_msg() with proper
error check. Hence use the wrappers instead of calling usb_control_msg()
directly.

Signed-off-by: Himadri Pandya <himadrispan...@gmail.com>
---
 drivers/net/usb/rtl8150.c | 32 ++++++--------------------------
 1 file changed, 6 insertions(+), 26 deletions(-)

diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index 733f120c852b..e3002b675921 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -152,36 +152,16 @@ static const char driver_name [] = "rtl8150";
 */
 static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
 {
-       void *buf;
-       int ret;
-
-       buf = kmalloc(size, GFP_NOIO);
-       if (!buf)
-               return -ENOMEM;
-
-       ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
-                             RTL8150_REQ_GET_REGS, RTL8150_REQT_READ,
-                             indx, 0, buf, size, 500);
-       if (ret > 0 && ret <= size)
-               memcpy(data, buf, ret);
-       kfree(buf);
-       return ret;
+       return usb_control_msg_recv(dev->udev, 0, RTL8150_REQ_GET_REGS,
+                                   RTL8150_REQT_READ, indx, 0, data,
+                                   size, 500);
 }
 
 static int set_registers(rtl8150_t * dev, u16 indx, u16 size, const void *data)
 {
-       void *buf;
-       int ret;
-
-       buf = kmemdup(data, size, GFP_NOIO);
-       if (!buf)
-               return -ENOMEM;
-
-       ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
-                             RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE,
-                             indx, 0, buf, size, 500);
-       kfree(buf);
-       return ret;
+       return usb_control_msg_send(dev->udev, 0, RTL8150_REQ_SET_REGS,
+                                   RTL8150_REQT_WRITE, indx, 0, data,
+                                   size, 500);
 }
 
 static void async_set_reg_cb(struct urb *urb)
-- 
2.17.1

Reply via email to