[git:media_tree/fixes] [media] cinergyT2-core: handle error code on RC query

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cinergyT2-core: handle error code on RC query
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:54:33 2016 -0300

There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/cinergyT2-core.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c 
b/drivers/media/usb/dvb-usb/cinergyT2-core.c
index d85c0c4d4042..8ac825413d5a 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
@@ -102,7 +102,7 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter 
*adap)
/* Copy this pointer as we are gonna need it in the release phase */
cinergyt2_usb_device = adap->dev;
 
-   return 0;
+   return ret;
 }
 
 static struct rc_map_table rc_map_cinergyt2_table[] = {
@@ -162,14 +162,16 @@ static int repeatable_keys[] = {
 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
struct cinergyt2_state *st = d->priv;
-   int i;
+   int i, ret;
 
*state = REMOTE_NO_KEY_PRESSED;
 
mutex_lock(>data_mutex);
st->data[0] = CINERGYT2_EP1_GET_RC_EVENTS;
 
-   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   if (ret < 0)
+   goto ret;
 
if (st->data[4] == 0xff) {
/* key repeat */

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] nova-t-usb2: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] nova-t-usb2: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 11:38:46 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/nova-t-usb2.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/nova-t-usb2.c 
b/drivers/media/usb/dvb-usb/nova-t-usb2.c
index fc7569e2728d..26d7188a1163 100644
--- a/drivers/media/usb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/usb/dvb-usb/nova-t-usb2.c
@@ -74,22 +74,29 @@ static struct rc_map_table rc_map_haupp_table[] = {
  */
 static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
-   u8 key[5],cmd[2] = { DIBUSB_REQ_POLL_REMOTE, 0x35 }, data,toggle,custom;
+   u8 *buf, data, toggle, custom;
u16 raw;
int i;
struct dibusb_device_state *st = d->priv;
 
-   dvb_usb_generic_rw(d,cmd,2,key,5,0);
+   buf = kmalloc(5, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   buf[0] = DIBUSB_REQ_POLL_REMOTE;
+   buf[1] = 0x35;
+   dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
 
*state = REMOTE_NO_KEY_PRESSED;
-   switch (key[0]) {
+   switch (buf[0]) {
case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
-   raw = ((key[1] << 8) | key[2]) >> 3;
+   raw = ((buf[1] << 8) | buf[2]) >> 3;
toggle = !!(raw & 0x800);
data = raw & 0x3f;
custom = (raw >> 6) & 0x1f;
 
-   deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x 
d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
+   deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x 
d: %02x toggle: %d\n",
+  buf[1], buf[2], buf[3], custom, data, toggle);
 
for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) {
if (rc5_data(_map_haupp_table[i]) == data &&
@@ -117,6 +124,7 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
break;
}
 
+   kfree(buf);
return 0;
 }
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] pctv452e: don't call BUG_ON() on non-fatal error

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] pctv452e: don't call BUG_ON() on non-fatal error
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 14:15:53 2016 -0300

There are some conditions on this driver that are tested with
BUG_ON() with are not serious enough to hang a machine.

So, just return an error if this happens.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/pctv452e.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/pctv452e.c 
b/drivers/media/usb/dvb-usb/pctv452e.c
index 58b685094904..7ad0006c5ae0 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -109,9 +109,10 @@ static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, 
u8 *data,
unsigned int rlen;
int ret;
 
-   BUG_ON(NULL == data && 0 != (write_len | read_len));
-   BUG_ON(write_len > 64 - 4);
-   BUG_ON(read_len > 64 - 4);
+   if (!data || (write_len > 64 - 4) || (read_len > 64 - 4)) {
+   err("%s: transfer data invalid", __func__);
+   return -EIO;
+   };
 
mutex_lock(>ca_mutex);
id = state->c++;

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] af9005: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] af9005: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Wed Oct 5 06:46:49 2016 -0300

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 

 drivers/media/usb/dvb-usb/af9005.c | 319 +
 1 file changed, 181 insertions(+), 138 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/af9005.c 
