diff options
author | Ezequiel Garcia <ezequiel.garcia@free-electrons.com> | 2014-04-17 08:28:20 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2014-05-24 16:12:11 -0400 |
commit | 85ac1a1772bb41da895bad83a81f6a62c8f293f6 (patch) | |
tree | d491a04c51f663061fb9f7c968e2dbb1351e18fb | |
parent | 8774bed9ce832d8d9ccb79e92800b808aa2d2ad2 (diff) |
[media] media: stk1160: Avoid stack-allocated buffer for control URBs
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 <stern@rowland.harvard.edu>
Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Cc: stable@vger.kernel.org # for v3.7 and up
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
-rw-r--r-- | drivers/media/usb/stk1160/stk1160-core.c | 10 | ||||
-rw-r--r-- | drivers/media/usb/stk1160/stk1160.h | 1 |
2 files changed, 9 insertions, 2 deletions
diff --git a/drivers/media/usb/stk1160/stk1160-core.c b/drivers/media/usb/stk1160/stk1160-core.c index 34a26e0cfe77..03504dcf3c52 100644 --- a/drivers/media/usb/stk1160/stk1160-core.c +++ b/drivers/media/usb/stk1160/stk1160-core.c | |||
@@ -67,17 +67,25 @@ int stk1160_read_reg(struct stk1160 *dev, u16 reg, u8 *value) | |||
67 | { | 67 | { |
68 | int ret; | 68 | int ret; |
69 | int pipe = usb_rcvctrlpipe(dev->udev, 0); | 69 | int pipe = usb_rcvctrlpipe(dev->udev, 0); |
70 | u8 *buf; | ||
70 | 71 | ||
71 | *value = 0; | 72 | *value = 0; |
73 | |||
74 | buf = kmalloc(sizeof(u8), GFP_KERNEL); | ||
75 | if (!buf) | ||
76 | return -ENOMEM; | ||
72 | ret = usb_control_msg(dev->udev, pipe, 0x00, | 77 | ret = usb_control_msg(dev->udev, pipe, 0x00, |
73 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | 78 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
74 | 0x00, reg, value, sizeof(u8), HZ); | 79 | 0x00, reg, buf, sizeof(u8), HZ); |
75 | if (ret < 0) { | 80 | if (ret < 0) { |
76 | stk1160_err("read failed on reg 0x%x (%d)\n", | 81 | stk1160_err("read failed on reg 0x%x (%d)\n", |
77 | reg, ret); | 82 | reg, ret); |
83 | kfree(buf); | ||
78 | return ret; | 84 | return ret; |
79 | } | 85 | } |
80 | 86 | ||
87 | *value = *buf; | ||
88 | kfree(buf); | ||
81 | return 0; | 89 | return 0; |
82 | } | 90 | } |
83 | 91 | ||
diff --git a/drivers/media/usb/stk1160/stk1160.h b/drivers/media/usb/stk1160/stk1160.h index 05b05b160e1e..abdea484c998 100644 --- a/drivers/media/usb/stk1160/stk1160.h +++ b/drivers/media/usb/stk1160/stk1160.h | |||
@@ -143,7 +143,6 @@ struct stk1160 { | |||
143 | int num_alt; | 143 | int num_alt; |
144 | 144 | ||
145 | struct stk1160_isoc_ctl isoc_ctl; | 145 | struct stk1160_isoc_ctl isoc_ctl; |
146 | char urb_buf[255]; /* urb control msg buffer */ | ||
147 | 146 | ||
148 | /* frame properties */ | 147 | /* frame properties */ |
149 | int width; /* current frame width */ | 148 | int width; /* current frame width */ |