From: Patrick Boettcher <patrick.boettcher@posteo.de>
To: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Cc: "Linux Media Mailing List" <linux-media@vger.kernel.org>,
"Mauro Carvalho Chehab" <mchehab@infradead.org>,
"Andy Lutomirski" <luto@amacapital.net>,
"Johannes Stezenbach" <js@linuxtv.org>,
"Jiri Kosina" <jikos@kernel.org>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
"Andy Lutomirski" <luto@kernel.org>,
"Michael Krufky" <mkrufky@linuxtv.org>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Jörg Otte" <jrg.otte@gmail.com>, "Arnd Bergmann" <arnd@arndb.de>
Subject: Re: [PATCH 09/26] dibusb: don't do DMA on stack
Date: Mon, 10 Oct 2016 08:37:31 +0200 [thread overview]
Message-ID: <20161010083731.0efad775@posteo.de> (raw)
In-Reply-To: <801c76677194f958a58622129df3a0fcd59a5447.1475860773.git.mchehab@s-opensource.com>
On Fri, 7 Oct 2016 14:24:19 -0300
Mauro Carvalho Chehab <mchehab@s-opensource.com> wrote:
> The USB control messages require DMA to work. We cannot pass
> a stack-allocated buffer, as it is not warranted that the
> stack would be into a DMA enabled area.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
> ---
> drivers/media/usb/dvb-usb/dibusb-common.c | 106
> +++++++++++++++++++++---------
> drivers/media/usb/dvb-usb/dibusb.h | 5 ++ 2 files changed,
> 81 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c
> b/drivers/media/usb/dvb-usb/dibusb-common.c index
> 4b08c2a47ae2..76b26dc7339c 100644 ---
> a/drivers/media/usb/dvb-usb/dibusb-common.c +++
> b/drivers/media/usb/dvb-usb/dibusb-common.c @@ -12,9 +12,6 @@
> #include <linux/kconfig.h>
> #include "dibusb.h"
>
> -/* Max transfer size done by I2C transfer functions */
> -#define MAX_XFER_SIZE 64
> -
> static int debug;
> module_param(debug, int, 0644);
> MODULE_PARM_DESC(debug, "set debugging level (1=info (|-able))."
> DVB_USB_DEBUG_STATUS); @@ -63,72 +60,109 @@
> EXPORT_SYMBOL(dibusb_pid_filter_ctrl);
> int dibusb_power_ctrl(struct dvb_usb_device *d, int onoff)
> {
> - u8 b[3];
> + u8 *b;
> int ret;
> +
> + b = kmalloc(3, GFP_KERNEL);
> + if (!b)
> + return -ENOMEM;
> +
> b[0] = DIBUSB_REQ_SET_IOCTL;
> b[1] = DIBUSB_IOCTL_CMD_POWER_MODE;
> b[2] = onoff ? DIBUSB_IOCTL_POWER_WAKEUP :
> DIBUSB_IOCTL_POWER_SLEEP;
> - ret = dvb_usb_generic_write(d,b,3);
> +
> + ret = dvb_usb_generic_write(d, b, 3);
> +
> + kfree(b);
> +
> msleep(10);
> +
> return ret;
> }
> EXPORT_SYMBOL(dibusb_power_ctrl);
>
> int dibusb2_0_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
> {
> - u8 b[3] = { 0 };
> + struct dibusb_state *st = adap->priv;
> int ret;
>
> if ((ret = dibusb_streaming_ctrl(adap,onoff)) < 0)
> return ret;
>
> if (onoff) {
> - b[0] = DIBUSB_REQ_SET_STREAMING_MODE;
> - b[1] = 0x00;
> - if ((ret = dvb_usb_generic_write(adap->dev,b,2)) < 0)
> + st->data[0] = DIBUSB_REQ_SET_STREAMING_MODE;
> + st->data[1] = 0x00;
> + ret = dvb_usb_generic_write(adap->dev, st->data, 2);
> + if (ret < 0)
> return ret;
> }
>
> - b[0] = DIBUSB_REQ_SET_IOCTL;
> - b[1] = onoff ? DIBUSB_IOCTL_CMD_ENABLE_STREAM :
> DIBUSB_IOCTL_CMD_DISABLE_STREAM;
> - return dvb_usb_generic_write(adap->dev,b,3);
> + st->data[0] = DIBUSB_REQ_SET_IOCTL;
> + st->data[1] = onoff ? DIBUSB_IOCTL_CMD_ENABLE_STREAM :
> DIBUSB_IOCTL_CMD_DISABLE_STREAM;
> + return dvb_usb_generic_write(adap->dev, st->data, 3);
> }
> EXPORT_SYMBOL(dibusb2_0_streaming_ctrl);
>
> int dibusb2_0_power_ctrl(struct dvb_usb_device *d, int onoff)
> {
> - if (onoff) {
> - u8 b[3] = { DIBUSB_REQ_SET_IOCTL,
> DIBUSB_IOCTL_CMD_POWER_MODE, DIBUSB_IOCTL_POWER_WAKEUP };
> - return dvb_usb_generic_write(d,b,3);
> - } else
> + u8 *b;
> + int ret;
> +
> + if (!onoff)
> return 0;
> +
> + b = kmalloc(3, GFP_KERNEL);
> + if (!b)
> + return -ENOMEM;
> +
> + b[0] = DIBUSB_REQ_SET_IOCTL;
> + b[1] = DIBUSB_IOCTL_CMD_POWER_MODE;
> + b[2] = DIBUSB_IOCTL_POWER_WAKEUP;
> +
> + ret = dvb_usb_generic_write(d, b, 3);
> +
> + kfree(b);
> +
> + return ret;
> }
> EXPORT_SYMBOL(dibusb2_0_power_ctrl);
>
> static int dibusb_i2c_msg(struct dvb_usb_device *d, u8 addr,
> u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
> {
> - u8 sndbuf[MAX_XFER_SIZE]; /* lead(1) devaddr,direction(1)
> addr(2) data(wlen) (len(2) (when reading)) */
> + u8 *sndbuf;
> + int ret, wo, len;
> +
> /* write only ? */
> - int wo = (rbuf == NULL || rlen == 0),
> - len = 2 + wlen + (wo ? 0 : 2);
> + wo = (rbuf == NULL || rlen == 0);
>
> - if (4 + wlen > sizeof(sndbuf)) {
> + len = 2 + wlen + (wo ? 0 : 2);
> +
> + sndbuf = kmalloc(MAX_XFER_SIZE, GFP_KERNEL);
> + if (!sndbuf)
> + return -ENOMEM;
> +
> + if (4 + wlen > MAX_XFER_SIZE) {
> warn("i2c wr: len=%d is too big!\n", wlen);
> - return -EOPNOTSUPP;
> + ret = -EOPNOTSUPP;
> + goto ret;
> }
>
> sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ;
> sndbuf[1] = (addr << 1) | (wo ? 0 : 1);
>
> - memcpy(&sndbuf[2],wbuf,wlen);
> + memcpy(&sndbuf[2], wbuf, wlen);
>
> if (!wo) {
> - sndbuf[wlen+2] = (rlen >> 8) & 0xff;
> - sndbuf[wlen+3] = rlen & 0xff;
> + sndbuf[wlen + 2] = (rlen >> 8) & 0xff;
> + sndbuf[wlen + 3] = rlen & 0xff;
> }
>
> - return dvb_usb_generic_rw(d,sndbuf,len,rbuf,rlen,0);
> + ret = dvb_usb_generic_rw(d, sndbuf, len, rbuf, rlen, 0);
> +
> +ret:
> + kfree(sndbuf);
> + return ret;
> }
>
> /*
> @@ -320,11 +354,23 @@ EXPORT_SYMBOL(rc_map_dibusb_table);
>
> int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
> {
> - u8 key[5],cmd = DIBUSB_REQ_POLL_REMOTE;
> - dvb_usb_generic_rw(d,&cmd,1,key,5,0);
> - dvb_usb_nec_rc_key_to_event(d,key,event,state);
> - if (key[0] != 0)
> - deb_info("key: %*ph\n", 5, key);
> + u8 *buf;
> +
> + buf = kmalloc(5, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + buf[0] = DIBUSB_REQ_POLL_REMOTE;
> +
> + dvb_usb_generic_rw(d, buf, 1, buf, 5, 0);
> +
> + dvb_usb_nec_rc_key_to_event(d, buf, event, state);
> +
> + if (buf[0] != 0)
> + deb_info("key: %*ph\n", 5, buf);
> +
> + kfree(buf);
> +
> return 0;
> }
> EXPORT_SYMBOL(dibusb_rc_query);
> diff --git a/drivers/media/usb/dvb-usb/dibusb.h
> b/drivers/media/usb/dvb-usb/dibusb.h index 3f82163d8ab8..42e9750393e5
> 100644 --- a/drivers/media/usb/dvb-usb/dibusb.h
> +++ b/drivers/media/usb/dvb-usb/dibusb.h
> @@ -96,10 +96,15 @@
> #define DIBUSB_IOCTL_CMD_ENABLE_STREAM 0x01
> #define DIBUSB_IOCTL_CMD_DISABLE_STREAM 0x02
>
> +/* Max transfer size done by I2C transfer functions */
> +#define MAX_XFER_SIZE 64
> +
> struct dibusb_state {
> struct dib_fe_xfer_ops ops;
> int mt2060_present;
> u8 tuner_addr;
> +
> + unsigned char data[MAX_XFER_SIZE];
> };
>
> struct dibusb_device_state {
Reviewed-By: Patrick Boettcher <patrick.boettcher@posteo.de>
next prev parent reply other threads:[~2016-10-10 6:40 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-07 17:24 [PATCH 00/26] Don't use stack for DMA transers on dvb-usb drivers Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 01/26] af9005: don't do DMA on stack Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 02/26] cinergyT2-core: " Mauro Carvalho Chehab
2016-10-10 6:39 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 03/26] cinergyT2-core:: handle error code on RC query Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 04/26] cinergyT2-fe: cache stats at cinergyt2_fe_read_status() Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 05/26] cinergyT2-fe: don't do DMA on stack Mauro Carvalho Chehab
2016-10-10 6:39 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 06/26] cxusb: " Mauro Carvalho Chehab
2016-10-10 6:38 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 07/26] dib0700: be sure that dib0700_ctrl_rd() users can do DMA Mauro Carvalho Chehab
2016-10-10 6:38 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 08/26] dib0700_core: don't use stack on I2C reads Mauro Carvalho Chehab
2016-10-10 6:37 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 09/26] dibusb: don't do DMA on stack Mauro Carvalho Chehab
2016-10-10 6:37 ` Patrick Boettcher [this message]
2016-10-07 17:24 ` [PATCH 10/26] dibusb: handle error code on RC query Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 11/26] digitv: don't do DMA on stack Mauro Carvalho Chehab
2016-10-10 6:36 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 12/26] dtt200u-fe: " Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 13/26] dtt200u-fe: handle errors on USB control messages Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 14/26] dtt200u: don't do DMA on stack Mauro Carvalho Chehab
2016-10-10 6:36 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 15/26] dtt200u: handle USB control message errors Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 16/26] dtv5100: : don't do DMA on stack Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 17/26] gp8psk: " Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 18/26] gp8psk: don't go past the buffer size Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 19/26] nova-t-usb2: don't do DMA on stack Mauro Carvalho Chehab
2016-10-10 6:35 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 20/26] pctv452e: " Mauro Carvalho Chehab
2016-10-10 6:35 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 21/26] pctv452e: don't call BUG_ON() on non-fatal error Mauro Carvalho Chehab
2016-10-08 10:11 ` [PATCH v2 " Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 22/26] technisat-usb2: use DMA buffers for I2C transfers Mauro Carvalho Chehab
2016-10-10 6:34 ` Patrick Boettcher
2016-10-07 17:24 ` [PATCH 23/26] dvb-usb: warn if return value for USB read/write routines is not checked Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 24/26] nova-t-usb2: handle error code on RC query Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 25/26] dw2102: return error if su3000_power_ctrl() fails Mauro Carvalho Chehab
2016-10-07 17:24 ` [PATCH 26/26] digitv: handle error code on RC query Mauro Carvalho Chehab
2016-10-10 11:24 ` [PATCH 00/26] Don't use stack for DMA transers on dvb-usb drivers Antti Palosaari
2016-10-10 11:44 ` Michael Ira Krufky
2016-10-11 10:12 ` Mauro Carvalho Chehab
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=20161010083731.0efad775@posteo.de \
--to=patrick.boettcher@posteo.de \
--cc=arnd@arndb.de \
--cc=jikos@kernel.org \
--cc=jrg.otte@gmail.com \
--cc=js@linuxtv.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=mchehab@infradead.org \
--cc=mchehab@kernel.org \
--cc=mchehab@s-opensource.com \
--cc=mkrufky@linuxtv.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.