b/drivers/media/usb/dvb-usb/af9005.c
index efa782ed6e2d..b257780fb380 100644
--- a/drivers/media/usb/dvb-usb/af9005.c
+++ b/drivers/media/usb/dvb-usb/af9005.c
@@ -52,17 +52,16 @@ u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 
0xff };
 struct af9005_device_state {
u8 sequence;
int led_state;
+   unsigned char data[256];
+   struct mutex data_mutex;
 };
 
 static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
  int readwrite, int type, u8 * values, int len)
 {
struct af9005_device_state *st = d->priv;
-   u8 obuf[16] = { 0 };
-   u8 ibuf[17] = { 0 };
-   u8 command;
-   int i;
-   int ret;
+   u8 command, seq;
+   int i, ret;
 
if (len < 1) {
err("generic read/write, less than 1 byte. Makes no sense.");
@@ -73,16 +72,17 @@ static int af9005_generic_read_write(struct dvb_usb_device 
*d, u16 reg,
return -EINVAL;
}
 
-   obuf[0] = 14;   /* rest of buffer length low */
-   obuf[1] = 0;/* rest of buffer length high */
+   mutex_lock(>data_mutex);
+   st->data[0] = 14;   /* rest of buffer length low */
+   st->data[1] = 0;/* rest of buffer length high */
 
-   obuf[2] = AF9005_REGISTER_RW;   /* register operation */
-   obuf[3] = 12;   /* rest of buffer length */
+   st->data[2] = AF9005_REGISTER_RW;   /* register operation */
+   st->data[3] = 12;   /* rest of buffer length */
 
-   obuf[4] = st->sequence++;   /* sequence number */
+   st->data[4] = seq = st->sequence++; /* sequence number */
 
-   obuf[5] = (u8) (reg >> 8);  /* register address */
-   obuf[6] = (u8) (reg & 0xff);
+   st->data[5] = (u8) (reg >> 8);  /* register address */
+   st->data[6] = (u8) (reg & 0xff);
 
if (type == AF9005_OFDM_REG) {
command = AF9005_CMD_OFDM_REG;
@@ -96,51 +96,52 @@ static int af9005_generic_read_write(struct dvb_usb_device 
*d, u16 reg,
command |= readwrite;
if (readwrite == AF9005_CMD_WRITE)
for (i = 0; i < len; i++)
-   obuf[8 + i] = values[i];
+   st->data[8 + i] = values[i];
else if (type == AF9005_TUNER_REG)
/* read command for tuner, the first byte contains the i2c 
address */
-   obuf[8] = values[0];
-   obuf[7] = command;
+   st->data[8] = values[0];
+   st->data[7] = command;
 
-   ret = dvb_usb_generic_rw(d, obuf, 16, ibuf, 17, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 16, st->data, 17, 0);
if (ret)
-   return ret;
+   goto ret;
 
/* sanity check */
-   if (ibuf[2] != AF9005_REGISTER_RW_ACK) {
+   if (st->data[2] != AF9005_REGISTER_RW_ACK) {
err("generic read/write, wrong reply code.");
-   return -EIO;
+   ret = -EIO;
+   goto ret;
}
-   if (ibuf[3] != 0x0d) {
+   if (st->data[3] != 0x0d) {
err("generic read/write, wrong length in reply.");
-   return -EIO;
+   ret = -EIO;
+   goto ret;
}
-   if (ibuf[4] != obuf[4]) {
+   if (st->data[4] != seq) {
err("generic read/write, wrong sequence in reply.");
-   return -EIO;
+   ret = -EIO;
+   goto ret;
}
/*
-  Windows driver doesn't check these fields, in fact sometimes
-  the register in the reply is different that what has been sent
-
-  if (ibuf[5] != obuf[5] || ibuf[6] != obuf[6]) {
-  err("generic read/write, wrong register in reply.");
-  return -EIO;
-  }
-  if (ibuf[7] != command) {
-  err("generic read/write wrong command in reply.");
-  return -EIO;
-  }
+* In thesis, both input and output buffers should have
+* identical values for st->data[5] to st->data[8].
+* However, windows driver doesn't check these fields, in fact
+* sometimes the register in the reply is different that what
+* has been sent
 */
-   if (ibuf[16] != 0x01) {
+   if (st->data[16] != 0x01) {
 

[git:media_tree/fixes] [media] flexcop-usb: don't use stack for DMA

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] flexcop-usb: don't use stack for DMA
Author:  Mauro Carvalho Chehab 
Date:Mon Oct 10 07:55:54 2016 -0300

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.

While here, remove a dead function calling usb_control_msg().

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/b2c2/flexcop-usb.c | 105 +++
 drivers/media/usb/b2c2/flexcop-usb.h |   4 ++
 2 files changed, 72 insertions(+), 37 deletions(-)

---

diff --git a/drivers/media/usb/b2c2/flexcop-usb.c 
b/drivers/media/usb/b2c2/flexcop-usb.c
index d4bdba60b0f7..52bc42da8a4c 100644
--- a/drivers/media/usb/b2c2/flexcop-usb.c
+++ b/drivers/media/usb/b2c2/flexcop-usb.c
@@ -73,23 +73,34 @@ static int flexcop_usb_readwrite_dw(struct flexcop_device 
*fc, u16 wRegOffsPCI,
u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR;
u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) |
(read ? 0x80 : 0);
+   int ret;
+
+   mutex_lock(_usb->data_mutex);
+   if (!read)
+   memcpy(fc_usb->data, val, sizeof(*val));
 
-   int len = usb_control_msg(fc_usb->udev,
+   ret = usb_control_msg(fc_usb->udev,
read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT,
request,
request_type, /* 0xc0 read or 0x40 write */
wAddress,
0,
-   val,
+   fc_usb->data,
sizeof(u32),
B2C2_WAIT_FOR_OPERATION_RDW * HZ);
 
-   if (len != sizeof(u32)) {
+   if (ret != sizeof(u32)) {
err("error while %s dword from %d (%d).", read ? "reading" :
"writing", wAddress, wRegOffsPCI);
-   return -EIO;
+   if (ret >= 0)
+   ret = -EIO;
}
-   return 0;
+
+   if (read && ret >= 0)
+   memcpy(val, fc_usb->data, sizeof(*val));
+   mutex_unlock(_usb->data_mutex);
+
+   return ret;
 }
 /*
  * DKT 010817 - add support for V8 memory read/write and flash update
@@ -100,9 +111,14 @@ static int flexcop_usb_v8_memory_req(struct flexcop_usb 
*fc_usb,
 {
u8 request_type = USB_TYPE_VENDOR;
u16 wIndex;
-   int nWaitTime, pipe, len;
+   int nWaitTime, pipe, ret;
wIndex = page << 8;
 
+   if (buflen > sizeof(fc_usb->data)) {
+   err("Buffer size bigger than max URB control message\n");
+   return -EIO;
+   }
+
switch (req) {
case B2C2_USB_READ_V8_MEM:
nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ;
@@ -127,17 +143,32 @@ static int flexcop_usb_v8_memory_req(struct flexcop_usb 
*fc_usb,
deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n", request_type, req,
wAddress, wIndex, buflen);
 
-   len = usb_control_msg(fc_usb->udev, pipe,
+   mutex_lock(_usb->data_mutex);
+
+   if ((request_type & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT)
+   memcpy(fc_usb->data, pbBuffer, buflen);
+
+   ret = usb_control_msg(fc_usb->udev, pipe,
req,
request_type,
wAddress,
wIndex,
-   pbBuffer,
+   fc_usb->data,
buflen,
nWaitTime * HZ);
+   if (ret != buflen)
+   ret = -EIO;
+
+   if (ret >= 0) {
+   ret = 0;
+   if ((request_type & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
+   memcpy(pbBuffer, fc_usb->data, buflen);
+   }
 
-   debug_dump(pbBuffer, len, deb_v8);
-   return len == buflen ? 0 : -EIO;
+   mutex_unlock(_usb->data_mutex);
+
+   debug_dump(pbBuffer, ret, deb_v8);
+   return ret;
 }
 
 #define bytes_left_to_read_on_page(paddr,buflen) \
@@ -196,29 +227,6 @@ static int flexcop_usb_get_mac_addr(struct flexcop_device 
*fc, int extended)
fc->dvb_adapter.proposed_mac, 6);
 }
 
-#if 0
-static int flexcop_usb_utility_req(struct flexcop_usb *fc_usb, int set,
-   flexcop_usb_utility_function_t func, u8 extra, u16 wIndex,
-   u16 buflen, u8 *pvBuffer)
-{
-   u16 wValue;
-   u8 request_type = (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR;
-   int nWaitTime = 2,
-   pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN, len;
-   wValue = (func << 8) | extra;
-
-   len = usb_control_msg(fc_usb->udev,pipe,
-   B2C2_USB_UTILITY,
-   request_type,
-   wValue,
-   

[git:media_tree/fixes] [media] dtt200u-fe: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtt200u-fe: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 08:06:57 2016 -0300

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 

 drivers/media/usb/dvb-usb/dtt200u-fe.c | 95 +++---
 1 file changed, 65 insertions(+), 30 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c 
b/drivers/media/usb/dvb-usb/dtt200u-fe.c
index 9bb15f7b48db..7f7f64be6353 100644
--- a/drivers/media/usb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c
@@ -18,17 +18,22 @@ struct dtt200u_fe_state {
 
struct dtv_frontend_properties fep;
struct dvb_frontend frontend;
+
+   unsigned char data[80];
+   struct mutex data_mutex;
 };
 
 static int dtt200u_fe_read_status(struct dvb_frontend *fe,
  enum fe_status *stat)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 st = GET_TUNE_STATUS, b[3];
 
-   dvb_usb_generic_rw(state->d,,1,b,3,0);
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_TUNE_STATUS;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
 
-   switch (b[0]) {
+   switch (state->data[0]) {
case 0x01:
*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER |
FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
@@ -41,51 +46,75 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
*stat = 0;
break;
}
+   mutex_unlock(>data_mutex);
return 0;
 }
 
 static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_VIT_ERR_CNT,b[3];
-   dvb_usb_generic_rw(state->d,,1,b,3,0);
-   *ber = (b[0] << 16) | (b[1] << 8) | b[2];
+
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_VIT_ERR_CNT;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   *ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2];
+
+   mutex_unlock(>data_mutex);
return 0;
 }
 
 static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_RS_UNCOR_BLK_CNT,b[2];
 
-   dvb_usb_generic_rw(state->d,,1,b,2,0);
-   *unc = (b[0] << 8) | b[1];
-   return 0;
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_RS_UNCOR_BLK_CNT;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
+
+   mutex_unlock(>data_mutex);
+   return ret;
 }
 
 static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 
*strength)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_AGC, b;
-   dvb_usb_generic_rw(state->d,,1,,1,0);
-   *strength = (b << 8) | b;
-   return 0;
+
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_AGC;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+
+   mutex_unlock(>data_mutex);
+   return ret;
 }
 
 static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_SNR,br;
-   dvb_usb_generic_rw(state->d,,1,,1,0);
-   *snr = ~((br << 8) | br);
-   return 0;
+
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_SNR;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+
+   mutex_unlock(>data_mutex);
+   return ret;
 }
 
 static int dtt200u_fe_init(struct dvb_frontend* fe)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 b = SET_INIT;
-   return dvb_usb_generic_write(state->d,,1);
+   int ret;
+
+   mutex_lock(>data_mutex);
+   state->data[0] = SET_INIT;
+
+   ret = dvb_usb_generic_write(state->d, state->data, 1);
+   mutex_unlock(>data_mutex);
+
+   return ret;
 }
 
 static int dtt200u_fe_sleep(struct dvb_frontend* fe)
@@ -106,29 +135,34 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend 
*fe)
struct dtv_frontend_properties *fep = >dtv_property_cache;
struct dtt200u_fe_state *state = fe->demodulator_priv;
u16 freq = fep->frequency / 25;
-   u8 bwbuf[2] = { SET_BANDWIDTH, 0 },freqbuf[3] = { SET_RF_FREQ, 0, 0 };
 
+   mutex_lock(>data_mutex);
+   state->data[0] = SET_BANDWIDTH;
switch (fep->bandwidth_hz) {
case 800:
-   bwbuf[1] = 8;
+   state->data[1] = 8;
break;
case 700:
-   bwbuf[1] = 7;
+   

[git:media_tree/fixes] [media] cinergyT2-fe: cache stats at cinergyt2_fe_read_status()

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cinergyT2-fe: cache stats at cinergyt2_fe_read_status()
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 06:07:36 2016 -0300

Instead of sending USB commands for every stats call, collect
them once, when status is updated. As the frontend kthread
will call it on every few seconds, the stats will still be
collected.

Besides reducing the amount of USB/I2C transfers, this also
warrants that all stats will be collected at the same time,
and makes easier to convert it to DVBv5 stats in the future.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/cinergyT2-fe.c | 48 +---
 1 file changed, 7 insertions(+), 41 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c 
b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
index b3ec743a7a2e..fd8edcb56e61 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
@@ -139,6 +139,7 @@ static uint16_t compute_tps(struct dtv_frontend_properties 
*op)
 struct cinergyt2_fe_state {
struct dvb_frontend fe;
struct dvb_usb_device *d;
+   struct dvbt_get_status_msg status;
 };
 
 static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
@@ -154,6 +155,8 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
if (ret < 0)
return ret;
 
+   state->status = result;
+
*status = 0;
 
if (0x - le16_to_cpu(result.gain) > 30)
@@ -177,34 +180,16 @@ static int cinergyt2_fe_read_status(struct dvb_frontend 
*fe,
 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
-
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *),
-   sizeof(status), 0);
-   if (ret < 0)
-   return ret;
 
-   *ber = le32_to_cpu(status.viterbi_error_rate);
+   *ber = le32_to_cpu(state->status.viterbi_error_rate);
return 0;
 }
 
 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *),
-   sizeof(status), 0);
-   if (ret < 0) {
-   err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
-   ret);
-   return ret;
-   }
-   *unc = le32_to_cpu(status.uncorrected_block_count);
+   *unc = le32_to_cpu(state->status.uncorrected_block_count);
return 0;
 }
 
@@ -212,35 +197,16 @@ static int cinergyt2_fe_read_signal_strength(struct 
dvb_frontend *fe,
u16 *strength)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *),
-   sizeof(status), 0);
-   if (ret < 0) {
-   err("cinergyt2_fe_read_signal_strength() Failed!"
-   " (Error=%d)\n", ret);
-   return ret;
-   }
-   *strength = (0x - le16_to_cpu(status.gain));
+   *strength = (0x - le16_to_cpu(state->status.gain));
return 0;
 }
 
 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *),
-   sizeof(status), 0);
-   if (ret < 0) {
-   err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
-   return ret;
-   }
-   *snr = (status.snr << 8) | status.snr;
+   *snr = (state->status.snr << 8) | state->status.snr;
return 0;
 }
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] dtt200u-fe: don't keep waiting for lock at set_frontend()

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtt200u-fe: don't keep waiting for lock at set_frontend()
Author:  Mauro Carvalho Chehab 
Date:Mon Oct 10 15:34:13 2016 -0300

It is up to the frontend kthread to wait for lock.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dtt200u-fe.c | 9 -
 1 file changed, 9 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c 
b/drivers/media/usb/dvb-usb/dtt200u-fe.c
index c09332bd99cb..9bb15f7b48db 100644
--- a/drivers/media/usb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c
@@ -105,8 +105,6 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend *fe)
 {
struct dtv_frontend_properties *fep = >dtv_property_cache;
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   int i;
-   enum fe_status st;
u16 freq = fep->frequency / 25;
u8 bwbuf[2] = { SET_BANDWIDTH, 0 },freqbuf[3] = { SET_RF_FREQ, 0, 0 };
 
@@ -130,13 +128,6 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend *fe)
freqbuf[2] = (freq >> 8) & 0xff;
dvb_usb_generic_write(state->d,freqbuf,3);
 
-   for (i = 0; i < 30; i++) {
-   msleep(20);
-   dtt200u_fe_read_status(fe, );
-   if (st & FE_TIMEDOUT)
-   continue;
-   }
-
return 0;
 }
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] stk-webcam: don't use stack for DMA

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] stk-webcam: don't use stack for DMA
Author:  Mauro Carvalho Chehab 
Date:Mon Oct 10 11:17:15 2016 -0300

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 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/stkwebcam/stk-webcam.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

---

diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c 
b/drivers/media/usb/stkwebcam/stk-webcam.c
index db200c9d796d..22a9aae16291 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -147,20 +147,26 @@ int stk_camera_write_reg(struct stk_camera *dev, u16 
index, u8 value)
 int stk_camera_read_reg(struct stk_camera *dev, u16 index, int *value)
 {
struct usb_device *udev = dev->udev;
+   unsigned char *buf;
int ret;
 
+   buf = kmalloc(sizeof(u8), GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
0x00,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0x00,
index,
-   (u8 *) value,
+   buf,
sizeof(u8),
500);
-   if (ret < 0)
-   return ret;
-   else
-   return 0;
+   if (ret >= 0)
+   memcpy(value, buf, sizeof(u8));
+
+   kfree(buf);
+   return ret;
 }
 
 static int stk_start_stream(struct stk_camera *dev)

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] cinergyT2-core: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cinergyT2-core: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Wed Oct 5 06:02:19 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/cinergyT2-core.c | 84 ++
 1 file changed, 61 insertions(+), 23 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c 
b/drivers/media/usb/dvb-usb/cinergyT2-core.c
index 9fd1527494eb..d85c0c4d4042 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
@@ -41,6 +41,8 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 struct cinergyt2_state {
u8 rc_counter;
+   unsigned char data[64];
+   struct mutex data_mutex;
 };
 
 /* We are missing a release hook with usb_device data */
@@ -50,33 +52,52 @@ static struct dvb_usb_device_properties 
cinergyt2_properties;
 
 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
 {
-   char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
-   char result[64];
-   return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
-   sizeof(result), 0);
+   struct dvb_usb_device *d = adap->dev;
+   struct cinergyt2_state *st = d->priv;
+   int ret;
+
+   mutex_lock(>data_mutex);
+   st->data[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
+   st->data[1] = enable ? 1 : 0;
+
+   ret = dvb_usb_generic_rw(d, st->data, 2, st->data, 64, 0);
+   mutex_unlock(>data_mutex);
+
+   return ret;
 }
 
 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
 {
-   char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
-   char state[3];
-   return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
+   struct cinergyt2_state *st = d->priv;
+   int ret;
+
+   mutex_lock(>data_mutex);
+   st->data[0] = CINERGYT2_EP1_SLEEP_MODE;
+   st->data[1] = enable ? 0 : 1;
+
+   ret = dvb_usb_generic_rw(d, st->data, 2, st->data, 3, 0);
+   mutex_unlock(>data_mutex);
+
+   return ret;
 }
 
 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
 {
-   char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
-   char state[3];
+   struct dvb_usb_device *d = adap->dev;
+   struct cinergyt2_state *st = d->priv;
int ret;
 
adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
 
-   ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
-   sizeof(state), 0);
+   mutex_lock(>data_mutex);
+   st->data[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
+
+   ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 3, 0);
if (ret < 0) {
deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
"state info\n");
}
+   mutex_unlock(>data_mutex);
 
/* Copy this pointer as we are gonna need it in the release phase */
cinergyt2_usb_device = adap->dev;
@@ -141,13 +162,16 @@ static int repeatable_keys[] = {
 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
struct cinergyt2_state *st = d->priv;
-   u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
int i;
 
*state = REMOTE_NO_KEY_PRESSED;
 
-   dvb_usb_generic_rw(d, , 1, key, sizeof(key), 0);
-   if (key[4] == 0xff) {
+   mutex_lock(>data_mutex);
+   st->data[0] = CINERGYT2_EP1_GET_RC_EVENTS;
+
+   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+
+   if (st->data[4] == 0xff) {
/* key repeat */
st->rc_counter++;
if (st->rc_counter > RC_REPEAT_DELAY) {
@@ -157,31 +181,45 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, 
u32 *event, int *state)
*event = d->last_event;
deb_rc("repeat key, event %x\n",
   *event);
-   return 0;
+   goto ret;
}
}
deb_rc("repeated key (non repeatable)\n");
}
-   return 0;
+   goto ret;
}
 
/* hack to pass checksum on the custom field */
-   key[2] = ~key[1];
-   dvb_usb_nec_rc_key_to_event(d, key, event, state);
-   if (key[0] != 0) {
+   st->data[2] = ~st->data[1];
+   dvb_usb_nec_rc_key_to_event(d, st->data, event, state);
+   if 

[git:media_tree/fixes] [media] digitv: handle error code on RC query

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] digitv: handle error code on RC query
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:52:31 2016 -0300

There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/digitv.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/digitv.c 
b/drivers/media/usb/dvb-usb/digitv.c
index 09f8c28bd4db..4284f6984dc1 100644
--- a/drivers/media/usb/dvb-usb/digitv.c
+++ b/drivers/media/usb/dvb-usb/digitv.c
@@ -29,7 +29,9 @@ static int digitv_ctrl_msg(struct dvb_usb_device *d,
u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
struct digitv_state *st = d->priv;
-   int wo = (rbuf == NULL || rlen == 0); /* write-only */
+   int ret, wo;
+
+   wo = (rbuf == NULL || rlen == 0); /* write-only */
 
memset(st->sndbuf, 0, 7);
memset(st->rcvbuf, 0, 7);
@@ -40,12 +42,12 @@ static int digitv_ctrl_msg(struct dvb_usb_device *d,
 
if (wo) {
memcpy(>sndbuf[3], wbuf, wlen);
-   dvb_usb_generic_write(d, st->sndbuf, 7);
+   ret = dvb_usb_generic_write(d, st->sndbuf, 7);
} else {
-   dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
+   ret = dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
memcpy(rbuf, >rcvbuf[3], rlen);
}
-   return 0;
+   return ret;
 }
 
 /* I2C */

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] digitv: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] digitv: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 07:55:38 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/digitv.c | 20 +++-
 drivers/media/usb/dvb-usb/digitv.h |  5 -
 2 files changed, 15 insertions(+), 10 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/digitv.c 
b/drivers/media/usb/dvb-usb/digitv.c
index 63134335c994..09f8c28bd4db 100644
--- a/drivers/media/usb/dvb-usb/digitv.c
+++ b/drivers/media/usb/dvb-usb/digitv.c
@@ -28,20 +28,22 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 static int digitv_ctrl_msg(struct dvb_usb_device *d,
u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
+   struct digitv_state *st = d->priv;
int wo = (rbuf == NULL || rlen == 0); /* write-only */
-   u8 sndbuf[7],rcvbuf[7];
-   memset(sndbuf,0,7); memset(rcvbuf,0,7);
 
-   sndbuf[0] = cmd;
-   sndbuf[1] = vv;
-   sndbuf[2] = wo ? wlen : rlen;
+   memset(st->sndbuf, 0, 7);
+   memset(st->rcvbuf, 0, 7);
+
+   st->sndbuf[0] = cmd;
+   st->sndbuf[1] = vv;
+   st->sndbuf[2] = wo ? wlen : rlen;
 
if (wo) {
-   memcpy([3],wbuf,wlen);
-   dvb_usb_generic_write(d,sndbuf,7);
+   memcpy(>sndbuf[3], wbuf, wlen);
+   dvb_usb_generic_write(d, st->sndbuf, 7);
} else {
-   dvb_usb_generic_rw(d,sndbuf,7,rcvbuf,7,10);
-   memcpy(rbuf,[3],rlen);
+   dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
+   memcpy(rbuf, >rcvbuf[3], rlen);
}
return 0;
 }
diff --git a/drivers/media/usb/dvb-usb/digitv.h 
b/drivers/media/usb/dvb-usb/digitv.h
index 908c09f4966b..581e09c25491 100644
--- a/drivers/media/usb/dvb-usb/digitv.h
+++ b/drivers/media/usb/dvb-usb/digitv.h
@@ -5,7 +5,10 @@
 #include "dvb-usb.h"
 
 struct digitv_state {
-int is_nxt6000;
+   int is_nxt6000;
+
+   unsigned char sndbuf[7];
+   unsigned char rcvbuf[7];
 };
 
 /* protocol (from usblogging and the SDK:

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] cpia2_usb: don't use stack for DMA

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cpia2_usb: don't use stack for DMA
Author:  Mauro Carvalho Chehab 
Date:Mon Oct 10 08:28:26 2016 -0300

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 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/cpia2/cpia2_usb.c | 34 ++
 1 file changed, 30 insertions(+), 4 deletions(-)

---

diff --git a/drivers/media/usb/cpia2/cpia2_usb.c 
b/drivers/media/usb/cpia2/cpia2_usb.c
index 13620cdf0599..e9100a235831 100644
--- a/drivers/media/usb/cpia2/cpia2_usb.c
+++ b/drivers/media/usb/cpia2/cpia2_usb.c
@@ -545,18 +545,30 @@ static void free_sbufs(struct camera_data *cam)
 static int write_packet(struct usb_device *udev,
u8 request, u8 * registers, u16 start, size_t size)
 {
+   unsigned char *buf;
+   int ret;
+
if (!registers || size <= 0)
return -EINVAL;
 
-   return usb_control_msg(udev,
+   buf = kmalloc(size, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   memcpy(buf, registers, size);
+
+   ret = usb_control_msg(udev,
   usb_sndctrlpipe(udev, 0),
   request,
   USB_TYPE_VENDOR | USB_RECIP_DEVICE,
   start,   /* value */
   0,   /* index */
-  registers,   /* buffer */
+  buf, /* buffer */
   size,
   HZ);
+
+   kfree(buf);
+   return ret;
 }
 
 /
@@ -567,18 +579,32 @@ static int write_packet(struct usb_device *udev,
 static int read_packet(struct usb_device *udev,
   u8 request, u8 * registers, u16 start, size_t size)
 {
+   unsigned char *buf;
+   int ret;
+
if (!registers || size <= 0)
return -EINVAL;
 
-   return usb_control_msg(udev,
+   buf = kmalloc(size, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   ret = usb_control_msg(udev,
   usb_rcvctrlpipe(udev, 0),
   request,
   USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_DEVICE,
   start,   /* value */
   0,   /* index */
-  registers,   /* buffer */
+  buf, /* buffer */
   size,
   HZ);
+
+   if (ret >= 0)
+   memcpy(registers, buf, size);
+
+   kfree(buf);
+
+   return ret;
 }
 
 /**

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] nova-t-usb2: handle error code on RC query

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] nova-t-usb2: handle error code on RC query
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:50:21 2016 -0300

There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/nova-t-usb2.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/nova-t-usb2.c 
b/drivers/media/usb/dvb-usb/nova-t-usb2.c
index 26d7188a1163..1babd3341910 100644
--- a/drivers/media/usb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/usb/dvb-usb/nova-t-usb2.c
@@ -76,7 +76,7 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
 {
u8 *buf, data, toggle, custom;
u16 raw;
-   int i;
+   int i, ret;
struct dibusb_device_state *st = d->priv;
 
buf = kmalloc(5, GFP_KERNEL);
@@ -85,7 +85,9 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
 
buf[0] = DIBUSB_REQ_POLL_REMOTE;
buf[1] = 0x35;
-   dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
+   ret = dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
+   if (ret < 0)
+   goto ret;
 
*state = REMOTE_NO_KEY_PRESSED;
switch (buf[0]) {
@@ -124,8 +126,9 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
break;
}
 
+ret:
kfree(buf);
-   return 0;
+   return ret;
 }
 
 static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] dib0700: be sure that dib0700_ctrl_rd() users can do DMA

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dib0700: be sure that dib0700_ctrl_rd() users can do DMA
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 06:40:24 2016 -0300

dib0700_ctrl_rd() takes a RX and a TX pointer. Be sure that
both will point to a memory allocated via kmalloc().

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dib0700_core.c|  4 +++-
 drivers/media/usb/dvb-usb/dib0700_devices.c | 25 +
 2 files changed, 16 insertions(+), 13 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dib0700_core.c 
b/drivers/media/usb/dvb-usb/dib0700_core.c
index f3196658fb70..515f89dba199 100644
--- a/drivers/media/usb/dvb-usb/dib0700_core.c
+++ b/drivers/media/usb/dvb-usb/dib0700_core.c
@@ -292,13 +292,15 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter 
*adap,
 
/* special thing in the current firmware: when length 
is zero the read-failed */
len = dib0700_ctrl_rd(d, st->buf, msg[i].len + 2,
-   msg[i+1].buf, msg[i+1].len);
+ st->buf, msg[i + 1].len);
if (len <= 0) {
deb_info("I2C read failed on address 0x%02x\n",
msg[i].addr);
break;
}
 
+   memcpy(msg[i + 1].buf, st->buf, msg[i + 1].len);
+
msg[i+1].len = len;
 
i++;
diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c 
b/drivers/media/usb/dvb-usb/dib0700_devices.c
index 0857b56e652c..ef1b8ee75c57 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -508,8 +508,6 @@ static int stk7700ph_tuner_attach(struct dvb_usb_adapter 
*adap)
 
 #define DEFAULT_RC_INTERVAL 50
 
-static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
-
 /*
  * This function is used only when firmware is < 1.20 version. Newer
  * firmwares use bulk mode, with functions implemented at dib0700_core,
@@ -517,7 +515,6 @@ static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
  */
 static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
 {
-   u8 key[4];
enum rc_type protocol;
u32 scancode;
u8 toggle;
@@ -532,39 +529,43 @@ static int dib0700_rc_query_old_firmware(struct 
dvb_usb_device *d)
return 0;
}
 
-   i = dib0700_ctrl_rd(d, rc_request, 2, key, 4);
+   st->buf[0] = REQUEST_POLL_RC;
+   st->buf[1] = 0;
+
+   i = dib0700_ctrl_rd(d, st->buf, 2, st->buf, 4);
if (i <= 0) {
err("RC Query Failed");
-   return -1;
+   return -EIO;
}
 
/* losing half of KEY_0 events from Philipps rc5 remotes.. */
-   if (key[0] == 0 && key[1] == 0 && key[2] == 0 && key[3] == 0)
+   if (st->buf[0] == 0 && st->buf[1] == 0
+   && st->buf[2] == 0 && st->buf[3] == 0)
return 0;
 
-   /* info("%d: %2X %2X %2X 
%2X",dvb_usb_dib0700_ir_proto,(int)key[3-2],(int)key[3-3],(int)key[3-1],(int)key[3]);
  */
+   /* info("%d: %2X %2X %2X %2X",dvb_usb_dib0700_ir_proto,(int)st->buf[3 - 
2],(int)st->buf[3 - 3],(int)st->buf[3 - 1],(int)st->buf[3]);  */
 
dib0700_rc_setup(d, NULL); /* reset ir sensor data to prevent false 
events */
 
switch (d->props.rc.core.protocol) {
case RC_BIT_NEC:
/* NEC protocol sends repeat code as 0 0 0 FF */
-   if ((key[3-2] == 0x00) && (key[3-3] == 0x00) &&
-   (key[3] == 0xff)) {
+   if ((st->buf[3 - 2] == 0x00) && (st->buf[3 - 3] == 0x00) &&
+   (st->buf[3] == 0xff)) {
rc_repeat(d->rc_dev);
return 0;
}
 
protocol = RC_TYPE_NEC;
-   scancode = RC_SCANCODE_NEC(key[3-2], key[3-3]);
+   scancode = RC_SCANCODE_NEC(st->buf[3 - 2], st->buf[3 - 3]);
toggle = 0;
break;
 
default:
/* RC-5 protocol changes toggle bit on new keypress */
protocol = RC_TYPE_RC5;
-   scancode = RC_SCANCODE_RC5(key[3-2], key[3-3]);
-   toggle = key[3-1];
+   scancode = RC_SCANCODE_RC5(st->buf[3 - 2], st->buf[3 - 3]);
+   toggle = st->buf[3 - 1];
break;
}
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] gp8psk: don't go past the buffer size

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] gp8psk: don't go past the buffer size
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 14:12:48 2016 -0300

Add checks to avoid going out of the buffer.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/gp8psk.c | 11 +++
 1 file changed, 11 insertions(+)

---

diff --git a/drivers/media/usb/dvb-usb/gp8psk.c 
b/drivers/media/usb/dvb-usb/gp8psk.c
index 807f5628a3bb..adfd76491451 100644
--- a/drivers/media/usb/dvb-usb/gp8psk.c
+++ b/drivers/media/usb/dvb-usb/gp8psk.c
@@ -60,6 +60,9 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 
value, u16 index, u8
struct gp8psk_state *st = d->priv;
int ret = 0,try = 0;
 
+   if (blen > sizeof(st->data))
+   return -EIO;
+
if ((ret = mutex_lock_interruptible(>usb_mutex)))
return ret;
 
@@ -98,6 +101,9 @@ int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 
value,
deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
debug_dump(b,blen,deb_xfer);
 
+   if (blen > sizeof(st->data))
+   return -EIO;
+
if ((ret = mutex_lock_interruptible(>usb_mutex)))
return ret;
 
@@ -151,6 +157,11 @@ static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
err("failed to load bcm4500 firmware.");
goto out_free;
}
+   if (buflen > 64) {
+   err("firmare chunk size bigger than 64 bytes.");
+   goto out_free;
+   }
+
memcpy(buf, ptr, buflen);
if (dvb_usb_generic_write(d, buf, buflen)) {
err("failed to load bcm4500 firmware.");

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] dibusb: handle error code on RC query

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dibusb: handle error code on RC query
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:40:48 2016 -0300

There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dibusb-common.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c 
b/drivers/media/usb/dvb-usb/dibusb-common.c
index 951f3dac9082..b0fd9a609352 100644
--- a/drivers/media/usb/dvb-usb/dibusb-common.c
+++ b/drivers/media/usb/dvb-usb/dibusb-common.c
@@ -366,6 +366,7 @@ EXPORT_SYMBOL(rc_map_dibusb_table);
 int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
u8 *buf;
+   int ret;
 
buf = kmalloc(5, GFP_KERNEL);
if (!buf)
@@ -373,7 +374,9 @@ int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, 
int *state)
 
buf[0] = DIBUSB_REQ_POLL_REMOTE;
 
-   dvb_usb_generic_rw(d, buf, 1, buf, 5, 0);
+   ret = dvb_usb_generic_rw(d, buf, 1, buf, 5, 0);
+   if (ret < 0)
+   goto ret;
 
dvb_usb_nec_rc_key_to_event(d, buf, event, state);
 
@@ -382,6 +385,7 @@ int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, 
int *state)
 
kfree(buf);
 
-   return 0;
+ret:
+   return ret;
 }
 EXPORT_SYMBOL(dibusb_rc_query);

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] dib0700_core: don't use stack on I2C reads

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dib0700_core: don't use stack on I2C reads
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 06:53:51 2016 -0300

Be sure that I2C reads won't use stack by passing
a pointer to the state buffer, that we know it was
allocated via kmalloc, instead of relying on the buffer
allocated by an I2C client.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dib0700_core.c | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

---

diff --git a/drivers/media/usb/dvb-usb/dib0700_core.c 
b/drivers/media/usb/dvb-usb/dib0700_core.c
index 515f89dba199..92d5408684ac 100644
--- a/drivers/media/usb/dvb-usb/dib0700_core.c
+++ b/drivers/media/usb/dvb-usb/dib0700_core.c
@@ -213,7 +213,7 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, 
struct i2c_msg *msg,
 usb_rcvctrlpipe(d->udev, 0),
 REQUEST_NEW_I2C_READ,
 USB_TYPE_VENDOR | USB_DIR_IN,
-value, index, msg[i].buf,
+value, index, st->buf,
 msg[i].len,
 USB_CTRL_GET_TIMEOUT);
if (result < 0) {
@@ -221,6 +221,14 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, 
struct i2c_msg *msg,
break;
}
 
+   if (msg[i].len > sizeof(st->buf)) {
+   deb_info("buffer too small to fit %d bytes\n",
+msg[i].len);
+   return -EIO;
+   }
+
+   memcpy(msg[i].buf, st->buf, msg[i].len);
+
deb_data("<<< ");
debug_dump(msg[i].buf, msg[i].len, deb_data);
 
@@ -238,6 +246,13 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, 
struct i2c_msg *msg,
/* I2C ctrl + FE bus; */
st->buf[3] = ((gen_mode << 6) & 0xC0) |
 ((bus_mode << 4) & 0x30);
+
+   if (msg[i].len > sizeof(st->buf) - 4) {
+   deb_info("i2c message to big: %d\n",
+msg[i].len);
+   return -EIO;
+   }
+
/* The Actual i2c payload */
memcpy(>buf[4], msg[i].buf, msg[i].len);
 
@@ -283,6 +298,11 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter 
*adap,
/* fill in the address */
st->buf[1] = msg[i].addr << 1;
/* fill the buffer */
+   if (msg[i].len > sizeof(st->buf) - 2) {
+   deb_info("i2c xfer to big: %d\n",
+   msg[i].len);
+   return -EIO;
+   }
memcpy(>buf[2], msg[i].buf, msg[i].len);
 
/* write/read request */
@@ -299,6 +319,11 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter 
*adap,
break;
}
 
+   if (msg[i + 1].len > sizeof(st->buf)) {
+   deb_info("i2c xfer buffer to small for %d\n",
+   msg[i].len);
+   return -EIO;
+   }
memcpy(msg[i + 1].buf, st->buf, msg[i + 1].len);
 
msg[i+1].len = len;

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] technisat-usb2: use DMA buffers for I2C transfers

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] technisat-usb2: use DMA buffers for I2C transfers
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 12:04:38 2016 -0300

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.

On this driver, most of the transfers are OK, but the I2C
one was using stack.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/technisat-usb2.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c 
b/drivers/media/usb/dvb-usb/technisat-usb2.c
index d9f3262bf071..4706628a3ed5 100644
--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
@@ -89,9 +89,13 @@ struct technisat_usb2_state {
 static int technisat_usb2_i2c_access(struct usb_device *udev,
u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
 {
-   u8 b[64];
+   u8 *b;
int ret, actual_length;
 
+   b = kmalloc(64, GFP_KERNEL);
+   if (!b)
+   return -ENOMEM;
+
deb_i2c("i2c-access: %02x, tx: ", device_addr);
debug_dump(tx, txlen, deb_i2c);
deb_i2c(" ");
@@ -123,7 +127,7 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
 
if (ret < 0) {
err("i2c-error: out failed %02x = %d", device_addr, ret);
-   return -ENODEV;
+   goto err;
}
 
ret = usb_bulk_msg(udev,
@@ -131,7 +135,7 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
b, 64, _length, 1000);
if (ret < 0) {
err("i2c-error: in failed %02x = %d", device_addr, ret);
-   return -ENODEV;
+   goto err;
}
 
if (b[0] != I2C_STATUS_OK) {
@@ -140,7 +144,7 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
if (!(b[0] == I2C_STATUS_NAK &&
device_addr == 0x60
/* && device_is_technisat_usb2 */))
-   return -ENODEV;
+   goto err;
}
 
deb_i2c("status: %d, ", b[0]);
@@ -154,7 +158,9 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
 
deb_i2c("\n");
 
-   return 0;
+err:
+   kfree(b);
+   return ret;
 }
 
 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg 
*msg,

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] cxusb: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cxusb: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 06:30:27 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/cxusb.c | 62 ++-
 drivers/media/usb/dvb-usb/cxusb.h |  6 
 2 files changed, 41 insertions(+), 27 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index 907ac01ae297..39772812269d 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -45,9 +45,6 @@
 #include "si2168.h"
 #include "si2157.h"
 
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE  80
-
 /* debug */
 static int dvb_usb_cxusb_debug;
 module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
@@ -61,23 +58,27 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 static int cxusb_ctrl_msg(struct dvb_usb_device *d,
  u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
-   int wo = (rbuf == NULL || rlen == 0); /* write-only */
-   u8 sndbuf[MAX_XFER_SIZE];
+   struct cxusb_state *st = d->priv;
+   int ret, wo;
 
-   if (1 + wlen > sizeof(sndbuf)) {
-   warn("i2c wr: len=%d is too big!\n",
-wlen);
+   if (1 + wlen > MAX_XFER_SIZE) {
+   warn("i2c wr: len=%d is too big!\n", wlen);
return -EOPNOTSUPP;
}
 
-   memset(sndbuf, 0, 1+wlen);
+   wo = (rbuf == NULL || rlen == 0); /* write-only */
 
-   sndbuf[0] = cmd;
-   memcpy([1], wbuf, wlen);
+   mutex_lock(>data_mutex);
+   st->data[0] = cmd;
+   memcpy(>data[1], wbuf, wlen);
if (wo)
-   return dvb_usb_generic_write(d, sndbuf, 1+wlen);
+   ret = dvb_usb_generic_write(d, st->data, 1 + wlen);
else
-   return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 1 + wlen,
+rbuf, rlen, 0);
+
+   mutex_unlock(>data_mutex);
+   return ret;
 }
 
 /* GPIO */
@@ -1460,36 +1461,43 @@ static struct dvb_usb_device_properties 
cxusb_mygica_t230_properties;
 static int cxusb_probe(struct usb_interface *intf,
   const struct usb_device_id *id)
 {
+   struct dvb_usb_device *d;
+   struct cxusb_state *st;
+
if (0 == dvb_usb_device_init(intf, _medion_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_lgh064f_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_dee1601_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_lgz201_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_dtt7579_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_dualdig4_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_nano2_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf,
_bluebird_nano2_needsfirmware_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _aver_a868r_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf,
 _bluebird_dualdig4_rev2_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _d680_dmb_properties,
-   

[git:media_tree/fixes] [media] dtt200u-fe: handle errors on USB control messages

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtt200u-fe: handle errors on USB control messages
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:44:09 2016 -0300

If something goes wrong, return an error code, instead of
assuming that everything went fine.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dtt200u-fe.c | 40 ++
 1 file changed, 31 insertions(+), 9 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c 
b/drivers/media/usb/dvb-usb/dtt200u-fe.c
index 7f7f64be6353..f5c042baa254 100644
--- a/drivers/media/usb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c
@@ -27,11 +27,17 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
  enum fe_status *stat)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_TUNE_STATUS;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   if (ret < 0) {
+   *stat = 0;
+   mutex_unlock(>data_mutex);
+   return ret;
+   }
 
switch (state->data[0]) {
case 0x01:
@@ -53,25 +59,30 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
 static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_VIT_ERR_CNT;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
-   *ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2];
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   if (ret >= 0)
+   *ber = (state->data[0] << 16) | (state->data[1] << 8) | 
state->data[2];
 
mutex_unlock(>data_mutex);
-   return 0;
+   return ret;
 }
 
 static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_RS_UNCOR_BLK_CNT;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
+   if (ret >= 0)
+   *unc = (state->data[0] << 8) | state->data[1];
 
mutex_unlock(>data_mutex);
return ret;
@@ -80,11 +91,14 @@ static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* 
fe, u32 *unc)
 static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 
*strength)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_AGC;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   if (ret >= 0)
+   *strength = (state->data[0] << 8) | state->data[0];
 
mutex_unlock(>data_mutex);
return ret;
@@ -93,11 +107,14 @@ static int dtt200u_fe_read_signal_strength(struct 
dvb_frontend* fe, u16 *strengt
 static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_SNR;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   if (ret >= 0)
+   *snr = ~((state->data[0] << 8) | state->data[0]);
 
mutex_unlock(>data_mutex);
return ret;
@@ -134,6 +151,7 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend *fe)
 {
struct dtv_frontend_properties *fep = >dtv_property_cache;
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
u16 freq = fep->frequency / 25;
 
mutex_lock(>data_mutex);
@@ -153,12 +171,16 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend 
*fe)
goto ret;
}
 
-   dvb_usb_generic_write(state->d, state->data, 2);
+   ret = dvb_usb_generic_write(state->d, state->data, 2);
+   if (ret < 0)
+   goto ret;
 
state->data[0] = SET_RF_FREQ;
state->data[1] = freq & 0xff;
state->data[2] = (freq >> 8) & 0xff;
-   dvb_usb_generic_write(state->d, state->data, 3);
+   ret = dvb_usb_generic_write(state->d, state->data, 3);
+   if (ret < 0)
+   goto ret;
 
 ret:
mutex_unlock(>data_mutex);

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org

[git:media_tree/fixes] [media] dw2102: return error if su3000_power_ctrl() fails

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dw2102: return error if su3000_power_ctrl() fails
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:55:53 2016 -0300

Instead of silently ignoring the error, return it.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dw2102.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

---

diff --git a/drivers/media/usb/dvb-usb/dw2102.c 
b/drivers/media/usb/dvb-usb/dw2102.c
index 5fb0c650926e..2c720cb2fb00 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -852,7 +852,7 @@ static int su3000_power_ctrl(struct dvb_usb_device *d, int 
i)
if (i && !state->initialized) {
state->initialized = 1;
/* reset board */
-   dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
+   return dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
}
 
return 0;

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] cinergyT2-fe: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cinergyT2-fe: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 06:16:59 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/cinergyT2-fe.c | 56 +++-
 1 file changed, 33 insertions(+), 23 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c 
b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
index fd8edcb56e61..2d29b4174dba 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
@@ -139,6 +139,10 @@ static uint16_t compute_tps(struct dtv_frontend_properties 
*op)
 struct cinergyt2_fe_state {
struct dvb_frontend fe;
struct dvb_usb_device *d;
+
+   unsigned char data[64];
+   struct mutex data_mutex;
+
struct dvbt_get_status_msg status;
 };
 
@@ -146,28 +150,31 @@ static int cinergyt2_fe_read_status(struct dvb_frontend 
*fe,
enum fe_status *status)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg result;
-   u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *),
-   sizeof(result), 0);
+   mutex_lock(>data_mutex);
+   state->data[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
+
+   ret = dvb_usb_generic_rw(state->d, state->data, 1,
+state->data, sizeof(state->status), 0);
+   if (!ret)
+   memcpy(>status, state->data, sizeof(state->status));
+   mutex_unlock(>data_mutex);
+
if (ret < 0)
return ret;
 
-   state->status = result;
-
*status = 0;
 
-   if (0x - le16_to_cpu(result.gain) > 30)
+   if (0x - le16_to_cpu(state->status.gain) > 30)
*status |= FE_HAS_SIGNAL;
-   if (result.lock_bits & (1 << 6))
+   if (state->status.lock_bits & (1 << 6))
*status |= FE_HAS_LOCK;
-   if (result.lock_bits & (1 << 5))
+   if (state->status.lock_bits & (1 << 5))
*status |= FE_HAS_SYNC;
-   if (result.lock_bits & (1 << 4))
+   if (state->status.lock_bits & (1 << 4))
*status |= FE_HAS_CARRIER;
-   if (result.lock_bits & (1 << 1))
+   if (state->status.lock_bits & (1 << 1))
*status |= FE_HAS_VITERBI;
 
if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
@@ -232,34 +239,36 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend 
*fe)
 {
struct dtv_frontend_properties *fep = >dtv_property_cache;
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_set_parameters_msg param;
-   char result[2];
+   struct dvbt_set_parameters_msg *param;
int err;
 
-   param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
-   param.tps = cpu_to_le16(compute_tps(fep));
-   param.freq = cpu_to_le32(fep->frequency / 1000);
-   param.flags = 0;
+   mutex_lock(>data_mutex);
+
+   param = (void *)state->data;
+   param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
+   param->tps = cpu_to_le16(compute_tps(fep));
+   param->freq = cpu_to_le32(fep->frequency / 1000);
+   param->flags = 0;
 
switch (fep->bandwidth_hz) {
default:
case 800:
-   param.bandwidth = 8;
+   param->bandwidth = 8;
break;
case 700:
-   param.bandwidth = 7;
+   param->bandwidth = 7;
break;
case 600:
-   param.bandwidth = 6;
+   param->bandwidth = 6;
break;
}
 
-   err = dvb_usb_generic_rw(state->d,
-   (char *), sizeof(param),
-   result, sizeof(result), 0);
+   err = dvb_usb_generic_rw(state->d, state->data, sizeof(*param),
+state->data, 2, 0);
if (err < 0)
err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
 
+   mutex_unlock(>data_mutex);
return (err < 0) ? err : 0;
 }
 
@@ -281,6 +290,7 @@ struct dvb_frontend *cinergyt2_fe_attach(struct 
dvb_usb_device *d)
s->d = d;
memcpy(>fe.ops, _fe_ops, sizeof(struct dvb_frontend_ops));
s->fe.demodulator_priv = s;
+   mutex_init(>data_mutex);
return >fe;
 }
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] pctv452e: fix semicolon.cocci warnings

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] pctv452e: fix semicolon.cocci warnings
Author:  kbuild test robot 
Date:Tue Oct 11 10:22:08 2016 -0300

drivers/media/usb/dvb-usb/pctv452e.c:115:2-3: Unneeded semicolon

 Remove unneeded semicolon.

Generated by: scripts/coccinelle/misc/semicolon.cocci

Signed-off-by: Fengguang Wu 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/pctv452e.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

---

diff --git a/drivers/media/usb/dvb-usb/pctv452e.c 
b/drivers/media/usb/dvb-usb/pctv452e.c
index 7ad0006c5ae0..07fa08be9e99 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -112,7 +112,7 @@ static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, 
u8 *data,
if (!data || (write_len > 64 - 4) || (read_len > 64 - 4)) {
err("%s: transfer data invalid", __func__);
return -EIO;
-   };
+   }
 
mutex_lock(>ca_mutex);
id = state->c++;

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] gp8psk: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] gp8psk: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 11:24:21 2016 -0300

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 

 drivers/media/usb/dvb-usb/gp8psk.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/gp8psk.c 
b/drivers/media/usb/dvb-usb/gp8psk.c
index 5d0384dd45b5..807f5628a3bb 100644
--- a/drivers/media/usb/dvb-usb/gp8psk.c
+++ b/drivers/media/usb/dvb-usb/gp8psk.c
@@ -24,6 +24,10 @@ MODULE_PARM_DESC(debug, "set debugging level 
(1=info,xfer=2,rc=4 (or-able))." DV
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
+struct gp8psk_state {
+   unsigned char data[80];
+};
+
 static int gp8psk_get_fw_version(struct dvb_usb_device *d, u8 *fw_vers)
 {
return (gp8psk_usb_in_op(d, GET_FW_VERS, 0, 0, fw_vers, 6));
@@ -53,17 +57,19 @@ static void gp8psk_info(struct dvb_usb_device *d)
 
 int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, 
u8 *b, int blen)
 {
+   struct gp8psk_state *st = d->priv;
int ret = 0,try = 0;
 
if ((ret = mutex_lock_interruptible(>usb_mutex)))
return ret;
 
while (ret >= 0 && ret != blen && try < 3) {
+   memcpy(st->data, b, blen);
ret = usb_control_msg(d->udev,
usb_rcvctrlpipe(d->udev,0),
req,
USB_TYPE_VENDOR | USB_DIR_IN,
-   value,index,b,blen,
+   value, index, st->data, blen,
2000);
deb_info("reading number %d (ret: %d)\n",try,ret);
try++;
@@ -86,6 +92,7 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 
value, u16 index, u8
 int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
 u16 index, u8 *b, int blen)
 {
+   struct gp8psk_state *st = d->priv;
int ret;
 
deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
@@ -94,11 +101,12 @@ int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, 
u16 value,
if ((ret = mutex_lock_interruptible(>usb_mutex)))
return ret;
 
+   memcpy(st->data, b, blen);
if (usb_control_msg(d->udev,
usb_sndctrlpipe(d->udev,0),
req,
USB_TYPE_VENDOR | USB_DIR_OUT,
-   value,index,b,blen,
+   value, index, st->data, blen,
2000) != blen) {
warn("usb out operation failed.");
ret = -EIO;
@@ -265,6 +273,8 @@ static struct dvb_usb_device_properties gp8psk_properties = 
{
.usb_ctrl = CYPRESS_FX2,
.firmware = "dvb-usb-gp8psk-01.fw",
 
+   .size_of_priv = sizeof(struct gp8psk_state),
+
.num_adapters = 1,
.adapter = {
{

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] pctv452e: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] pctv452e: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 11:59:44 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/pctv452e.c | 129 ---
 1 file changed, 74 insertions(+), 55 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/pctv452e.c 
b/drivers/media/usb/dvb-usb/pctv452e.c
index c05de1b088a4..58b685094904 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -97,13 +97,14 @@ struct pctv452e_state {
u8 c;  /* transaction counter, wraps around...  */
u8 initialized; /* set to 1 if 0x15 has been sent */
u16 last_rc_key;
+
+   unsigned char data[80];
 };
 
 static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data,
 unsigned int write_len, unsigned int read_len)
 {
struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
-   u8 buf[64];
u8 id;
unsigned int rlen;
int ret;
@@ -112,33 +113,36 @@ static int tt3650_ci_msg(struct dvb_usb_device *d, u8 
cmd, u8 *data,
BUG_ON(write_len > 64 - 4);
BUG_ON(read_len > 64 - 4);
 
+   mutex_lock(>ca_mutex);
id = state->c++;
 
-   buf[0] = SYNC_BYTE_OUT;
-   buf[1] = id;
-   buf[2] = cmd;
-   buf[3] = write_len;
+   state->data[0] = SYNC_BYTE_OUT;
+   state->data[1] = id;
+   state->data[2] = cmd;
+   state->data[3] = write_len;
 
-   memcpy(buf + 4, data, write_len);
+   memcpy(state->data + 4, data, write_len);
 
rlen = (read_len > 0) ? 64 : 0;
-   ret = dvb_usb_generic_rw(d, buf, 4 + write_len,
- buf, rlen, /* delay_ms */ 0);
+   ret = dvb_usb_generic_rw(d, state->data, 4 + write_len,
+ state->data, rlen, /* delay_ms */ 0);
if (0 != ret)
goto failed;
 
ret = -EIO;
-   if (SYNC_BYTE_IN != buf[0] || id != buf[1])
+   if (SYNC_BYTE_IN != state->data[0] || id != state->data[1])
goto failed;
 
-   memcpy(data, buf + 4, read_len);
+   memcpy(data, state->data + 4, read_len);
 
+   mutex_unlock(>ca_mutex);
return 0;
 
 failed:
err("CI error %d; %02X %02X %02X -> %*ph.",
-ret, SYNC_BYTE_OUT, id, cmd, 3, buf);
+ret, SYNC_BYTE_OUT, id, cmd, 3, state->data);
 
+   mutex_unlock(>ca_mutex);
return ret;
 }
 
@@ -405,52 +409,53 @@ static int pctv452e_i2c_msg(struct dvb_usb_device *d, u8 
addr,
u8 *rcv_buf, u8 rcv_len)
 {
struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
-   u8 buf[64];
u8 id;
int ret;
 
+   mutex_lock(>ca_mutex);
id = state->c++;
 
ret = -EINVAL;
if (snd_len > 64 - 7 || rcv_len > 64 - 7)
goto failed;
 
-   buf[0] = SYNC_BYTE_OUT;
-   buf[1] = id;
-   buf[2] = PCTV_CMD_I2C;
-   buf[3] = snd_len + 3;
-   buf[4] = addr << 1;
-   buf[5] = snd_len;
-   buf[6] = rcv_len;
+   state->data[0] = SYNC_BYTE_OUT;
+   state->data[1] = id;
+   state->data[2] = PCTV_CMD_I2C;
+   state->data[3] = snd_len + 3;
+   state->data[4] = addr << 1;
+   state->data[5] = snd_len;
+   state->data[6] = rcv_len;
 
-   memcpy(buf + 7, snd_buf, snd_len);
+   memcpy(state->data + 7, snd_buf, snd_len);
 
-   ret = dvb_usb_generic_rw(d, buf, 7 + snd_len,
- buf, /* rcv_len */ 64,
+   ret = dvb_usb_generic_rw(d, state->data, 7 + snd_len,
+ state->data, /* rcv_len */ 64,
  /* delay_ms */ 0);
if (ret < 0)
goto failed;
 
/* TT USB protocol error. */
ret = -EIO;
-   if (SYNC_BYTE_IN != buf[0] || id != buf[1])
+   if (SYNC_BYTE_IN != state->data[0] || id != state->data[1])
goto failed;
 
/* I2C device didn't respond as expected. */
ret = -EREMOTEIO;
-   if (buf[5] < snd_len || buf[6] < rcv_len)
+   if (state->data[5] < snd_len || state->data[6] < rcv_len)
goto failed;
 
-   memcpy(rcv_buf, buf + 7, rcv_len);
+   memcpy(rcv_buf, state->data + 7, rcv_len);
+   mutex_unlock(>ca_mutex);
 
return rcv_len;
 
 failed:
-   err("I2C error %d; %02X %02X  %02X %02X %02X -> "
-"%02X %02X  %02X %02X %02X.",
+   err("I2C error %d; %02X %02X  %02X %02X %02X -> %*ph",
 ret, SYNC_BYTE_OUT, id, addr << 1, 

[git:media_tree/fixes] [media] dtt200u: handle USB control message errors

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtt200u: handle USB control message errors
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:37:50 2016 -0300

If something bad happens while an USB control message is
transfered, return an error code.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dtt200u.c | 26 ++
 1 file changed, 18 insertions(+), 8 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtt200u.c 
b/drivers/media/usb/dvb-usb/dtt200u.c
index 7706938b5167..f88572c7ae7c 100644
--- a/drivers/media/usb/dvb-usb/dtt200u.c
+++ b/drivers/media/usb/dvb-usb/dtt200u.c
@@ -28,37 +28,42 @@ struct dtt200u_state {
 static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff)
 {
struct dtt200u_state *st = d->priv;
+   int ret = 0;
 
mutex_lock(>data_mutex);
 
st->data[0] = SET_INIT;
 
if (onoff)
-   dvb_usb_generic_write(d, st->data, 2);
+   ret = dvb_usb_generic_write(d, st->data, 2);
 
mutex_unlock(>data_mutex);
-   return 0;
+   return ret;
 }
 
 static int dtt200u_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
struct dtt200u_state *st = adap->dev->priv;
+   int ret;
 
mutex_lock(>data_mutex);
st->data[0] = SET_STREAMING;
st->data[1] = onoff;
 
-   dvb_usb_generic_write(adap->dev, st->data, 2);
+   ret = dvb_usb_generic_write(adap->dev, st->data, 2);
+   if (ret < 0)
+   goto ret;
 
if (onoff)
-   return 0;
+   goto ret;
 
st->data[0] = RESET_PID_FILTER;
-   dvb_usb_generic_write(adap->dev, st->data, 1);
+   ret = dvb_usb_generic_write(adap->dev, st->data, 1);
 
+ret:
mutex_unlock(>data_mutex);
 
-   return 0;
+   return ret;
 }
 
 static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 
pid, int onoff)
@@ -84,11 +89,15 @@ static int dtt200u_rc_query(struct dvb_usb_device *d)
 {
struct dtt200u_state *st = d->priv;
u32 scancode;
+   int ret;
 
mutex_lock(>data_mutex);
st->data[0] = GET_RC_CODE;
 
-   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   if (ret < 0)
+   goto ret;
+
if (st->data[0] == 1) {
enum rc_type proto = RC_TYPE_NEC;
 
@@ -116,8 +125,9 @@ static int dtt200u_rc_query(struct dvb_usb_device *d)
if (st->data[0] != 0)
deb_info("st->data: %*ph\n", 5, st->data);
 
+ret:
mutex_unlock(>data_mutex);
-   return 0;
+   return ret;
 }
 
 static int dtt200u_frontend_attach(struct dvb_usb_adapter *adap)

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/fixes] [media] dtv5100: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtv5100: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 08:51:23 2016 -0300

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 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dtv5100.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtv5100.c 
b/drivers/media/usb/dvb-usb/dtv5100.c
index 3d11df41cac0..c60fb54f445f 100644
--- a/drivers/media/usb/dvb-usb/dtv5100.c
+++ b/drivers/media/usb/dvb-usb/dtv5100.c
@@ -31,9 +31,14 @@ module_param_named(debug, dvb_usb_dtv5100_debug, int, 0644);
 MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
+struct dtv5100_state {
+   unsigned char data[80];
+};
+
 static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
   u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
 {
+   struct dtv5100_state *st = d->priv;
u8 request;
u8 type;
u16 value;
@@ -60,9 +65,10 @@ static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
}
index = (addr << 8) + wbuf[0];
 
+   memcpy(st->data, rbuf, rlen);
msleep(1); /* avoid I2C errors */
return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), request,
-  type, value, index, rbuf, rlen,
+  type, value, index, st->data, rlen,
   DTV5100_USB_TIMEOUT);
 }
 
@@ -176,7 +182,7 @@ static struct dvb_usb_device_properties dtv5100_properties 
= {
.caps = DVB_USB_IS_AN_I2C_ADAPTER,
.usb_ctrl = DEVICE_SPECIFIC,
 
-   .size_of_priv = 0,
+   .size_of_priv = sizeof(struct dtv5100_state),
 
.num_adapters = 1,
.adapter = {{

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] pctv452e: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] pctv452e: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 11:59:44 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/pctv452e.c | 129 ---
 1 file changed, 74 insertions(+), 55 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/pctv452e.c 
b/drivers/media/usb/dvb-usb/pctv452e.c
index c05de1b088a4..58b685094904 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -97,13 +97,14 @@ struct pctv452e_state {
u8 c;  /* transaction counter, wraps around...  */
u8 initialized; /* set to 1 if 0x15 has been sent */
u16 last_rc_key;
+
+   unsigned char data[80];
 };
 
 static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data,
 unsigned int write_len, unsigned int read_len)
 {
struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
-   u8 buf[64];
u8 id;
unsigned int rlen;
int ret;
@@ -112,33 +113,36 @@ static int tt3650_ci_msg(struct dvb_usb_device *d, u8 
cmd, u8 *data,
BUG_ON(write_len > 64 - 4);
BUG_ON(read_len > 64 - 4);
 
+   mutex_lock(>ca_mutex);
id = state->c++;
 
-   buf[0] = SYNC_BYTE_OUT;
-   buf[1] = id;
-   buf[2] = cmd;
-   buf[3] = write_len;
+   state->data[0] = SYNC_BYTE_OUT;
+   state->data[1] = id;
+   state->data[2] = cmd;
+   state->data[3] = write_len;
 
-   memcpy(buf + 4, data, write_len);
+   memcpy(state->data + 4, data, write_len);
 
rlen = (read_len > 0) ? 64 : 0;
-   ret = dvb_usb_generic_rw(d, buf, 4 + write_len,
- buf, rlen, /* delay_ms */ 0);
+   ret = dvb_usb_generic_rw(d, state->data, 4 + write_len,
+ state->data, rlen, /* delay_ms */ 0);
if (0 != ret)
goto failed;
 
ret = -EIO;
-   if (SYNC_BYTE_IN != buf[0] || id != buf[1])
+   if (SYNC_BYTE_IN != state->data[0] || id != state->data[1])
goto failed;
 
-   memcpy(data, buf + 4, read_len);
+   memcpy(data, state->data + 4, read_len);
 
+   mutex_unlock(>ca_mutex);
return 0;
 
 failed:
err("CI error %d; %02X %02X %02X -> %*ph.",
-ret, SYNC_BYTE_OUT, id, cmd, 3, buf);
+ret, SYNC_BYTE_OUT, id, cmd, 3, state->data);
 
+   mutex_unlock(>ca_mutex);
return ret;
 }
 
@@ -405,52 +409,53 @@ static int pctv452e_i2c_msg(struct dvb_usb_device *d, u8 
addr,
u8 *rcv_buf, u8 rcv_len)
 {
struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
-   u8 buf[64];
u8 id;
int ret;
 
+   mutex_lock(>ca_mutex);
id = state->c++;
 
ret = -EINVAL;
if (snd_len > 64 - 7 || rcv_len > 64 - 7)
goto failed;
 
-   buf[0] = SYNC_BYTE_OUT;
-   buf[1] = id;
-   buf[2] = PCTV_CMD_I2C;
-   buf[3] = snd_len + 3;
-   buf[4] = addr << 1;
-   buf[5] = snd_len;
-   buf[6] = rcv_len;
+   state->data[0] = SYNC_BYTE_OUT;
+   state->data[1] = id;
+   state->data[2] = PCTV_CMD_I2C;
+   state->data[3] = snd_len + 3;
+   state->data[4] = addr << 1;
+   state->data[5] = snd_len;
+   state->data[6] = rcv_len;
 
-   memcpy(buf + 7, snd_buf, snd_len);
+   memcpy(state->data + 7, snd_buf, snd_len);
 
-   ret = dvb_usb_generic_rw(d, buf, 7 + snd_len,
- buf, /* rcv_len */ 64,
+   ret = dvb_usb_generic_rw(d, state->data, 7 + snd_len,
+ state->data, /* rcv_len */ 64,
  /* delay_ms */ 0);
if (ret < 0)
goto failed;
 
/* TT USB protocol error. */
ret = -EIO;
-   if (SYNC_BYTE_IN != buf[0] || id != buf[1])
+   if (SYNC_BYTE_IN != state->data[0] || id != state->data[1])
goto failed;
 
/* I2C device didn't respond as expected. */
ret = -EREMOTEIO;
-   if (buf[5] < snd_len || buf[6] < rcv_len)
+   if (state->data[5] < snd_len || state->data[6] < rcv_len)
goto failed;
 
-   memcpy(rcv_buf, buf + 7, rcv_len);
+   memcpy(rcv_buf, state->data + 7, rcv_len);
+   mutex_unlock(>ca_mutex);
 
return rcv_len;
 
 failed:
-   err("I2C error %d; %02X %02X  %02X %02X %02X -> "
-"%02X %02X  %02X %02X %02X.",
+   err("I2C error %d; %02X %02X  %02X %02X %02X -> %*ph",
 ret, SYNC_BYTE_OUT, id, addr << 1, 

[git:media_tree/master] [media] dib0700_core: don't use stack on I2C reads

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dib0700_core: don't use stack on I2C reads
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 06:53:51 2016 -0300

Be sure that I2C reads won't use stack by passing
a pointer to the state buffer, that we know it was
allocated via kmalloc, instead of relying on the buffer
allocated by an I2C client.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dib0700_core.c | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

---

diff --git a/drivers/media/usb/dvb-usb/dib0700_core.c 
b/drivers/media/usb/dvb-usb/dib0700_core.c
index 515f89dba199..92d5408684ac 100644
--- a/drivers/media/usb/dvb-usb/dib0700_core.c
+++ b/drivers/media/usb/dvb-usb/dib0700_core.c
@@ -213,7 +213,7 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, 
struct i2c_msg *msg,
 usb_rcvctrlpipe(d->udev, 0),
 REQUEST_NEW_I2C_READ,
 USB_TYPE_VENDOR | USB_DIR_IN,
-value, index, msg[i].buf,
+value, index, st->buf,
 msg[i].len,
 USB_CTRL_GET_TIMEOUT);
if (result < 0) {
@@ -221,6 +221,14 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, 
struct i2c_msg *msg,
break;
}
 
+   if (msg[i].len > sizeof(st->buf)) {
+   deb_info("buffer too small to fit %d bytes\n",
+msg[i].len);
+   return -EIO;
+   }
+
+   memcpy(msg[i].buf, st->buf, msg[i].len);
+
deb_data("<<< ");
debug_dump(msg[i].buf, msg[i].len, deb_data);
 
@@ -238,6 +246,13 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, 
struct i2c_msg *msg,
/* I2C ctrl + FE bus; */
st->buf[3] = ((gen_mode << 6) & 0xC0) |
 ((bus_mode << 4) & 0x30);
+
+   if (msg[i].len > sizeof(st->buf) - 4) {
+   deb_info("i2c message to big: %d\n",
+msg[i].len);
+   return -EIO;
+   }
+
/* The Actual i2c payload */
memcpy(>buf[4], msg[i].buf, msg[i].len);
 
@@ -283,6 +298,11 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter 
*adap,
/* fill in the address */
st->buf[1] = msg[i].addr << 1;
/* fill the buffer */
+   if (msg[i].len > sizeof(st->buf) - 2) {
+   deb_info("i2c xfer to big: %d\n",
+   msg[i].len);
+   return -EIO;
+   }
memcpy(>buf[2], msg[i].buf, msg[i].len);
 
/* write/read request */
@@ -299,6 +319,11 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter 
*adap,
break;
}
 
+   if (msg[i + 1].len > sizeof(st->buf)) {
+   deb_info("i2c xfer buffer to small for %d\n",
+   msg[i].len);
+   return -EIO;
+   }
memcpy(msg[i + 1].buf, st->buf, msg[i + 1].len);
 
msg[i+1].len = len;

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] cinergyT2-fe: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cinergyT2-fe: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 06:16:59 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/cinergyT2-fe.c | 56 +++-
 1 file changed, 33 insertions(+), 23 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c 
b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
index fd8edcb56e61..2d29b4174dba 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
@@ -139,6 +139,10 @@ static uint16_t compute_tps(struct dtv_frontend_properties 
*op)
 struct cinergyt2_fe_state {
struct dvb_frontend fe;
struct dvb_usb_device *d;
+
+   unsigned char data[64];
+   struct mutex data_mutex;
+
struct dvbt_get_status_msg status;
 };
 
@@ -146,28 +150,31 @@ static int cinergyt2_fe_read_status(struct dvb_frontend 
*fe,
enum fe_status *status)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg result;
-   u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *),
-   sizeof(result), 0);
+   mutex_lock(>data_mutex);
+   state->data[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
+
+   ret = dvb_usb_generic_rw(state->d, state->data, 1,
+state->data, sizeof(state->status), 0);
+   if (!ret)
+   memcpy(>status, state->data, sizeof(state->status));
+   mutex_unlock(>data_mutex);
+
if (ret < 0)
return ret;
 
-   state->status = result;
-
*status = 0;
 
-   if (0x - le16_to_cpu(result.gain) > 30)
+   if (0x - le16_to_cpu(state->status.gain) > 30)
*status |= FE_HAS_SIGNAL;
-   if (result.lock_bits & (1 << 6))
+   if (state->status.lock_bits & (1 << 6))
*status |= FE_HAS_LOCK;
-   if (result.lock_bits & (1 << 5))
+   if (state->status.lock_bits & (1 << 5))
*status |= FE_HAS_SYNC;
-   if (result.lock_bits & (1 << 4))
+   if (state->status.lock_bits & (1 << 4))
*status |= FE_HAS_CARRIER;
-   if (result.lock_bits & (1 << 1))
+   if (state->status.lock_bits & (1 << 1))
*status |= FE_HAS_VITERBI;
 
if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
@@ -232,34 +239,36 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend 
*fe)
 {
struct dtv_frontend_properties *fep = >dtv_property_cache;
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_set_parameters_msg param;
-   char result[2];
+   struct dvbt_set_parameters_msg *param;
int err;
 
-   param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
-   param.tps = cpu_to_le16(compute_tps(fep));
-   param.freq = cpu_to_le32(fep->frequency / 1000);
-   param.flags = 0;
+   mutex_lock(>data_mutex);
+
+   param = (void *)state->data;
+   param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
+   param->tps = cpu_to_le16(compute_tps(fep));
+   param->freq = cpu_to_le32(fep->frequency / 1000);
+   param->flags = 0;
 
switch (fep->bandwidth_hz) {
default:
case 800:
-   param.bandwidth = 8;
+   param->bandwidth = 8;
break;
case 700:
-   param.bandwidth = 7;
+   param->bandwidth = 7;
break;
case 600:
-   param.bandwidth = 6;
+   param->bandwidth = 6;
break;
}
 
-   err = dvb_usb_generic_rw(state->d,
-   (char *), sizeof(param),
-   result, sizeof(result), 0);
+   err = dvb_usb_generic_rw(state->d, state->data, sizeof(*param),
+state->data, 2, 0);
if (err < 0)
err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
 
+   mutex_unlock(>data_mutex);
return (err < 0) ? err : 0;
 }
 
@@ -281,6 +290,7 @@ struct dvb_frontend *cinergyt2_fe_attach(struct 
dvb_usb_device *d)
s->d = d;
memcpy(>fe.ops, _fe_ops, sizeof(struct dvb_frontend_ops));
s->fe.demodulator_priv = s;
+   mutex_init(>data_mutex);
return >fe;
 }
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] dvb-usb: warn if return value for USB read/write routines is not checked

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dvb-usb: warn if return value for USB read/write routines is 
not checked
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 11:41:13 2016 -0300

the return values for dvb_usb_generic_rw() and dvb_usb_generic_write()
should be checked, as otherwise the drivers won't be doing the right
thing in the case of errors.

So, add __must_check to both declarations.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dvb-usb.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dvb-usb.h 
b/drivers/media/usb/dvb-usb/dvb-usb.h
index 639c4678c65b..1448c3d27ea2 100644
--- a/drivers/media/usb/dvb-usb/dvb-usb.h
+++ b/drivers/media/usb/dvb-usb/dvb-usb.h
@@ -462,8 +462,10 @@ extern int dvb_usb_device_init(struct usb_interface *,
 extern void dvb_usb_device_exit(struct usb_interface *);
 
 /* the generic read/write method for device control */
-extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, 
u16,int);
-extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
+extern int __must_check
+dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16, int);
+extern int __must_check
+dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
 
 /* commonly used remote control parsing */
 extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, 
int *);

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] cinergyT2-fe: cache stats at cinergyt2_fe_read_status()

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cinergyT2-fe: cache stats at cinergyt2_fe_read_status()
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 06:07:36 2016 -0300

Instead of sending USB commands for every stats call, collect
them once, when status is updated. As the frontend kthread
will call it on every few seconds, the stats will still be
collected.

Besides reducing the amount of USB/I2C transfers, this also
warrants that all stats will be collected at the same time,
and makes easier to convert it to DVBv5 stats in the future.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/cinergyT2-fe.c | 48 +---
 1 file changed, 7 insertions(+), 41 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c 
b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
index b3ec743a7a2e..fd8edcb56e61 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
@@ -139,6 +139,7 @@ static uint16_t compute_tps(struct dtv_frontend_properties 
*op)
 struct cinergyt2_fe_state {
struct dvb_frontend fe;
struct dvb_usb_device *d;
+   struct dvbt_get_status_msg status;
 };
 
 static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
@@ -154,6 +155,8 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
if (ret < 0)
return ret;
 
+   state->status = result;
+
*status = 0;
 
if (0x - le16_to_cpu(result.gain) > 30)
@@ -177,34 +180,16 @@ static int cinergyt2_fe_read_status(struct dvb_frontend 
*fe,
 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
-
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *),
-   sizeof(status), 0);
-   if (ret < 0)
-   return ret;
 
-   *ber = le32_to_cpu(status.viterbi_error_rate);
+   *ber = le32_to_cpu(state->status.viterbi_error_rate);
return 0;
 }
 
 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *),
-   sizeof(status), 0);
-   if (ret < 0) {
-   err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
-   ret);
-   return ret;
-   }
-   *unc = le32_to_cpu(status.uncorrected_block_count);
+   *unc = le32_to_cpu(state->status.uncorrected_block_count);
return 0;
 }
 
@@ -212,35 +197,16 @@ static int cinergyt2_fe_read_signal_strength(struct 
dvb_frontend *fe,
u16 *strength)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *),
-   sizeof(status), 0);
-   if (ret < 0) {
-   err("cinergyt2_fe_read_signal_strength() Failed!"
-   " (Error=%d)\n", ret);
-   return ret;
-   }
-   *strength = (0x - le16_to_cpu(status.gain));
+   *strength = (0x - le16_to_cpu(state->status.gain));
return 0;
 }
 
 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
struct cinergyt2_fe_state *state = fe->demodulator_priv;
-   struct dvbt_get_status_msg status;
-   char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-   int ret;
 
-   ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *),
-   sizeof(status), 0);
-   if (ret < 0) {
-   err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
-   return ret;
-   }
-   *snr = (status.snr << 8) | status.snr;
+   *snr = (state->status.snr << 8) | state->status.snr;
return 0;
 }
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] pctv452e: don't call BUG_ON() on non-fatal error

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] pctv452e: don't call BUG_ON() on non-fatal error
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 14:15:53 2016 -0300

There are some conditions on this driver that are tested with
BUG_ON() with are not serious enough to hang a machine.

So, just return an error if this happens.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/pctv452e.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/pctv452e.c 
b/drivers/media/usb/dvb-usb/pctv452e.c
index 58b685094904..7ad0006c5ae0 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -109,9 +109,10 @@ static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, 
u8 *data,
unsigned int rlen;
int ret;
 
-   BUG_ON(NULL == data && 0 != (write_len | read_len));
-   BUG_ON(write_len > 64 - 4);
-   BUG_ON(read_len > 64 - 4);
+   if (!data || (write_len > 64 - 4) || (read_len > 64 - 4)) {
+   err("%s: transfer data invalid", __func__);
+   return -EIO;
+   };
 
mutex_lock(>ca_mutex);
id = state->c++;

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] cxusb: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cxusb: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 06:30:27 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/cxusb.c | 62 ++-
 drivers/media/usb/dvb-usb/cxusb.h |  6 
 2 files changed, 41 insertions(+), 27 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index 907ac01ae297..39772812269d 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -45,9 +45,6 @@
 #include "si2168.h"
 #include "si2157.h"
 
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE  80
-
 /* debug */
 static int dvb_usb_cxusb_debug;
 module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
@@ -61,23 +58,27 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 static int cxusb_ctrl_msg(struct dvb_usb_device *d,
  u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
-   int wo = (rbuf == NULL || rlen == 0); /* write-only */
-   u8 sndbuf[MAX_XFER_SIZE];
+   struct cxusb_state *st = d->priv;
+   int ret, wo;
 
-   if (1 + wlen > sizeof(sndbuf)) {
-   warn("i2c wr: len=%d is too big!\n",
-wlen);
+   if (1 + wlen > MAX_XFER_SIZE) {
+   warn("i2c wr: len=%d is too big!\n", wlen);
return -EOPNOTSUPP;
}
 
-   memset(sndbuf, 0, 1+wlen);
+   wo = (rbuf == NULL || rlen == 0); /* write-only */
 
-   sndbuf[0] = cmd;
-   memcpy([1], wbuf, wlen);
+   mutex_lock(>data_mutex);
+   st->data[0] = cmd;
+   memcpy(>data[1], wbuf, wlen);
if (wo)
-   return dvb_usb_generic_write(d, sndbuf, 1+wlen);
+   ret = dvb_usb_generic_write(d, st->data, 1 + wlen);
else
-   return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 1 + wlen,
+rbuf, rlen, 0);
+
+   mutex_unlock(>data_mutex);
+   return ret;
 }
 
 /* GPIO */
@@ -1460,36 +1461,43 @@ static struct dvb_usb_device_properties 
cxusb_mygica_t230_properties;
 static int cxusb_probe(struct usb_interface *intf,
   const struct usb_device_id *id)
 {
+   struct dvb_usb_device *d;
+   struct cxusb_state *st;
+
if (0 == dvb_usb_device_init(intf, _medion_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_lgh064f_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_dee1601_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_lgz201_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_dtt7579_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_dualdig4_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _bluebird_nano2_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf,
_bluebird_nano2_needsfirmware_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _aver_a868r_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf,
 _bluebird_dualdig4_rev2_properties,
-THIS_MODULE, NULL, adapter_nr) ||
+THIS_MODULE, , adapter_nr) ||
0 == dvb_usb_device_init(intf, _d680_dmb_properties,
-   

[git:media_tree/master] [media] dw2102: return error if su3000_power_ctrl() fails

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dw2102: return error if su3000_power_ctrl() fails
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:55:53 2016 -0300

Instead of silently ignoring the error, return it.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dw2102.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

---

diff --git a/drivers/media/usb/dvb-usb/dw2102.c 
b/drivers/media/usb/dvb-usb/dw2102.c
index 5fb0c650926e..2c720cb2fb00 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -852,7 +852,7 @@ static int su3000_power_ctrl(struct dvb_usb_device *d, int 
i)
if (i && !state->initialized) {
state->initialized = 1;
/* reset board */
-   dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
+   return dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
}
 
return 0;

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] dibusb: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dibusb: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 07:34:36 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dibusb-common.c | 107 +++---
 drivers/media/usb/dvb-usb/dibusb.h|   3 +
 2 files changed, 85 insertions(+), 25 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c 
b/drivers/media/usb/dvb-usb/dibusb-common.c
index 4b08c2a47ae2..951f3dac9082 100644
--- a/drivers/media/usb/dvb-usb/dibusb-common.c
+++ b/drivers/media/usb/dvb-usb/dibusb-common.c
@@ -63,72 +63,117 @@ 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 };
int ret;
+   u8 *b;
+
+   b = kmalloc(3, GFP_KERNEL);
+   if (!b)
+   return -ENOMEM;
 
if ((ret = dibusb_streaming_ctrl(adap,onoff)) < 0)
-   return ret;
+   goto ret;
 
if (onoff) {
b[0] = DIBUSB_REQ_SET_STREAMING_MODE;
b[1] = 0x00;
-   if ((ret = dvb_usb_generic_write(adap->dev,b,2)) < 0)
-   return ret;
+   ret = dvb_usb_generic_write(adap->dev, b, 2);
+   if (ret  < 0)
+   goto 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);
+   ret = dvb_usb_generic_write(adap->dev, b, 3);
+
+ret:
+   kfree(b);
+   return ret;
 }
 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);
+
+   len = 2 + wlen + (wo ? 0 : 2);
 
-   if (4 + wlen > sizeof(sndbuf)) {
+   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([2],wbuf,wlen);
+   memcpy([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 +365,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,,1,key,5,0);
-   

[git:media_tree/master] [media] gp8psk: don't go past the buffer size

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] gp8psk: don't go past the buffer size
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 14:12:48 2016 -0300

Add checks to avoid going out of the buffer.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/gp8psk.c | 11 +++
 1 file changed, 11 insertions(+)

---

diff --git a/drivers/media/usb/dvb-usb/gp8psk.c 
b/drivers/media/usb/dvb-usb/gp8psk.c
index 807f5628a3bb..adfd76491451 100644
--- a/drivers/media/usb/dvb-usb/gp8psk.c
+++ b/drivers/media/usb/dvb-usb/gp8psk.c
@@ -60,6 +60,9 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 
value, u16 index, u8
struct gp8psk_state *st = d->priv;
int ret = 0,try = 0;
 
+   if (blen > sizeof(st->data))
+   return -EIO;
+
if ((ret = mutex_lock_interruptible(>usb_mutex)))
return ret;
 
@@ -98,6 +101,9 @@ int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 
value,
deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
debug_dump(b,blen,deb_xfer);
 
+   if (blen > sizeof(st->data))
+   return -EIO;
+
if ((ret = mutex_lock_interruptible(>usb_mutex)))
return ret;
 
@@ -151,6 +157,11 @@ static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
err("failed to load bcm4500 firmware.");
goto out_free;
}
+   if (buflen > 64) {
+   err("firmare chunk size bigger than 64 bytes.");
+   goto out_free;
+   }
+
memcpy(buf, ptr, buflen);
if (dvb_usb_generic_write(d, buf, buflen)) {
err("failed to load bcm4500 firmware.");

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] dtv5100: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtv5100: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 08:51:23 2016 -0300

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 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dtv5100.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtv5100.c 
b/drivers/media/usb/dvb-usb/dtv5100.c
index 3d11df41cac0..c60fb54f445f 100644
--- a/drivers/media/usb/dvb-usb/dtv5100.c
+++ b/drivers/media/usb/dvb-usb/dtv5100.c
@@ -31,9 +31,14 @@ module_param_named(debug, dvb_usb_dtv5100_debug, int, 0644);
 MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
+struct dtv5100_state {
+   unsigned char data[80];
+};
+
 static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
   u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
 {
+   struct dtv5100_state *st = d->priv;
u8 request;
u8 type;
u16 value;
@@ -60,9 +65,10 @@ static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
}
index = (addr << 8) + wbuf[0];
 
+   memcpy(st->data, rbuf, rlen);
msleep(1); /* avoid I2C errors */
return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), request,
-  type, value, index, rbuf, rlen,
+  type, value, index, st->data, rlen,
   DTV5100_USB_TIMEOUT);
 }
 
@@ -176,7 +182,7 @@ static struct dvb_usb_device_properties dtv5100_properties 
= {
.caps = DVB_USB_IS_AN_I2C_ADAPTER,
.usb_ctrl = DEVICE_SPECIFIC,
 
-   .size_of_priv = 0,
+   .size_of_priv = sizeof(struct dtv5100_state),
 
.num_adapters = 1,
.adapter = {{

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] technisat-usb2: use DMA buffers for I2C transfers

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] technisat-usb2: use DMA buffers for I2C transfers
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 12:04:38 2016 -0300

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.

On this driver, most of the transfers are OK, but the I2C
one was using stack.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/technisat-usb2.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c 
b/drivers/media/usb/dvb-usb/technisat-usb2.c
index d9f3262bf071..4706628a3ed5 100644
--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
@@ -89,9 +89,13 @@ struct technisat_usb2_state {
 static int technisat_usb2_i2c_access(struct usb_device *udev,
u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
 {
-   u8 b[64];
+   u8 *b;
int ret, actual_length;
 
+   b = kmalloc(64, GFP_KERNEL);
+   if (!b)
+   return -ENOMEM;
+
deb_i2c("i2c-access: %02x, tx: ", device_addr);
debug_dump(tx, txlen, deb_i2c);
deb_i2c(" ");
@@ -123,7 +127,7 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
 
if (ret < 0) {
err("i2c-error: out failed %02x = %d", device_addr, ret);
-   return -ENODEV;
+   goto err;
}
 
ret = usb_bulk_msg(udev,
@@ -131,7 +135,7 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
b, 64, _length, 1000);
if (ret < 0) {
err("i2c-error: in failed %02x = %d", device_addr, ret);
-   return -ENODEV;
+   goto err;
}
 
if (b[0] != I2C_STATUS_OK) {
@@ -140,7 +144,7 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
if (!(b[0] == I2C_STATUS_NAK &&
device_addr == 0x60
/* && device_is_technisat_usb2 */))
-   return -ENODEV;
+   goto err;
}
 
deb_i2c("status: %d, ", b[0]);
@@ -154,7 +158,9 @@ static int technisat_usb2_i2c_access(struct usb_device 
*udev,
 
deb_i2c("\n");
 
-   return 0;
+err:
+   kfree(b);
+   return ret;
 }
 
 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg 
*msg,

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] digitv: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] digitv: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 07:55:38 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/digitv.c | 20 +++-
 drivers/media/usb/dvb-usb/digitv.h |  5 -
 2 files changed, 15 insertions(+), 10 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/digitv.c 
b/drivers/media/usb/dvb-usb/digitv.c
index 63134335c994..09f8c28bd4db 100644
--- a/drivers/media/usb/dvb-usb/digitv.c
+++ b/drivers/media/usb/dvb-usb/digitv.c
@@ -28,20 +28,22 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 static int digitv_ctrl_msg(struct dvb_usb_device *d,
u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
+   struct digitv_state *st = d->priv;
int wo = (rbuf == NULL || rlen == 0); /* write-only */
-   u8 sndbuf[7],rcvbuf[7];
-   memset(sndbuf,0,7); memset(rcvbuf,0,7);
 
-   sndbuf[0] = cmd;
-   sndbuf[1] = vv;
-   sndbuf[2] = wo ? wlen : rlen;
+   memset(st->sndbuf, 0, 7);
+   memset(st->rcvbuf, 0, 7);
+
+   st->sndbuf[0] = cmd;
+   st->sndbuf[1] = vv;
+   st->sndbuf[2] = wo ? wlen : rlen;
 
if (wo) {
-   memcpy([3],wbuf,wlen);
-   dvb_usb_generic_write(d,sndbuf,7);
+   memcpy(>sndbuf[3], wbuf, wlen);
+   dvb_usb_generic_write(d, st->sndbuf, 7);
} else {
-   dvb_usb_generic_rw(d,sndbuf,7,rcvbuf,7,10);
-   memcpy(rbuf,[3],rlen);
+   dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
+   memcpy(rbuf, >rcvbuf[3], rlen);
}
return 0;
 }
diff --git a/drivers/media/usb/dvb-usb/digitv.h 
b/drivers/media/usb/dvb-usb/digitv.h
index 908c09f4966b..581e09c25491 100644
--- a/drivers/media/usb/dvb-usb/digitv.h
+++ b/drivers/media/usb/dvb-usb/digitv.h
@@ -5,7 +5,10 @@
 #include "dvb-usb.h"
 
 struct digitv_state {
-int is_nxt6000;
+   int is_nxt6000;
+
+   unsigned char sndbuf[7];
+   unsigned char rcvbuf[7];
 };
 
 /* protocol (from usblogging and the SDK:

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] pctv452e: fix semicolon.cocci warnings

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] pctv452e: fix semicolon.cocci warnings
Author:  kbuild test robot 
Date:Tue Oct 11 10:22:08 2016 -0300

drivers/media/usb/dvb-usb/pctv452e.c:115:2-3: Unneeded semicolon

 Remove unneeded semicolon.

Generated by: scripts/coccinelle/misc/semicolon.cocci

Signed-off-by: Fengguang Wu 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/pctv452e.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

---

diff --git a/drivers/media/usb/dvb-usb/pctv452e.c 
b/drivers/media/usb/dvb-usb/pctv452e.c
index 7ad0006c5ae0..07fa08be9e99 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -112,7 +112,7 @@ static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, 
u8 *data,
if (!data || (write_len > 64 - 4) || (read_len > 64 - 4)) {
err("%s: transfer data invalid", __func__);
return -EIO;
-   };
+   }
 
mutex_lock(>ca_mutex);
id = state->c++;

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] cpia2_usb: don't use stack for DMA

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cpia2_usb: don't use stack for DMA
Author:  Mauro Carvalho Chehab 
Date:Mon Oct 10 08:28:26 2016 -0300

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 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/cpia2/cpia2_usb.c | 34 ++
 1 file changed, 30 insertions(+), 4 deletions(-)

---

diff --git a/drivers/media/usb/cpia2/cpia2_usb.c 
b/drivers/media/usb/cpia2/cpia2_usb.c
index 13620cdf0599..e9100a235831 100644
--- a/drivers/media/usb/cpia2/cpia2_usb.c
+++ b/drivers/media/usb/cpia2/cpia2_usb.c
@@ -545,18 +545,30 @@ static void free_sbufs(struct camera_data *cam)
 static int write_packet(struct usb_device *udev,
u8 request, u8 * registers, u16 start, size_t size)
 {
+   unsigned char *buf;
+   int ret;
+
if (!registers || size <= 0)
return -EINVAL;
 
-   return usb_control_msg(udev,
+   buf = kmalloc(size, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   memcpy(buf, registers, size);
+
+   ret = usb_control_msg(udev,
   usb_sndctrlpipe(udev, 0),
   request,
   USB_TYPE_VENDOR | USB_RECIP_DEVICE,
   start,   /* value */
   0,   /* index */
-  registers,   /* buffer */
+  buf, /* buffer */
   size,
   HZ);
+
+   kfree(buf);
+   return ret;
 }
 
 /
@@ -567,18 +579,32 @@ static int write_packet(struct usb_device *udev,
 static int read_packet(struct usb_device *udev,
   u8 request, u8 * registers, u16 start, size_t size)
 {
+   unsigned char *buf;
+   int ret;
+
if (!registers || size <= 0)
return -EINVAL;
 
-   return usb_control_msg(udev,
+   buf = kmalloc(size, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   ret = usb_control_msg(udev,
   usb_rcvctrlpipe(udev, 0),
   request,
   USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_DEVICE,
   start,   /* value */
   0,   /* index */
-  registers,   /* buffer */
+  buf, /* buffer */
   size,
   HZ);
+
+   if (ret >= 0)
+   memcpy(registers, buf, size);
+
+   kfree(buf);
+
+   return ret;
 }
 
 /**

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] dtt200u-fe: handle errors on USB control messages

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtt200u-fe: handle errors on USB control messages
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:44:09 2016 -0300

If something goes wrong, return an error code, instead of
assuming that everything went fine.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dtt200u-fe.c | 40 ++
 1 file changed, 31 insertions(+), 9 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c 
b/drivers/media/usb/dvb-usb/dtt200u-fe.c
index 7f7f64be6353..f5c042baa254 100644
--- a/drivers/media/usb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c
@@ -27,11 +27,17 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
  enum fe_status *stat)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_TUNE_STATUS;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   if (ret < 0) {
+   *stat = 0;
+   mutex_unlock(>data_mutex);
+   return ret;
+   }
 
switch (state->data[0]) {
case 0x01:
@@ -53,25 +59,30 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
 static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_VIT_ERR_CNT;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
-   *ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2];
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   if (ret >= 0)
+   *ber = (state->data[0] << 16) | (state->data[1] << 8) | 
state->data[2];
 
mutex_unlock(>data_mutex);
-   return 0;
+   return ret;
 }
 
 static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_RS_UNCOR_BLK_CNT;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
+   if (ret >= 0)
+   *unc = (state->data[0] << 8) | state->data[1];
 
mutex_unlock(>data_mutex);
return ret;
@@ -80,11 +91,14 @@ static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* 
fe, u32 *unc)
 static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 
*strength)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_AGC;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   if (ret >= 0)
+   *strength = (state->data[0] << 8) | state->data[0];
 
mutex_unlock(>data_mutex);
return ret;
@@ -93,11 +107,14 @@ static int dtt200u_fe_read_signal_strength(struct 
dvb_frontend* fe, u16 *strengt
 static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
 
mutex_lock(>data_mutex);
state->data[0] = GET_SNR;
 
-   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+   if (ret >= 0)
+   *snr = ~((state->data[0] << 8) | state->data[0]);
 
mutex_unlock(>data_mutex);
return ret;
@@ -134,6 +151,7 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend *fe)
 {
struct dtv_frontend_properties *fep = >dtv_property_cache;
struct dtt200u_fe_state *state = fe->demodulator_priv;
+   int ret;
u16 freq = fep->frequency / 25;
 
mutex_lock(>data_mutex);
@@ -153,12 +171,16 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend 
*fe)
goto ret;
}
 
-   dvb_usb_generic_write(state->d, state->data, 2);
+   ret = dvb_usb_generic_write(state->d, state->data, 2);
+   if (ret < 0)
+   goto ret;
 
state->data[0] = SET_RF_FREQ;
state->data[1] = freq & 0xff;
state->data[2] = (freq >> 8) & 0xff;
-   dvb_usb_generic_write(state->d, state->data, 3);
+   ret = dvb_usb_generic_write(state->d, state->data, 3);
+   if (ret < 0)
+   goto ret;
 
 ret:
mutex_unlock(>data_mutex);

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org

[git:media_tree/master] [media] s2255drv: don't use stack for DMA

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] s2255drv: don't use stack for DMA
Author:  Mauro Carvalho Chehab 
Date:Mon Oct 10 11:11:13 2016 -0300

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 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/s2255/s2255drv.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/usb/s2255/s2255drv.c 
b/drivers/media/usb/s2255/s2255drv.c
index c3a0e87066eb..f7bb78c1873c 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -1901,19 +1901,30 @@ static long s2255_vendor_req(struct s2255_dev *dev, 
unsigned char Request,
 s32 TransferBufferLength, int bOut)
 {
int r;
+   unsigned char *buf;
+
+   buf = kmalloc(TransferBufferLength, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
if (!bOut) {
r = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
Request,
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
USB_DIR_IN,
-   Value, Index, TransferBuffer,
+   Value, Index, buf,
TransferBufferLength, HZ * 5);
+
+   if (r >= 0)
+   memcpy(TransferBuffer, buf, TransferBufferLength);
} else {
+   memcpy(buf, TransferBuffer, TransferBufferLength);
r = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
Request, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
-   Value, Index, TransferBuffer,
+   Value, Index, buf,
TransferBufferLength, HZ * 5);
}
+   kfree(buf);
return r;
 }
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] nova-t-usb2: handle error code on RC query

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] nova-t-usb2: handle error code on RC query
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:50:21 2016 -0300

There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/nova-t-usb2.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/nova-t-usb2.c 
b/drivers/media/usb/dvb-usb/nova-t-usb2.c
index 26d7188a1163..1babd3341910 100644
--- a/drivers/media/usb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/usb/dvb-usb/nova-t-usb2.c
@@ -76,7 +76,7 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
 {
u8 *buf, data, toggle, custom;
u16 raw;
-   int i;
+   int i, ret;
struct dibusb_device_state *st = d->priv;
 
buf = kmalloc(5, GFP_KERNEL);
@@ -85,7 +85,9 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
 
buf[0] = DIBUSB_REQ_POLL_REMOTE;
buf[1] = 0x35;
-   dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
+   ret = dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
+   if (ret < 0)
+   goto ret;
 
*state = REMOTE_NO_KEY_PRESSED;
switch (buf[0]) {
@@ -124,8 +126,9 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
break;
}
 
+ret:
kfree(buf);
-   return 0;
+   return ret;
 }
 
 static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] stk-webcam: don't use stack for DMA

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] stk-webcam: don't use stack for DMA
Author:  Mauro Carvalho Chehab 
Date:Mon Oct 10 11:17:15 2016 -0300

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 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/stkwebcam/stk-webcam.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

---

diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c 
b/drivers/media/usb/stkwebcam/stk-webcam.c
index db200c9d796d..22a9aae16291 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -147,20 +147,26 @@ int stk_camera_write_reg(struct stk_camera *dev, u16 
index, u8 value)
 int stk_camera_read_reg(struct stk_camera *dev, u16 index, int *value)
 {
struct usb_device *udev = dev->udev;
+   unsigned char *buf;
int ret;
 
+   buf = kmalloc(sizeof(u8), GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
0x00,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0x00,
index,
-   (u8 *) value,
+   buf,
sizeof(u8),
500);
-   if (ret < 0)
-   return ret;
-   else
-   return 0;
+   if (ret >= 0)
+   memcpy(value, buf, sizeof(u8));
+
+   kfree(buf);
+   return ret;
 }
 
 static int stk_start_stream(struct stk_camera *dev)

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] dtt200u: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtt200u: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 08:40:43 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dtt200u.c | 104 ++--
 1 file changed, 75 insertions(+), 29 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtt200u.c 
b/drivers/media/usb/dvb-usb/dtt200u.c
index d2a01b50af0d..7706938b5167 100644
--- a/drivers/media/usb/dvb-usb/dtt200u.c
+++ b/drivers/media/usb/dvb-usb/dtt200u.c
@@ -20,74 +20,103 @@ MODULE_PARM_DESC(debug, "set debugging level 
(1=info,xfer=2 (or-able))." DVB_USB
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
+struct dtt200u_state {
+   unsigned char data[80];
+   struct mutex data_mutex;
+};
+
 static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff)
 {
-   u8 b = SET_INIT;
+   struct dtt200u_state *st = d->priv;
+
+   mutex_lock(>data_mutex);
+
+   st->data[0] = SET_INIT;
 
if (onoff)
-   dvb_usb_generic_write(d,,2);
+   dvb_usb_generic_write(d, st->data, 2);
 
+   mutex_unlock(>data_mutex);
return 0;
 }
 
 static int dtt200u_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
-   u8 b_streaming[2] = { SET_STREAMING, onoff };
-   u8 b_rst_pid = RESET_PID_FILTER;
+   struct dtt200u_state *st = adap->dev->priv;
+
+   mutex_lock(>data_mutex);
+   st->data[0] = SET_STREAMING;
+   st->data[1] = onoff;
 
-   dvb_usb_generic_write(adap->dev, b_streaming, 2);
+   dvb_usb_generic_write(adap->dev, st->data, 2);
+
+   if (onoff)
+   return 0;
+
+   st->data[0] = RESET_PID_FILTER;
+   dvb_usb_generic_write(adap->dev, st->data, 1);
+
+   mutex_unlock(>data_mutex);
 
-   if (onoff == 0)
-   dvb_usb_generic_write(adap->dev, _rst_pid, 1);
return 0;
 }
 
 static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 
pid, int onoff)
 {
-   u8 b_pid[4];
+   struct dtt200u_state *st = adap->dev->priv;
+   int ret;
+
pid = onoff ? pid : 0;
 
-   b_pid[0] = SET_PID_FILTER;
-   b_pid[1] = index;
-   b_pid[2] = pid & 0xff;
-   b_pid[3] = (pid >> 8) & 0x1f;
+   mutex_lock(>data_mutex);
+   st->data[0] = SET_PID_FILTER;
+   st->data[1] = index;
+   st->data[2] = pid & 0xff;
+   st->data[3] = (pid >> 8) & 0x1f;
 
-   return dvb_usb_generic_write(adap->dev, b_pid, 4);
+   ret = dvb_usb_generic_write(adap->dev, st->data, 4);
+   mutex_unlock(>data_mutex);
+
+   return ret;
 }
 
 static int dtt200u_rc_query(struct dvb_usb_device *d)
 {
-   u8 key[5],cmd = GET_RC_CODE;
+   struct dtt200u_state *st = d->priv;
u32 scancode;
 
-   dvb_usb_generic_rw(d,,1,key,5,0);
-   if (key[0] == 1) {
+   mutex_lock(>data_mutex);
+   st->data[0] = GET_RC_CODE;
+
+   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   if (st->data[0] == 1) {
enum rc_type proto = RC_TYPE_NEC;
 
-   scancode = key[1];
-   if ((u8) ~key[1] != key[2]) {
+   scancode = st->data[1];
+   if ((u8) ~st->data[1] != st->data[2]) {
/* Extended NEC */
scancode = scancode << 8;
-   scancode |= key[2];
+   scancode |= st->data[2];
proto = RC_TYPE_NECX;
}
scancode = scancode << 8;
-   scancode |= key[3];
+   scancode |= st->data[3];
 
/* Check command checksum is ok */
-   if ((u8) ~key[3] == key[4])
+   if ((u8) ~st->data[3] == st->data[4])
rc_keydown(d->rc_dev, proto, scancode, 0);
else
rc_keyup(d->rc_dev);
-   } else if (key[0] == 2) {
+   } else if (st->data[0] == 2) {
rc_repeat(d->rc_dev);
} else {
rc_keyup(d->rc_dev);
}
 
-   if (key[0] != 0)
-   deb_info("key: %*ph\n", 5, key);
+   if (st->data[0] != 0)
+   deb_info("st->data: %*ph\n", 5, st->data);
 
+   mutex_unlock(>data_mutex);
return 0;
 }
 
@@ -106,17 +135,24 @@ static struct dvb_usb_device_properties 
wt220u_miglia_properties;
 static int dtt200u_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id)
 {
+   struct dvb_usb_device *d;
+   struct dtt200u_state *st;
+
if (0 == 

[git:media_tree/master] [media] dtt200u: handle USB control message errors

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtt200u: handle USB control message errors
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:37:50 2016 -0300

If something bad happens while an USB control message is
transfered, return an error code.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dtt200u.c | 26 ++
 1 file changed, 18 insertions(+), 8 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtt200u.c 
b/drivers/media/usb/dvb-usb/dtt200u.c
index 7706938b5167..f88572c7ae7c 100644
--- a/drivers/media/usb/dvb-usb/dtt200u.c
+++ b/drivers/media/usb/dvb-usb/dtt200u.c
@@ -28,37 +28,42 @@ struct dtt200u_state {
 static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff)
 {
struct dtt200u_state *st = d->priv;
+   int ret = 0;
 
mutex_lock(>data_mutex);
 
st->data[0] = SET_INIT;
 
if (onoff)
-   dvb_usb_generic_write(d, st->data, 2);
+   ret = dvb_usb_generic_write(d, st->data, 2);
 
mutex_unlock(>data_mutex);
-   return 0;
+   return ret;
 }
 
 static int dtt200u_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
struct dtt200u_state *st = adap->dev->priv;
+   int ret;
 
mutex_lock(>data_mutex);
st->data[0] = SET_STREAMING;
st->data[1] = onoff;
 
-   dvb_usb_generic_write(adap->dev, st->data, 2);
+   ret = dvb_usb_generic_write(adap->dev, st->data, 2);
+   if (ret < 0)
+   goto ret;
 
if (onoff)
-   return 0;
+   goto ret;
 
st->data[0] = RESET_PID_FILTER;
-   dvb_usb_generic_write(adap->dev, st->data, 1);
+   ret = dvb_usb_generic_write(adap->dev, st->data, 1);
 
+ret:
mutex_unlock(>data_mutex);
 
-   return 0;
+   return ret;
 }
 
 static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 
pid, int onoff)
@@ -84,11 +89,15 @@ static int dtt200u_rc_query(struct dvb_usb_device *d)
 {
struct dtt200u_state *st = d->priv;
u32 scancode;
+   int ret;
 
mutex_lock(>data_mutex);
st->data[0] = GET_RC_CODE;
 
-   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   if (ret < 0)
+   goto ret;
+
if (st->data[0] == 1) {
enum rc_type proto = RC_TYPE_NEC;
 
@@ -116,8 +125,9 @@ static int dtt200u_rc_query(struct dvb_usb_device *d)
if (st->data[0] != 0)
deb_info("st->data: %*ph\n", 5, st->data);
 
+ret:
mutex_unlock(>data_mutex);
-   return 0;
+   return ret;
 }
 
 static int dtt200u_frontend_attach(struct dvb_usb_adapter *adap)

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] flexcop-usb: don't use stack for DMA

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] flexcop-usb: don't use stack for DMA
Author:  Mauro Carvalho Chehab 
Date:Mon Oct 10 07:55:54 2016 -0300

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.

While here, remove a dead function calling usb_control_msg().

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/b2c2/flexcop-usb.c | 105 +++
 drivers/media/usb/b2c2/flexcop-usb.h |   4 ++
 2 files changed, 72 insertions(+), 37 deletions(-)

---

diff --git a/drivers/media/usb/b2c2/flexcop-usb.c 
b/drivers/media/usb/b2c2/flexcop-usb.c
index d4bdba60b0f7..52bc42da8a4c 100644
--- a/drivers/media/usb/b2c2/flexcop-usb.c
+++ b/drivers/media/usb/b2c2/flexcop-usb.c
@@ -73,23 +73,34 @@ static int flexcop_usb_readwrite_dw(struct flexcop_device 
*fc, u16 wRegOffsPCI,
u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR;
u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) |
(read ? 0x80 : 0);
+   int ret;
+
+   mutex_lock(_usb->data_mutex);
+   if (!read)
+   memcpy(fc_usb->data, val, sizeof(*val));
 
-   int len = usb_control_msg(fc_usb->udev,
+   ret = usb_control_msg(fc_usb->udev,
read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT,
request,
request_type, /* 0xc0 read or 0x40 write */
wAddress,
0,
-   val,
+   fc_usb->data,
sizeof(u32),
B2C2_WAIT_FOR_OPERATION_RDW * HZ);
 
-   if (len != sizeof(u32)) {
+   if (ret != sizeof(u32)) {
err("error while %s dword from %d (%d).", read ? "reading" :
"writing", wAddress, wRegOffsPCI);
-   return -EIO;
+   if (ret >= 0)
+   ret = -EIO;
}
-   return 0;
+
+   if (read && ret >= 0)
+   memcpy(val, fc_usb->data, sizeof(*val));
+   mutex_unlock(_usb->data_mutex);
+
+   return ret;
 }
 /*
  * DKT 010817 - add support for V8 memory read/write and flash update
@@ -100,9 +111,14 @@ static int flexcop_usb_v8_memory_req(struct flexcop_usb 
*fc_usb,
 {
u8 request_type = USB_TYPE_VENDOR;
u16 wIndex;
-   int nWaitTime, pipe, len;
+   int nWaitTime, pipe, ret;
wIndex = page << 8;
 
+   if (buflen > sizeof(fc_usb->data)) {
+   err("Buffer size bigger than max URB control message\n");
+   return -EIO;
+   }
+
switch (req) {
case B2C2_USB_READ_V8_MEM:
nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ;
@@ -127,17 +143,32 @@ static int flexcop_usb_v8_memory_req(struct flexcop_usb 
*fc_usb,
deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n", request_type, req,
wAddress, wIndex, buflen);
 
-   len = usb_control_msg(fc_usb->udev, pipe,
+   mutex_lock(_usb->data_mutex);
+
+   if ((request_type & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT)
+   memcpy(fc_usb->data, pbBuffer, buflen);
+
+   ret = usb_control_msg(fc_usb->udev, pipe,
req,
request_type,
wAddress,
wIndex,
-   pbBuffer,
+   fc_usb->data,
buflen,
nWaitTime * HZ);
+   if (ret != buflen)
+   ret = -EIO;
+
+   if (ret >= 0) {
+   ret = 0;
+   if ((request_type & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
+   memcpy(pbBuffer, fc_usb->data, buflen);
+   }
 
-   debug_dump(pbBuffer, len, deb_v8);
-   return len == buflen ? 0 : -EIO;
+   mutex_unlock(_usb->data_mutex);
+
+   debug_dump(pbBuffer, ret, deb_v8);
+   return ret;
 }
 
 #define bytes_left_to_read_on_page(paddr,buflen) \
@@ -196,29 +227,6 @@ static int flexcop_usb_get_mac_addr(struct flexcop_device 
*fc, int extended)
fc->dvb_adapter.proposed_mac, 6);
 }
 
-#if 0
-static int flexcop_usb_utility_req(struct flexcop_usb *fc_usb, int set,
-   flexcop_usb_utility_function_t func, u8 extra, u16 wIndex,
-   u16 buflen, u8 *pvBuffer)
-{
-   u16 wValue;
-   u8 request_type = (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR;
-   int nWaitTime = 2,
-   pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN, len;
-   wValue = (func << 8) | extra;
-
-   len = usb_control_msg(fc_usb->udev,pipe,
-   B2C2_USB_UTILITY,
-   request_type,
-   wValue,
-   

[git:media_tree/master] [media] af9005: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] af9005: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Wed Oct 5 06:46:49 2016 -0300

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 

 drivers/media/usb/dvb-usb/af9005.c | 319 +
 1 file changed, 181 insertions(+), 138 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/af9005.c 
b/drivers/media/usb/dvb-usb/af9005.c
index efa782ed6e2d..b257780fb380 100644
--- a/drivers/media/usb/dvb-usb/af9005.c
+++ b/drivers/media/usb/dvb-usb/af9005.c
@@ -52,17 +52,16 @@ u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 
0xff };
 struct af9005_device_state {
u8 sequence;
int led_state;
+   unsigned char data[256];
+   struct mutex data_mutex;
 };
 
 static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
  int readwrite, int type, u8 * values, int len)
 {
struct af9005_device_state *st = d->priv;
-   u8 obuf[16] = { 0 };
-   u8 ibuf[17] = { 0 };
-   u8 command;
-   int i;
-   int ret;
+   u8 command, seq;
+   int i, ret;
 
if (len < 1) {
err("generic read/write, less than 1 byte. Makes no sense.");
@@ -73,16 +72,17 @@ static int af9005_generic_read_write(struct dvb_usb_device 
*d, u16 reg,
return -EINVAL;
}
 
-   obuf[0] = 14;   /* rest of buffer length low */
-   obuf[1] = 0;/* rest of buffer length high */
+   mutex_lock(>data_mutex);
+   st->data[0] = 14;   /* rest of buffer length low */
+   st->data[1] = 0;/* rest of buffer length high */
 
-   obuf[2] = AF9005_REGISTER_RW;   /* register operation */
-   obuf[3] = 12;   /* rest of buffer length */
+   st->data[2] = AF9005_REGISTER_RW;   /* register operation */
+   st->data[3] = 12;   /* rest of buffer length */
 
-   obuf[4] = st->sequence++;   /* sequence number */
+   st->data[4] = seq = st->sequence++; /* sequence number */
 
-   obuf[5] = (u8) (reg >> 8);  /* register address */
-   obuf[6] = (u8) (reg & 0xff);
+   st->data[5] = (u8) (reg >> 8);  /* register address */
+   st->data[6] = (u8) (reg & 0xff);
 
if (type == AF9005_OFDM_REG) {
command = AF9005_CMD_OFDM_REG;
@@ -96,51 +96,52 @@ static int af9005_generic_read_write(struct dvb_usb_device 
*d, u16 reg,
command |= readwrite;
if (readwrite == AF9005_CMD_WRITE)
for (i = 0; i < len; i++)
-   obuf[8 + i] = values[i];
+   st->data[8 + i] = values[i];
else if (type == AF9005_TUNER_REG)
/* read command for tuner, the first byte contains the i2c 
address */
-   obuf[8] = values[0];
-   obuf[7] = command;
+   st->data[8] = values[0];
+   st->data[7] = command;
 
-   ret = dvb_usb_generic_rw(d, obuf, 16, ibuf, 17, 0);
+   ret = dvb_usb_generic_rw(d, st->data, 16, st->data, 17, 0);
if (ret)
-   return ret;
+   goto ret;
 
/* sanity check */
-   if (ibuf[2] != AF9005_REGISTER_RW_ACK) {
+   if (st->data[2] != AF9005_REGISTER_RW_ACK) {
err("generic read/write, wrong reply code.");
-   return -EIO;
+   ret = -EIO;
+   goto ret;
}
-   if (ibuf[3] != 0x0d) {
+   if (st->data[3] != 0x0d) {
err("generic read/write, wrong length in reply.");
-   return -EIO;
+   ret = -EIO;
+   goto ret;
}
-   if (ibuf[4] != obuf[4]) {
+   if (st->data[4] != seq) {
err("generic read/write, wrong sequence in reply.");
-   return -EIO;
+   ret = -EIO;
+   goto ret;
}
/*
-  Windows driver doesn't check these fields, in fact sometimes
-  the register in the reply is different that what has been sent
-
-  if (ibuf[5] != obuf[5] || ibuf[6] != obuf[6]) {
-  err("generic read/write, wrong register in reply.");
-  return -EIO;
-  }
-  if (ibuf[7] != command) {
-  err("generic read/write wrong command in reply.");
-  return -EIO;
-  }
+* In thesis, both input and output buffers should have
+* identical values for st->data[5] to st->data[8].
+* However, windows driver doesn't check these fields, in fact
+* sometimes the register in the reply is different that what
+* has been sent
 */
-   if (ibuf[16] != 0x01) {
+   if (st->data[16] != 0x01) {
 

[git:media_tree/master] [media] digitv: handle error code on RC query

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] digitv: handle error code on RC query
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:52:31 2016 -0300

There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/digitv.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/digitv.c 
b/drivers/media/usb/dvb-usb/digitv.c
index 09f8c28bd4db..4284f6984dc1 100644
--- a/drivers/media/usb/dvb-usb/digitv.c
+++ b/drivers/media/usb/dvb-usb/digitv.c
@@ -29,7 +29,9 @@ static int digitv_ctrl_msg(struct dvb_usb_device *d,
u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
struct digitv_state *st = d->priv;
-   int wo = (rbuf == NULL || rlen == 0); /* write-only */
+   int ret, wo;
+
+   wo = (rbuf == NULL || rlen == 0); /* write-only */
 
memset(st->sndbuf, 0, 7);
memset(st->rcvbuf, 0, 7);
@@ -40,12 +42,12 @@ static int digitv_ctrl_msg(struct dvb_usb_device *d,
 
if (wo) {
memcpy(>sndbuf[3], wbuf, wlen);
-   dvb_usb_generic_write(d, st->sndbuf, 7);
+   ret = dvb_usb_generic_write(d, st->sndbuf, 7);
} else {
-   dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
+   ret = dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
memcpy(rbuf, >rcvbuf[3], rlen);
}
-   return 0;
+   return ret;
 }
 
 /* I2C */

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] dibusb: handle error code on RC query

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dibusb: handle error code on RC query
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 13:40:48 2016 -0300

There's no sense on decoding and generating a RC key code if
there was an error on the URB control message.

Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dibusb-common.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c 
b/drivers/media/usb/dvb-usb/dibusb-common.c
index 951f3dac9082..b0fd9a609352 100644
--- a/drivers/media/usb/dvb-usb/dibusb-common.c
+++ b/drivers/media/usb/dvb-usb/dibusb-common.c
@@ -366,6 +366,7 @@ EXPORT_SYMBOL(rc_map_dibusb_table);
 int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
u8 *buf;
+   int ret;
 
buf = kmalloc(5, GFP_KERNEL);
if (!buf)
@@ -373,7 +374,9 @@ int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, 
int *state)
 
buf[0] = DIBUSB_REQ_POLL_REMOTE;
 
-   dvb_usb_generic_rw(d, buf, 1, buf, 5, 0);
+   ret = dvb_usb_generic_rw(d, buf, 1, buf, 5, 0);
+   if (ret < 0)
+   goto ret;
 
dvb_usb_nec_rc_key_to_event(d, buf, event, state);
 
@@ -382,6 +385,7 @@ int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, 
int *state)
 
kfree(buf);
 
-   return 0;
+ret:
+   return ret;
 }
 EXPORT_SYMBOL(dibusb_rc_query);

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] cinergyT2-core: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] cinergyT2-core: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Wed Oct 5 06:02:19 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/cinergyT2-core.c | 84 ++
 1 file changed, 61 insertions(+), 23 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c 
b/drivers/media/usb/dvb-usb/cinergyT2-core.c
index 9fd1527494eb..d85c0c4d4042 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
@@ -41,6 +41,8 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 struct cinergyt2_state {
u8 rc_counter;
+   unsigned char data[64];
+   struct mutex data_mutex;
 };
 
 /* We are missing a release hook with usb_device data */
@@ -50,33 +52,52 @@ static struct dvb_usb_device_properties 
cinergyt2_properties;
 
 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
 {
-   char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
-   char result[64];
-   return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
-   sizeof(result), 0);
+   struct dvb_usb_device *d = adap->dev;
+   struct cinergyt2_state *st = d->priv;
+   int ret;
+
+   mutex_lock(>data_mutex);
+   st->data[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
+   st->data[1] = enable ? 1 : 0;
+
+   ret = dvb_usb_generic_rw(d, st->data, 2, st->data, 64, 0);
+   mutex_unlock(>data_mutex);
+
+   return ret;
 }
 
 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
 {
-   char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
-   char state[3];
-   return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
+   struct cinergyt2_state *st = d->priv;
+   int ret;
+
+   mutex_lock(>data_mutex);
+   st->data[0] = CINERGYT2_EP1_SLEEP_MODE;
+   st->data[1] = enable ? 0 : 1;
+
+   ret = dvb_usb_generic_rw(d, st->data, 2, st->data, 3, 0);
+   mutex_unlock(>data_mutex);
+
+   return ret;
 }
 
 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
 {
-   char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
-   char state[3];
+   struct dvb_usb_device *d = adap->dev;
+   struct cinergyt2_state *st = d->priv;
int ret;
 
adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
 
-   ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
-   sizeof(state), 0);
+   mutex_lock(>data_mutex);
+   st->data[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
+
+   ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 3, 0);
if (ret < 0) {
deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
"state info\n");
}
+   mutex_unlock(>data_mutex);
 
/* Copy this pointer as we are gonna need it in the release phase */
cinergyt2_usb_device = adap->dev;
@@ -141,13 +162,16 @@ static int repeatable_keys[] = {
 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
struct cinergyt2_state *st = d->priv;
-   u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
int i;
 
*state = REMOTE_NO_KEY_PRESSED;
 
-   dvb_usb_generic_rw(d, , 1, key, sizeof(key), 0);
-   if (key[4] == 0xff) {
+   mutex_lock(>data_mutex);
+   st->data[0] = CINERGYT2_EP1_GET_RC_EVENTS;
+
+   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+
+   if (st->data[4] == 0xff) {
/* key repeat */
st->rc_counter++;
if (st->rc_counter > RC_REPEAT_DELAY) {
@@ -157,31 +181,45 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, 
u32 *event, int *state)
*event = d->last_event;
deb_rc("repeat key, event %x\n",
   *event);
-   return 0;
+   goto ret;
}
}
deb_rc("repeated key (non repeatable)\n");
}
-   return 0;
+   goto ret;
}
 
/* hack to pass checksum on the custom field */
-   key[2] = ~key[1];
-   dvb_usb_nec_rc_key_to_event(d, key, event, state);
-   if (key[0] != 0) {
+   st->data[2] = ~st->data[1];
+   dvb_usb_nec_rc_key_to_event(d, st->data, event, state);
+   if 

[git:media_tree/master] [media] nova-t-usb2: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] nova-t-usb2: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 11:38:46 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/nova-t-usb2.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/nova-t-usb2.c 
b/drivers/media/usb/dvb-usb/nova-t-usb2.c
index fc7569e2728d..26d7188a1163 100644
--- a/drivers/media/usb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/usb/dvb-usb/nova-t-usb2.c
@@ -74,22 +74,29 @@ static struct rc_map_table rc_map_haupp_table[] = {
  */
 static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
-   u8 key[5],cmd[2] = { DIBUSB_REQ_POLL_REMOTE, 0x35 }, data,toggle,custom;
+   u8 *buf, data, toggle, custom;
u16 raw;
int i;
struct dibusb_device_state *st = d->priv;
 
-   dvb_usb_generic_rw(d,cmd,2,key,5,0);
+   buf = kmalloc(5, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   buf[0] = DIBUSB_REQ_POLL_REMOTE;
+   buf[1] = 0x35;
+   dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
 
*state = REMOTE_NO_KEY_PRESSED;
-   switch (key[0]) {
+   switch (buf[0]) {
case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
-   raw = ((key[1] << 8) | key[2]) >> 3;
+   raw = ((buf[1] << 8) | buf[2]) >> 3;
toggle = !!(raw & 0x800);
data = raw & 0x3f;
custom = (raw >> 6) & 0x1f;
 
-   deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x 
d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
+   deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x 
d: %02x toggle: %d\n",
+  buf[1], buf[2], buf[3], custom, data, toggle);
 
for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) {
if (rc5_data(_map_haupp_table[i]) == data &&
@@ -117,6 +124,7 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 
*event, int *state)
break;
}
 
+   kfree(buf);
return 0;
 }
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:media_tree/master] [media] dtt200u-fe: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtt200u-fe: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 08:06:57 2016 -0300

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 

 drivers/media/usb/dvb-usb/dtt200u-fe.c | 95 +++---
 1 file changed, 65 insertions(+), 30 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c 
b/drivers/media/usb/dvb-usb/dtt200u-fe.c
index 9bb15f7b48db..7f7f64be6353 100644
--- a/drivers/media/usb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c
@@ -18,17 +18,22 @@ struct dtt200u_fe_state {
 
struct dtv_frontend_properties fep;
struct dvb_frontend frontend;
+
+   unsigned char data[80];
+   struct mutex data_mutex;
 };
 
 static int dtt200u_fe_read_status(struct dvb_frontend *fe,
  enum fe_status *stat)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 st = GET_TUNE_STATUS, b[3];
 
-   dvb_usb_generic_rw(state->d,,1,b,3,0);
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_TUNE_STATUS;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
 
-   switch (b[0]) {
+   switch (state->data[0]) {
case 0x01:
*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER |
FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
@@ -41,51 +46,75 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
*stat = 0;
break;
}
+   mutex_unlock(>data_mutex);
return 0;
 }
 
 static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_VIT_ERR_CNT,b[3];
-   dvb_usb_generic_rw(state->d,,1,b,3,0);
-   *ber = (b[0] << 16) | (b[1] << 8) | b[2];
+
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_VIT_ERR_CNT;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
+   *ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2];
+
+   mutex_unlock(>data_mutex);
return 0;
 }
 
 static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_RS_UNCOR_BLK_CNT,b[2];
 
-   dvb_usb_generic_rw(state->d,,1,b,2,0);
-   *unc = (b[0] << 8) | b[1];
-   return 0;
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_RS_UNCOR_BLK_CNT;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
+
+   mutex_unlock(>data_mutex);
+   return ret;
 }
 
 static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 
*strength)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_AGC, b;
-   dvb_usb_generic_rw(state->d,,1,,1,0);
-   *strength = (b << 8) | b;
-   return 0;
+
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_AGC;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+
+   mutex_unlock(>data_mutex);
+   return ret;
 }
 
 static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 bw = GET_SNR,br;
-   dvb_usb_generic_rw(state->d,,1,,1,0);
-   *snr = ~((br << 8) | br);
-   return 0;
+
+   mutex_lock(>data_mutex);
+   state->data[0] = GET_SNR;
+
+   dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
+
+   mutex_unlock(>data_mutex);
+   return ret;
 }
 
 static int dtt200u_fe_init(struct dvb_frontend* fe)
 {
struct dtt200u_fe_state *state = fe->demodulator_priv;
-   u8 b = SET_INIT;
-   return dvb_usb_generic_write(state->d,,1);
+   int ret;
+
+   mutex_lock(>data_mutex);
+   state->data[0] = SET_INIT;
+
+   ret = dvb_usb_generic_write(state->d, state->data, 1);
+   mutex_unlock(>data_mutex);
+
+   return ret;
 }
 
 static int dtt200u_fe_sleep(struct dvb_frontend* fe)
@@ -106,29 +135,34 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend 
*fe)
struct dtv_frontend_properties *fep = >dtv_property_cache;
struct dtt200u_fe_state *state = fe->demodulator_priv;
u16 freq = fep->frequency / 25;
-   u8 bwbuf[2] = { SET_BANDWIDTH, 0 },freqbuf[3] = { SET_RF_FREQ, 0, 0 };
 
+   mutex_lock(>data_mutex);
+   state->data[0] = SET_BANDWIDTH;
switch (fep->bandwidth_hz) {
case 800:
-   bwbuf[1] = 8;
+   state->data[1] = 8;
break;
case 700:
-   bwbuf[1] = 7;
+   

[git:media_tree/fixes] [media] dtt200u: don't do DMA on stack

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] dtt200u: don't do DMA on stack
Author:  Mauro Carvalho Chehab 
Date:Fri Oct 7 08:40:43 2016 -0300

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.

Reviewed-by: Patrick Boettcher 
Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/dvb-usb/dtt200u.c | 104 ++--
 1 file changed, 75 insertions(+), 29 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dtt200u.c 
b/drivers/media/usb/dvb-usb/dtt200u.c
index d2a01b50af0d..7706938b5167 100644
--- a/drivers/media/usb/dvb-usb/dtt200u.c
+++ b/drivers/media/usb/dvb-usb/dtt200u.c
@@ -20,74 +20,103 @@ MODULE_PARM_DESC(debug, "set debugging level 
(1=info,xfer=2 (or-able))." DVB_USB
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
+struct dtt200u_state {
+   unsigned char data[80];
+   struct mutex data_mutex;
+};
+
 static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff)
 {
-   u8 b = SET_INIT;
+   struct dtt200u_state *st = d->priv;
+
+   mutex_lock(>data_mutex);
+
+   st->data[0] = SET_INIT;
 
if (onoff)
-   dvb_usb_generic_write(d,,2);
+   dvb_usb_generic_write(d, st->data, 2);
 
+   mutex_unlock(>data_mutex);
return 0;
 }
 
 static int dtt200u_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
-   u8 b_streaming[2] = { SET_STREAMING, onoff };
-   u8 b_rst_pid = RESET_PID_FILTER;
+   struct dtt200u_state *st = adap->dev->priv;
+
+   mutex_lock(>data_mutex);
+   st->data[0] = SET_STREAMING;
+   st->data[1] = onoff;
 
-   dvb_usb_generic_write(adap->dev, b_streaming, 2);
+   dvb_usb_generic_write(adap->dev, st->data, 2);
+
+   if (onoff)
+   return 0;
+
+   st->data[0] = RESET_PID_FILTER;
+   dvb_usb_generic_write(adap->dev, st->data, 1);
+
+   mutex_unlock(>data_mutex);
 
-   if (onoff == 0)
-   dvb_usb_generic_write(adap->dev, _rst_pid, 1);
return 0;
 }
 
 static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 
pid, int onoff)
 {
-   u8 b_pid[4];
+   struct dtt200u_state *st = adap->dev->priv;
+   int ret;
+
pid = onoff ? pid : 0;
 
-   b_pid[0] = SET_PID_FILTER;
-   b_pid[1] = index;
-   b_pid[2] = pid & 0xff;
-   b_pid[3] = (pid >> 8) & 0x1f;
+   mutex_lock(>data_mutex);
+   st->data[0] = SET_PID_FILTER;
+   st->data[1] = index;
+   st->data[2] = pid & 0xff;
+   st->data[3] = (pid >> 8) & 0x1f;
 
-   return dvb_usb_generic_write(adap->dev, b_pid, 4);
+   ret = dvb_usb_generic_write(adap->dev, st->data, 4);
+   mutex_unlock(>data_mutex);
+
+   return ret;
 }
 
 static int dtt200u_rc_query(struct dvb_usb_device *d)
 {
-   u8 key[5],cmd = GET_RC_CODE;
+   struct dtt200u_state *st = d->priv;
u32 scancode;
 
-   dvb_usb_generic_rw(d,,1,key,5,0);
-   if (key[0] == 1) {
+   mutex_lock(>data_mutex);
+   st->data[0] = GET_RC_CODE;
+
+   dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
+   if (st->data[0] == 1) {
enum rc_type proto = RC_TYPE_NEC;
 
-   scancode = key[1];
-   if ((u8) ~key[1] != key[2]) {
+   scancode = st->data[1];
+   if ((u8) ~st->data[1] != st->data[2]) {
/* Extended NEC */
scancode = scancode << 8;
-   scancode |= key[2];
+   scancode |= st->data[2];
proto = RC_TYPE_NECX;
}
scancode = scancode << 8;
-   scancode |= key[3];
+   scancode |= st->data[3];
 
/* Check command checksum is ok */
-   if ((u8) ~key[3] == key[4])
+   if ((u8) ~st->data[3] == st->data[4])
rc_keydown(d->rc_dev, proto, scancode, 0);
else
rc_keyup(d->rc_dev);
-   } else if (key[0] == 2) {
+   } else if (st->data[0] == 2) {
rc_repeat(d->rc_dev);
} else {
rc_keyup(d->rc_dev);
}
 
-   if (key[0] != 0)
-   deb_info("key: %*ph\n", 5, key);
+   if (st->data[0] != 0)
+   deb_info("st->data: %*ph\n", 5, st->data);
 
+   mutex_unlock(>data_mutex);
return 0;
 }
 
@@ -106,17 +135,24 @@ static struct dvb_usb_device_properties 
wt220u_miglia_properties;
 static int dtt200u_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id)
 {
+   struct dvb_usb_device *d;
+   struct dtt200u_state *st;
+
if (0 == 

[git:media_tree/fixes] [media] s2255drv: don't use stack for DMA

2016-10-14 Thread Mauro Carvalho Chehab
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: [media] s2255drv: don't use stack for DMA
Author:  Mauro Carvalho Chehab 
Date:Mon Oct 10 11:11:13 2016 -0300

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 
Signed-off-by: Mauro Carvalho Chehab 

 drivers/media/usb/s2255/s2255drv.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/usb/s2255/s2255drv.c 
b/drivers/media/usb/s2255/s2255drv.c
index c3a0e87066eb..f7bb78c1873c 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -1901,19 +1901,30 @@ static long s2255_vendor_req(struct s2255_dev *dev, 
unsigned char Request,
 s32 TransferBufferLength, int bOut)
 {
int r;
+   unsigned char *buf;
+
+   buf = kmalloc(TransferBufferLength, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
if (!bOut) {
r = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
Request,
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
USB_DIR_IN,
-   Value, Index, TransferBuffer,
+   Value, Index, buf,
TransferBufferLength, HZ * 5);
+
+   if (r >= 0)
+   memcpy(TransferBuffer, buf, TransferBufferLength);
} else {
+   memcpy(buf, TransferBuffer, TransferBufferLength);
r = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
Request, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
-   Value, Index, TransferBuffer,
+   Value, Index, buf,
TransferBufferLength, HZ * 5);
}
+   kfree(buf);
return r;
 }
 

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits