Commit 0065a79a authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[media] dw2102: Don't use dynamic static allocation

Dynamic static allocation is evil, as Kernel stack is too low, and
compilation complains about it on some archs:
	drivers/media/usb/dvb-usb/dw2102.c:368:1: warning: 'dw2102_earda_i2c_transfer' uses dynamic stack allocation [enabled by default]
	drivers/media/usb/dvb-usb/dw2102.c:449:1: warning: 'dw2104_i2c_transfer' uses dynamic stack allocation [enabled by default]
	drivers/media/usb/dvb-usb/dw2102.c:512:1: warning: 'dw3101_i2c_transfer' uses dynamic stack allocation [enabled by default]
	drivers/media/usb/dvb-usb/dw2102.c:621:1: warning: 's6x0_i2c_transfer' uses dynamic stack allocation [enabled by default]
Instead, let's enforce a limit for the buffer to be the max size of
a control URB payload data (64 bytes).
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
Reviewed-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent 1d7fa359
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
#include "stb6100_proc.h" #include "stb6100_proc.h"
#include "m88rs2000.h" #include "m88rs2000.h"
/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64
#ifndef USB_PID_DW2102 #ifndef USB_PID_DW2102
#define USB_PID_DW2102 0x2102 #define USB_PID_DW2102 0x2102
#endif #endif
...@@ -308,7 +311,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms ...@@ -308,7 +311,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms
case 2: { case 2: {
/* read */ /* read */
/* first write first register number */ /* first write first register number */
u8 ibuf[msg[1].len + 2], obuf[3]; u8 ibuf[MAX_XFER_SIZE], obuf[3];
if (2 + msg[1].len > sizeof(ibuf)) {
warn("i2c rd: len=%d is too big!\n",
msg[1].len);
return -EOPNOTSUPP;
}
obuf[0] = msg[0].addr << 1; obuf[0] = msg[0].addr << 1;
obuf[1] = msg[0].len; obuf[1] = msg[0].len;
obuf[2] = msg[0].buf[0]; obuf[2] = msg[0].buf[0];
...@@ -325,7 +335,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms ...@@ -325,7 +335,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms
switch (msg[0].addr) { switch (msg[0].addr) {
case 0x68: { case 0x68: {
/* write to register */ /* write to register */
u8 obuf[msg[0].len + 2]; u8 obuf[MAX_XFER_SIZE];
if (2 + msg[0].len > sizeof(obuf)) {
warn("i2c wr: len=%d is too big!\n",
msg[1].len);
return -EOPNOTSUPP;
}
obuf[0] = msg[0].addr << 1; obuf[0] = msg[0].addr << 1;
obuf[1] = msg[0].len; obuf[1] = msg[0].len;
memcpy(obuf + 2, msg[0].buf, msg[0].len); memcpy(obuf + 2, msg[0].buf, msg[0].len);
...@@ -335,7 +352,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms ...@@ -335,7 +352,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms
} }
case 0x61: { case 0x61: {
/* write to tuner */ /* write to tuner */
u8 obuf[msg[0].len + 2]; u8 obuf[MAX_XFER_SIZE];
if (2 + msg[0].len > sizeof(obuf)) {
warn("i2c wr: len=%d is too big!\n",
msg[1].len);
return -EOPNOTSUPP;
}
obuf[0] = msg[0].addr << 1; obuf[0] = msg[0].addr << 1;
obuf[1] = msg[0].len; obuf[1] = msg[0].len;
memcpy(obuf + 2, msg[0].buf, msg[0].len); memcpy(obuf + 2, msg[0].buf, msg[0].len);
...@@ -401,7 +425,14 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], i ...@@ -401,7 +425,14 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], i
default: { default: {
if (msg[j].flags == I2C_M_RD) { if (msg[j].flags == I2C_M_RD) {
/* read registers */ /* read registers */
u8 ibuf[msg[j].len + 2]; u8 ibuf[MAX_XFER_SIZE];
if (2 + msg[j].len > sizeof(ibuf)) {
warn("i2c rd: len=%d is too big!\n",
msg[j].len);
return -EOPNOTSUPP;
}
dw210x_op_rw(d->udev, 0xc3, dw210x_op_rw(d->udev, 0xc3,
(msg[j].addr << 1) + 1, 0, (msg[j].addr << 1) + 1, 0,
ibuf, msg[j].len + 2, ibuf, msg[j].len + 2,
...@@ -430,7 +461,14 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], i ...@@ -430,7 +461,14 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], i
} while (len > 0); } while (len > 0);
} else { } else {
/* write registers */ /* write registers */
u8 obuf[msg[j].len + 2]; u8 obuf[MAX_XFER_SIZE];
if (2 + msg[j].len > sizeof(obuf)) {
warn("i2c wr: len=%d is too big!\n",
msg[j].len);
return -EOPNOTSUPP;
}
obuf[0] = msg[j].addr << 1; obuf[0] = msg[j].addr << 1;
obuf[1] = msg[j].len; obuf[1] = msg[j].len;
memcpy(obuf + 2, msg[j].buf, msg[j].len); memcpy(obuf + 2, msg[j].buf, msg[j].len);
...@@ -463,7 +501,13 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], ...@@ -463,7 +501,13 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
case 2: { case 2: {
/* read */ /* read */
/* first write first register number */ /* first write first register number */
u8 ibuf[msg[1].len + 2], obuf[3]; u8 ibuf[MAX_XFER_SIZE], obuf[3];
if (2 + msg[1].len > sizeof(ibuf)) {
warn("i2c rd: len=%d is too big!\n",
msg[1].len);
return -EOPNOTSUPP;
}
obuf[0] = msg[0].addr << 1; obuf[0] = msg[0].addr << 1;
obuf[1] = msg[0].len; obuf[1] = msg[0].len;
obuf[2] = msg[0].buf[0]; obuf[2] = msg[0].buf[0];
...@@ -481,7 +525,13 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], ...@@ -481,7 +525,13 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
case 0x60: case 0x60:
case 0x0c: { case 0x0c: {
/* write to register */ /* write to register */
u8 obuf[msg[0].len + 2]; u8 obuf[MAX_XFER_SIZE];
if (2 + msg[0].len > sizeof(obuf)) {
warn("i2c wr: len=%d is too big!\n",
msg[0].len);
return -EOPNOTSUPP;
}
obuf[0] = msg[0].addr << 1; obuf[0] = msg[0].addr << 1;
obuf[1] = msg[0].len; obuf[1] = msg[0].len;
memcpy(obuf + 2, msg[0].buf, msg[0].len); memcpy(obuf + 2, msg[0].buf, msg[0].len);
...@@ -563,7 +613,14 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], ...@@ -563,7 +613,14 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
default: { default: {
if (msg[j].flags == I2C_M_RD) { if (msg[j].flags == I2C_M_RD) {
/* read registers */ /* read registers */
u8 ibuf[msg[j].len]; u8 ibuf[MAX_XFER_SIZE];
if (msg[j].len > sizeof(ibuf)) {
warn("i2c rd: len=%d is too big!\n",
msg[j].len);
return -EOPNOTSUPP;
}
dw210x_op_rw(d->udev, 0x91, 0, 0, dw210x_op_rw(d->udev, 0x91, 0, 0,
ibuf, msg[j].len, ibuf, msg[j].len,
DW210X_READ_MSG); DW210X_READ_MSG);
...@@ -590,7 +647,14 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], ...@@ -590,7 +647,14 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
} while (len > 0); } while (len > 0);
} else if (j < (num - 1)) { } else if (j < (num - 1)) {
/* write register addr before read */ /* write register addr before read */
u8 obuf[msg[j].len + 2]; u8 obuf[MAX_XFER_SIZE];
if (2 + msg[j].len > sizeof(obuf)) {
warn("i2c wr: len=%d is too big!\n",
msg[j].len);
return -EOPNOTSUPP;
}
obuf[0] = msg[j + 1].len; obuf[0] = msg[j + 1].len;
obuf[1] = (msg[j].addr << 1); obuf[1] = (msg[j].addr << 1);
memcpy(obuf + 2, msg[j].buf, msg[j].len); memcpy(obuf + 2, msg[j].buf, msg[j].len);
...@@ -602,7 +666,13 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], ...@@ -602,7 +666,13 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
break; break;
} else { } else {
/* write registers */ /* write registers */
u8 obuf[msg[j].len + 2]; u8 obuf[MAX_XFER_SIZE];
if (2 + msg[j].len > sizeof(obuf)) {
warn("i2c wr: len=%d is too big!\n",
msg[j].len);
return -EOPNOTSUPP;
}
obuf[0] = msg[j].len + 1; obuf[0] = msg[j].len + 1;
obuf[1] = (msg[j].addr << 1); obuf[1] = (msg[j].addr << 1);
memcpy(obuf + 2, msg[j].buf, msg[j].len); memcpy(obuf + 2, msg[j].buf, msg[j].len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment