linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lubomir Rintel <lkundrak@v3.sk>
To: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Cc: "Linux Media Mailing List" <linux-media@vger.kernel.org>,
	"Mauro Carvalho Chehab" <mchehab@infradead.org>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Hans Verkuil" <hans.verkuil@cisco.com>,
	"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
	"Federico Simoncelli" <fsimonce@redhat.com>,
	"Junghak Sung" <jh1009.sung@samsung.com>,
	"Nikola Forró" <nikola.forro@gmail.com>,
	"Insu Yun" <wuninsu@gmail.com>
Subject: Re: [PATCH] [media] usbtv: don't do DMA on stack
Date: Wed, 16 Nov 2016 17:11:11 +0100	[thread overview]
Message-ID: <1479312671.14443.3.camel@v3.sk> (raw)
In-Reply-To: <9c5e1833f754f55e9ccc05549a90c5fa439ce63e.1479309351.git.mchehab@s-opensource.com>

On Wed, 2016-11-16 at 13:15 -0200, Mauro Carvalho Chehab wrote:
> 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>
> ---
>  drivers/media/usb/usbtv/usbtv-video.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/usb/usbtv/usbtv-video.c
> b/drivers/media/usb/usbtv/usbtv-video.c
> index 86ffbf8780f2..d3b6d3dfaa09 100644
> --- a/drivers/media/usb/usbtv/usbtv-video.c
> +++ b/drivers/media/usb/usbtv/usbtv-video.c
> @@ -704,10 +704,14 @@ static int usbtv_s_ctrl(struct v4l2_ctrl *ctrl)
>  {
>  	struct usbtv *usbtv = container_of(ctrl->handler, struct
> usbtv,
>  								ctrl
> );
> -	u8 data[3];
> +	u8 *data;
>  	u16 index, size;
>  	int ret;
>  
> +	data = kmalloc(3, GFP_KERNEL);
> +	if (!data)
> +		return -ENOMEM;
> +
>  	/*
>  	 * Read in the current brightness/contrast registers. We
> need them
>  	 * both, because the values are for some reason interleaved.
> @@ -717,6 +721,8 @@ static int usbtv_s_ctrl(struct v4l2_ctrl *ctrl)
>  			usb_sndctrlpipe(usbtv->udev, 0),
> USBTV_CONTROL_REG,
>  			USB_DIR_OUT | USB_TYPE_VENDOR |
> USB_RECIP_DEVICE,
>  			0, USBTV_BASE + 0x0244, (void *)data, 3, 0);
> +		if (ret < 0)
> +			goto error;
>  	}
>  
>  	switch (ctrl->id) {
> @@ -752,6 +758,7 @@ static int usbtv_s_ctrl(struct v4l2_ctrl *ctrl)
>  		}
>  		break;
>  	default:
> +		kfree(data);
>  		return -EINVAL;
>  	}
>  
> @@ -759,12 +766,13 @@ static int usbtv_s_ctrl(struct v4l2_ctrl *ctrl)
>  			USBTV_CONTROL_REG,
>  			USB_DIR_OUT | USB_TYPE_VENDOR |
> USB_RECIP_DEVICE,
>  			0, index, (void *)data, size, 0);
> -	if (ret < 0) {
> +
> +error:
> +	if (ret < 0)
>  		dev_warn(usbtv->dev, "Failed to submit a control
> request.\n");
> -		return ret;
> -	}
>  
> -	return 0;
> +	kfree(data);
> +	return ret;
>  }
>  
>  static const struct v4l2_ctrl_ops usbtv_ctrl_ops = {

Reviewed-by: Lubomir Rintel <lkundrak@v3.sk>

Thank you,
Lubo

      reply	other threads:[~2016-11-16 16:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-16 15:15 [PATCH] [media] usbtv: don't do DMA on stack Mauro Carvalho Chehab
2016-11-16 16:11 ` Lubomir Rintel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479312671.14443.3.camel@v3.sk \
    --to=lkundrak@v3.sk \
    --cc=fsimonce@redhat.com \
    --cc=hans.verkuil@cisco.com \
    --cc=jh1009.sung@samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=mchehab@kernel.org \
    --cc=mchehab@s-opensource.com \
    --cc=nikola.forro@gmail.com \
    --cc=wuninsu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).