From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
To: Sander Eikelenboom <linux@eikelenboom.it>, linux-media@vger.kernel.org
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
Alan Stern <stern@rowland.harvard.edu>
Subject: Re: [PATCH v2] media: stk1160: Avoid stack-allocated buffer for control URBs
Date: Fri, 25 Apr 2014 18:51:53 -0300 [thread overview]
Message-ID: <20140425215153.GA1695@arch.cereza> (raw)
In-Reply-To: <1397737700-1081-1-git-send-email-ezequiel.garcia@free-electrons.com>
On Apr 17, Ezequiel Garcia wrote:
> 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>
Ouch, I forgot to Cc Sander!
Sander, Here's the patch:
https://patchwork.linuxtv.org/patch/23660/
Maybe you can give it a ride and confirm it fixes the warning over there?
Also, have you observed any serious issues caused by this or just the
DMA API debug warning?
> Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> ---
> drivers/media/usb/stk1160/stk1160-core.c | 10 +++++++++-
> 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 34a26e0..03504dc 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)
> {
> 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;
> }
>
> diff --git a/drivers/media/usb/stk1160/stk1160.h b/drivers/media/usb/stk1160/stk1160.h
> index 05b05b1..abdea48 100644
> --- a/drivers/media/usb/stk1160/stk1160.h
> +++ b/drivers/media/usb/stk1160/stk1160.h
> @@ -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 */
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
next prev parent reply other threads:[~2014-04-25 21:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-17 12:28 [PATCH v2] media: stk1160: Avoid stack-allocated buffer for control URBs Ezequiel Garcia
2014-04-25 21:51 ` Ezequiel Garcia [this message]
2014-04-28 16:42 ` Sander Eikelenboom
2014-05-09 10:34 ` Hans Verkuil
2014-05-09 13:07 ` Ezequiel Garcia
2014-05-17 12:21 ` Ezequiel Garcia
2014-05-23 10:38 ` Hans Verkuil
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=20140425215153.GA1695@arch.cereza \
--to=ezequiel.garcia@free-electrons.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=linux@eikelenboom.it \
--cc=stern@rowland.harvard.edu \
/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