Commit d35ef8f8 authored by Colin Ian King's avatar Colin Ian King Committed by David S. Miller

rsi: fix memory leak on buf and usb_reg_buf

In the cases where len is too long, the error return path fails to
kfree allocated buffers buf and usb_reg_buf.  The simplest fix is to
perform the sanity check on len before the allocations to avoid having
to do the kfree'ing in the first place.

Detected by CoverityScan, CID#1452258,1452259 ("Resource Leak")

Fixes: 59f73e2a ("rsi: check length before USB read/write register")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 17e48577
...@@ -162,13 +162,13 @@ static int rsi_usb_reg_read(struct usb_device *usbdev, ...@@ -162,13 +162,13 @@ static int rsi_usb_reg_read(struct usb_device *usbdev,
u8 *buf; u8 *buf;
int status = -ENOMEM; int status = -ENOMEM;
if (len > RSI_USB_CTRL_BUF_SIZE)
return -EINVAL;
buf = kmalloc(RSI_USB_CTRL_BUF_SIZE, GFP_KERNEL); buf = kmalloc(RSI_USB_CTRL_BUF_SIZE, GFP_KERNEL);
if (!buf) if (!buf)
return status; return status;
if (len > RSI_USB_CTRL_BUF_SIZE)
return -EINVAL;
status = usb_control_msg(usbdev, status = usb_control_msg(usbdev,
usb_rcvctrlpipe(usbdev, 0), usb_rcvctrlpipe(usbdev, 0),
USB_VENDOR_REGISTER_READ, USB_VENDOR_REGISTER_READ,
...@@ -207,13 +207,13 @@ static int rsi_usb_reg_write(struct usb_device *usbdev, ...@@ -207,13 +207,13 @@ static int rsi_usb_reg_write(struct usb_device *usbdev,
u8 *usb_reg_buf; u8 *usb_reg_buf;
int status = -ENOMEM; int status = -ENOMEM;
if (len > RSI_USB_CTRL_BUF_SIZE)
return -EINVAL;
usb_reg_buf = kmalloc(RSI_USB_CTRL_BUF_SIZE, GFP_KERNEL); usb_reg_buf = kmalloc(RSI_USB_CTRL_BUF_SIZE, GFP_KERNEL);
if (!usb_reg_buf) if (!usb_reg_buf)
return status; return status;
if (len > RSI_USB_CTRL_BUF_SIZE)
return -EINVAL;
usb_reg_buf[0] = (value & 0x00ff); usb_reg_buf[0] = (value & 0x00ff);
usb_reg_buf[1] = (value & 0xff00) >> 8; usb_reg_buf[1] = (value & 0xff00) >> 8;
usb_reg_buf[2] = 0x0; usb_reg_buf[2] = 0x0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment