Skip to content

Commit 5d0f2df

Browse files
committed
[media] technisat-usb2: don't do DMA on the stack
As warned by smatch: drivers/media/usb/dvb-usb/technisat-usb2.c:263 technisat_usb2_set_led() error: doing dma on the stack (led) drivers/media/usb/dvb-usb/technisat-usb2.c:280 technisat_usb2_set_led_timer() error: doing dma on the stack (&b) drivers/media/usb/dvb-usb/technisat-usb2.c:341 technisat_usb2_identify_state() error: doing dma on the stack (version) drivers/media/usb/dvb-usb/technisat-usb2.c:609 technisat_usb2_get_ir() error: doing dma on the stack (buf) drivers/media/usb/dvb-usb/technisat-usb2.c:619 technisat_usb2_get_ir() error: doing dma on the stack (buf) Create a buffer at the device state and use it for all the DMA transfers. Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 57bcbde commit 5d0f2df

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

drivers/media/usb/dvb-usb/technisat-usb2.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ struct technisat_usb2_state {
6060
u8 power_state;
6161

6262
u16 last_scan_code;
63+
64+
u8 buf[64];
6365
};
6466

6567
/* debug print helpers */
@@ -220,19 +222,19 @@ enum technisat_usb2_led_state {
220222
TECH_LED_UNDEFINED
221223
};
222224

223-
static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum technisat_usb2_led_state state)
225+
static int technisat_usb2_set_led(struct dvb_usb_device *d, int red,
226+
enum technisat_usb2_led_state st)
224227
{
228+
struct technisat_usb2_state *state = d->priv;
229+
u8 *led = state->buf;
225230
int ret;
226231

227-
u8 led[8] = {
228-
red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
229-
0
230-
};
232+
led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
231233

232-
if (disable_led_control && state != TECH_LED_OFF)
234+
if (disable_led_control && st != TECH_LED_OFF)
233235
return 0;
234236

235-
switch (state) {
237+
switch (st) {
236238
case TECH_LED_ON:
237239
led[1] = 0x82;
238240
break;
@@ -263,16 +265,19 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
263265
red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
264266
USB_TYPE_VENDOR | USB_DIR_OUT,
265267
0, 0,
266-
led, sizeof(led), 500);
268+
led, 8, 500);
267269

268270
mutex_unlock(&d->i2c_mutex);
269271
return ret;
270272
}
271273

272274
static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
273275
{
276+
struct technisat_usb2_state *state = d->priv;
277+
u8 *b = state->buf;
274278
int ret;
275-
u8 b = 0;
279+
280+
b[0] = 0;
276281

277282
if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
278283
return -EAGAIN;
@@ -281,7 +286,7 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
281286
SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
282287
USB_TYPE_VENDOR | USB_DIR_OUT,
283288
(red << 8) | green, 0,
284-
&b, 1, 500);
289+
b, 1, 500);
285290

286291
mutex_unlock(&d->i2c_mutex);
287292

@@ -328,7 +333,11 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
328333
struct dvb_usb_device_description **desc, int *cold)
329334
{
330335
int ret;
331-
u8 version[3];
336+
u8 *version;
337+
338+
version = kmalloc(3, GFP_KERNEL);
339+
if (!version)
340+
return -ENOMEM;
332341

333342
/* first select the interface */
334343
if (usb_set_interface(udev, 0, 1) != 0)
@@ -342,7 +351,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
342351
GET_VERSION_INFO_VENDOR_REQUEST,
343352
USB_TYPE_VENDOR | USB_DIR_IN,
344353
0, 0,
345-
version, sizeof(version), 500);
354+
version, 3, 500);
346355

347356
if (ret < 0)
348357
*cold = 1;
@@ -351,6 +360,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
351360
*cold = 0;
352361
}
353362

363+
kfree(version);
364+
354365
return 0;
355366
}
356367

@@ -594,7 +605,9 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
594605

595606
static int technisat_usb2_get_ir(struct dvb_usb_device *d)
596607
{
597-
u8 buf[62], *b;
608+
struct technisat_usb2_state *state = d->priv;
609+
u8 *buf = state->buf;
610+
u8 *b;
598611
int ret;
599612
struct ir_raw_event ev;
600613

@@ -620,7 +633,7 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
620633
GET_IR_DATA_VENDOR_REQUEST,
621634
USB_TYPE_VENDOR | USB_DIR_IN,
622635
0x8080, 0,
623-
buf, sizeof(buf), 500);
636+
buf, 62, 500);
624637

625638
unlock:
626639
mutex_unlock(&d->i2c_mutex);

0 commit comments

Comments
 (0)