Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] usbtv: don't do DMA on stack

As reported by smatch:
drivers/media/usb/usbtv/usbtv-video.c:716 usbtv_s_ctrl() error: doing dma on the stack (data)
drivers/media/usb/usbtv/usbtv-video.c:758 usbtv_s_ctrl() error: doing dma on the stack (data)

We should not do it, as it won't work on Kernels 4.9 and upper.
So, alloc a buffer for it.

Fixes: c53a846c48f2 ("[media] usbtv: add video controls")
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

+14 -6
+14 -6
drivers/media/usb/usbtv/usbtv-video.c
··· 704 704 { 705 705 struct usbtv *usbtv = container_of(ctrl->handler, struct usbtv, 706 706 ctrl); 707 - u8 data[3]; 707 + u8 *data; 708 708 u16 index, size; 709 709 int ret; 710 + 711 + data = kmalloc(3, GFP_KERNEL); 712 + if (!data) 713 + return -ENOMEM; 710 714 711 715 /* 712 716 * Read in the current brightness/contrast registers. We need them ··· 721 717 usb_sndctrlpipe(usbtv->udev, 0), USBTV_CONTROL_REG, 722 718 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 723 719 0, USBTV_BASE + 0x0244, (void *)data, 3, 0); 720 + if (ret < 0) 721 + goto error; 724 722 } 725 723 726 724 switch (ctrl->id) { ··· 758 752 } 759 753 break; 760 754 default: 755 + kfree(data); 761 756 return -EINVAL; 762 757 } 763 758 ··· 766 759 USBTV_CONTROL_REG, 767 760 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 768 761 0, index, (void *)data, size, 0); 769 - if (ret < 0) { 770 - dev_warn(usbtv->dev, "Failed to submit a control request.\n"); 771 - return ret; 772 - } 773 762 774 - return 0; 763 + error: 764 + if (ret < 0) 765 + dev_warn(usbtv->dev, "Failed to submit a control request.\n"); 766 + 767 + kfree(data); 768 + return ret; 775 769 } 776 770 777 771 static const struct v4l2_ctrl_ops usbtv_ctrl_ops = {