]> Git Repo - linux.git/commitdiff
[media] media: stk1160: Avoid stack-allocated buffer for control URBs
authorEzequiel Garcia <[email protected]>
Thu, 17 Apr 2014 12:28:20 +0000 (09:28 -0300)
committerMauro Carvalho Chehab <[email protected]>
Sat, 24 May 2014 20:12:11 +0000 (17:12 -0300)
Currently stk1160_read_reg() uses a stack-allocated char to get the
read control value. This is wrong because usb_control_msg() requires
a kmalloc-ed buffer.

This commit fixes such issue by kmalloc'ating a 1-byte buffer to receive
the read value.

While here, let's remove the urb_buf array which was meant for a similar
purpose, but never really used.

Cc: Alan Stern <[email protected]>
Reported-by: Sander Eikelenboom <[email protected]>
Signed-off-by: Ezequiel Garcia <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Cc: [email protected] # for v3.7 and up
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
drivers/media/usb/stk1160/stk1160-core.c
drivers/media/usb/stk1160/stk1160.h

index 34a26e0cfe77565f81924b325fb06a9d78750009..03504dcf3c5240cb8d3ee43bff40eac311c1b4cc 100644 (file)
@@ -67,17 +67,25 @@ int stk1160_read_reg(struct stk1160 *dev, u16 reg, u8 *value)
 {
        int ret;
        int pipe = usb_rcvctrlpipe(dev->udev, 0);
+       u8 *buf;
 
        *value = 0;
+
+       buf = kmalloc(sizeof(u8), GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
        ret = usb_control_msg(dev->udev, pipe, 0x00,
                        USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
-                       0x00, reg, value, sizeof(u8), HZ);
+                       0x00, reg, buf, sizeof(u8), HZ);
        if (ret < 0) {
                stk1160_err("read failed on reg 0x%x (%d)\n",
                        reg, ret);
+               kfree(buf);
                return ret;
        }
 
+       *value = *buf;
+       kfree(buf);
        return 0;
 }
 
index 05b05b160e1e9abdd886bf49702bc35c8b3a52dc..abdea484c9987ad25dcaff6e4582881522e5f68d 100644 (file)
@@ -143,7 +143,6 @@ struct stk1160 {
        int num_alt;
 
        struct stk1160_isoc_ctl isoc_ctl;
-       char urb_buf[255];       /* urb control msg buffer */
 
        /* frame properties */
        int width;                /* current frame width */
This page took 0.05056 seconds and 4 git commands to generate.