diff options
author | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2013-11-02 04:11:47 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2013-11-08 06:45:39 -0500 |
commit | 37ebaf6891ee81687bb558e8375c0712d8264ed8 (patch) | |
tree | 690fd4e54358fa1e6a9db6356a5f1afbc6b59593 /drivers/media | |
parent | 8393796dfa4cf5dffcceec464c7789bec3a2f471 (diff) |
[media] dvb-frontends: 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/dvb-frontends/af9013.c:77:1: warning: 'af9013_wr_regs_i2c' uses dynamic stack allocation [enabled by default]
drivers/media/dvb-frontends/af9033.c:188:1: warning: 'af9033_wr_reg_val_tab' uses dynamic stack allocation [enabled by default]
drivers/media/dvb-frontends/af9033.c:68:1: warning: 'af9033_wr_regs' uses dynamic stack allocation [enabled by default]
drivers/media/dvb-frontends/bcm3510.c:230:1: warning: 'bcm3510_do_hab_cmd' uses dynamic stack allocation [enabled by default]
drivers/media/dvb-frontends/cxd2820r_core.c:84:1: warning: 'cxd2820r_rd_regs_i2c.isra.1' uses dynamic stack allocation [enabled by default]
drivers/media/dvb-frontends/rtl2830.c:56:1: warning: 'rtl2830_wr' uses dynamic stack allocation [enabled by default]
drivers/media/dvb-frontends/rtl2832.c:187:1: warning: 'rtl2832_wr' uses dynamic stack allocation [enabled by default]
drivers/media/dvb-frontends/tda10071.c:52:1: warning: 'tda10071_wr_regs' uses dynamic stack allocation [enabled by default]
drivers/media/dvb-frontends/tda10071.c:84:1: warning: 'tda10071_rd_regs' uses dynamic stack allocation [enabled by default]
Instead, let's enforce a limit for the buffer. Considering that I2C
transfers are generally limited, and that devices used on USB has a
max data length of 64 bytes for the control URBs.
So, it seem safe to use 64 bytes as the hard limit for all those devices.
On most cases, the limit is a way lower than that, but this limit
is small enough to not affect the Kernel stack, and it is a no brain
limit, as using smaller ones would require to either carefully each
driver or to take a look on each datasheet.
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/dvb-frontends/af9013.c | 14 | ||||
-rw-r--r-- | drivers/media/dvb-frontends/af9033.c | 23 | ||||
-rw-r--r-- | drivers/media/dvb-frontends/cxd2820r_core.c | 21 | ||||
-rw-r--r-- | drivers/media/dvb-frontends/rtl2830.c | 14 | ||||
-rw-r--r-- | drivers/media/dvb-frontends/rtl2832.c | 14 | ||||
-rw-r--r-- | drivers/media/dvb-frontends/tda10071.c | 25 |
6 files changed, 96 insertions, 15 deletions
diff --git a/drivers/media/dvb-frontends/af9013.c b/drivers/media/dvb-frontends/af9013.c index a204f2828820..fb504f1e9125 100644 --- a/drivers/media/dvb-frontends/af9013.c +++ b/drivers/media/dvb-frontends/af9013.c | |||
@@ -24,6 +24,9 @@ | |||
24 | 24 | ||
25 | #include "af9013_priv.h" | 25 | #include "af9013_priv.h" |
26 | 26 | ||
27 | /* Max transfer size done by I2C transfer functions */ | ||
28 | #define MAX_XFER_SIZE 64 | ||
29 | |||
27 | struct af9013_state { | 30 | struct af9013_state { |
28 | struct i2c_adapter *i2c; | 31 | struct i2c_adapter *i2c; |
29 | struct dvb_frontend fe; | 32 | struct dvb_frontend fe; |
@@ -50,16 +53,23 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg, | |||
50 | const u8 *val, int len) | 53 | const u8 *val, int len) |
51 | { | 54 | { |
52 | int ret; | 55 | int ret; |
53 | u8 buf[3+len]; | 56 | u8 buf[MAX_XFER_SIZE]; |
54 | struct i2c_msg msg[1] = { | 57 | struct i2c_msg msg[1] = { |
55 | { | 58 | { |
56 | .addr = priv->config.i2c_addr, | 59 | .addr = priv->config.i2c_addr, |
57 | .flags = 0, | 60 | .flags = 0, |
58 | .len = sizeof(buf), | 61 | .len = 3 + len, |
59 | .buf = buf, | 62 | .buf = buf, |
60 | } | 63 | } |
61 | }; | 64 | }; |
62 | 65 | ||
66 | if (3 + len > sizeof(buf)) { | ||
67 | dev_warn(&priv->i2c->dev, | ||
68 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | ||
69 | KBUILD_MODNAME, reg, len); | ||
70 | return -EINVAL; | ||
71 | } | ||
72 | |||
63 | buf[0] = (reg >> 8) & 0xff; | 73 | buf[0] = (reg >> 8) & 0xff; |
64 | buf[1] = (reg >> 0) & 0xff; | 74 | buf[1] = (reg >> 0) & 0xff; |
65 | buf[2] = mbox; | 75 | buf[2] = mbox; |
diff --git a/drivers/media/dvb-frontends/af9033.c b/drivers/media/dvb-frontends/af9033.c index a777b4b944eb..30ee59052157 100644 --- a/drivers/media/dvb-frontends/af9033.c +++ b/drivers/media/dvb-frontends/af9033.c | |||
@@ -21,6 +21,9 @@ | |||
21 | 21 | ||
22 | #include "af9033_priv.h" | 22 | #include "af9033_priv.h" |
23 | 23 | ||
24 | /* Max transfer size done by I2C transfer functions */ | ||
25 | #define MAX_XFER_SIZE 64 | ||
26 | |||
24 | struct af9033_state { | 27 | struct af9033_state { |
25 | struct i2c_adapter *i2c; | 28 | struct i2c_adapter *i2c; |
26 | struct dvb_frontend fe; | 29 | struct dvb_frontend fe; |
@@ -40,16 +43,23 @@ static int af9033_wr_regs(struct af9033_state *state, u32 reg, const u8 *val, | |||
40 | int len) | 43 | int len) |
41 | { | 44 | { |
42 | int ret; | 45 | int ret; |
43 | u8 buf[3 + len]; | 46 | u8 buf[MAX_XFER_SIZE]; |
44 | struct i2c_msg msg[1] = { | 47 | struct i2c_msg msg[1] = { |
45 | { | 48 | { |
46 | .addr = state->cfg.i2c_addr, | 49 | .addr = state->cfg.i2c_addr, |
47 | .flags = 0, | 50 | .flags = 0, |
48 | .len = sizeof(buf), | 51 | .len = 3 + len, |
49 | .buf = buf, | 52 | .buf = buf, |
50 | } | 53 | } |
51 | }; | 54 | }; |
52 | 55 | ||
56 | if (3 + len > sizeof(buf)) { | ||
57 | dev_warn(&state->i2c->dev, | ||
58 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | ||
59 | KBUILD_MODNAME, reg, len); | ||
60 | return -EINVAL; | ||
61 | } | ||
62 | |||
53 | buf[0] = (reg >> 16) & 0xff; | 63 | buf[0] = (reg >> 16) & 0xff; |
54 | buf[1] = (reg >> 8) & 0xff; | 64 | buf[1] = (reg >> 8) & 0xff; |
55 | buf[2] = (reg >> 0) & 0xff; | 65 | buf[2] = (reg >> 0) & 0xff; |
@@ -161,7 +171,14 @@ static int af9033_wr_reg_val_tab(struct af9033_state *state, | |||
161 | const struct reg_val *tab, int tab_len) | 171 | const struct reg_val *tab, int tab_len) |
162 | { | 172 | { |
163 | int ret, i, j; | 173 | int ret, i, j; |
164 | u8 buf[tab_len]; | 174 | u8 buf[MAX_XFER_SIZE]; |
175 | |||
176 | if (tab_len > sizeof(buf)) { | ||
177 | dev_warn(&state->i2c->dev, | ||
178 | "%s: i2c wr len=%d is too big!\n", | ||
179 | KBUILD_MODNAME, tab_len); | ||
180 | return -EINVAL; | ||
181 | } | ||
165 | 182 | ||
166 | dev_dbg(&state->i2c->dev, "%s: tab_len=%d\n", __func__, tab_len); | 183 | dev_dbg(&state->i2c->dev, "%s: tab_len=%d\n", __func__, tab_len); |
167 | 184 | ||
diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c index d9eeeb1dfa96..03930d5e9fea 100644 --- a/drivers/media/dvb-frontends/cxd2820r_core.c +++ b/drivers/media/dvb-frontends/cxd2820r_core.c | |||
@@ -21,12 +21,15 @@ | |||
21 | 21 | ||
22 | #include "cxd2820r_priv.h" | 22 | #include "cxd2820r_priv.h" |
23 | 23 | ||
24 | /* Max transfer size done by I2C transfer functions */ | ||
25 | #define MAX_XFER_SIZE 64 | ||
26 | |||
24 | /* write multiple registers */ | 27 | /* write multiple registers */ |
25 | static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg, | 28 | static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg, |
26 | u8 *val, int len) | 29 | u8 *val, int len) |
27 | { | 30 | { |
28 | int ret; | 31 | int ret; |
29 | u8 buf[len+1]; | 32 | u8 buf[MAX_XFER_SIZE]; |
30 | struct i2c_msg msg[1] = { | 33 | struct i2c_msg msg[1] = { |
31 | { | 34 | { |
32 | .addr = i2c, | 35 | .addr = i2c, |
@@ -36,6 +39,13 @@ static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg, | |||
36 | } | 39 | } |
37 | }; | 40 | }; |
38 | 41 | ||
42 | if (1 + len > sizeof(buf)) { | ||
43 | dev_warn(&priv->i2c->dev, | ||
44 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | ||
45 | KBUILD_MODNAME, reg, len); | ||
46 | return -EINVAL; | ||
47 | } | ||
48 | |||
39 | buf[0] = reg; | 49 | buf[0] = reg; |
40 | memcpy(&buf[1], val, len); | 50 | memcpy(&buf[1], val, len); |
41 | 51 | ||
@@ -55,7 +65,7 @@ static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg, | |||
55 | u8 *val, int len) | 65 | u8 *val, int len) |
56 | { | 66 | { |
57 | int ret; | 67 | int ret; |
58 | u8 buf[len]; | 68 | u8 buf[MAX_XFER_SIZE]; |
59 | struct i2c_msg msg[2] = { | 69 | struct i2c_msg msg[2] = { |
60 | { | 70 | { |
61 | .addr = i2c, | 71 | .addr = i2c, |
@@ -70,6 +80,13 @@ static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg, | |||
70 | } | 80 | } |
71 | }; | 81 | }; |
72 | 82 | ||
83 | if (len > sizeof(buf)) { | ||
84 | dev_warn(&priv->i2c->dev, | ||
85 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | ||
86 | KBUILD_MODNAME, reg, len); | ||
87 | return -EINVAL; | ||
88 | } | ||
89 | |||
73 | ret = i2c_transfer(priv->i2c, msg, 2); | 90 | ret = i2c_transfer(priv->i2c, msg, 2); |
74 | if (ret == 2) { | 91 | if (ret == 2) { |
75 | memcpy(val, buf, len); | 92 | memcpy(val, buf, len); |
diff --git a/drivers/media/dvb-frontends/rtl2830.c b/drivers/media/dvb-frontends/rtl2830.c index 362d26d11e82..7efb796c472c 100644 --- a/drivers/media/dvb-frontends/rtl2830.c +++ b/drivers/media/dvb-frontends/rtl2830.c | |||
@@ -27,20 +27,30 @@ | |||
27 | 27 | ||
28 | #include "rtl2830_priv.h" | 28 | #include "rtl2830_priv.h" |
29 | 29 | ||
30 | /* Max transfer size done by I2C transfer functions */ | ||
31 | #define MAX_XFER_SIZE 64 | ||
32 | |||
30 | /* write multiple hardware registers */ | 33 | /* write multiple hardware registers */ |
31 | static int rtl2830_wr(struct rtl2830_priv *priv, u8 reg, const u8 *val, int len) | 34 | static int rtl2830_wr(struct rtl2830_priv *priv, u8 reg, const u8 *val, int len) |
32 | { | 35 | { |
33 | int ret; | 36 | int ret; |
34 | u8 buf[1+len]; | 37 | u8 buf[MAX_XFER_SIZE]; |
35 | struct i2c_msg msg[1] = { | 38 | struct i2c_msg msg[1] = { |
36 | { | 39 | { |
37 | .addr = priv->cfg.i2c_addr, | 40 | .addr = priv->cfg.i2c_addr, |
38 | .flags = 0, | 41 | .flags = 0, |
39 | .len = 1+len, | 42 | .len = 1 + len, |
40 | .buf = buf, | 43 | .buf = buf, |
41 | } | 44 | } |
42 | }; | 45 | }; |
43 | 46 | ||
47 | if (1 + len > sizeof(buf)) { | ||
48 | dev_warn(&priv->i2c->dev, | ||
49 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | ||
50 | KBUILD_MODNAME, reg, len); | ||
51 | return -EINVAL; | ||
52 | } | ||
53 | |||
44 | buf[0] = reg; | 54 | buf[0] = reg; |
45 | memcpy(&buf[1], val, len); | 55 | memcpy(&buf[1], val, len); |
46 | 56 | ||
diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c index a95dfe0a5ce3..ff73da9365e3 100644 --- a/drivers/media/dvb-frontends/rtl2832.c +++ b/drivers/media/dvb-frontends/rtl2832.c | |||
@@ -22,6 +22,9 @@ | |||
22 | #include "dvb_math.h" | 22 | #include "dvb_math.h" |
23 | #include <linux/bitops.h> | 23 | #include <linux/bitops.h> |
24 | 24 | ||
25 | /* Max transfer size done by I2C transfer functions */ | ||
26 | #define MAX_XFER_SIZE 64 | ||
27 | |||
25 | int rtl2832_debug; | 28 | int rtl2832_debug; |
26 | module_param_named(debug, rtl2832_debug, int, 0644); | 29 | module_param_named(debug, rtl2832_debug, int, 0644); |
27 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); | 30 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); |
@@ -162,16 +165,23 @@ static const struct rtl2832_reg_entry registers[] = { | |||
162 | static int rtl2832_wr(struct rtl2832_priv *priv, u8 reg, u8 *val, int len) | 165 | static int rtl2832_wr(struct rtl2832_priv *priv, u8 reg, u8 *val, int len) |
163 | { | 166 | { |
164 | int ret; | 167 | int ret; |
165 | u8 buf[1+len]; | 168 | u8 buf[MAX_XFER_SIZE]; |
166 | struct i2c_msg msg[1] = { | 169 | struct i2c_msg msg[1] = { |
167 | { | 170 | { |
168 | .addr = priv->cfg.i2c_addr, | 171 | .addr = priv->cfg.i2c_addr, |
169 | .flags = 0, | 172 | .flags = 0, |
170 | .len = 1+len, | 173 | .len = 1 + len, |
171 | .buf = buf, | 174 | .buf = buf, |
172 | } | 175 | } |
173 | }; | 176 | }; |
174 | 177 | ||
178 | if (1 + len > sizeof(buf)) { | ||
179 | dev_warn(&priv->i2c->dev, | ||
180 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | ||
181 | KBUILD_MODNAME, reg, len); | ||
182 | return -EINVAL; | ||
183 | } | ||
184 | |||
175 | buf[0] = reg; | 185 | buf[0] = reg; |
176 | memcpy(&buf[1], val, len); | 186 | memcpy(&buf[1], val, len); |
177 | 187 | ||
diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c index e79749cfec81..8ad3a57cf640 100644 --- a/drivers/media/dvb-frontends/tda10071.c +++ b/drivers/media/dvb-frontends/tda10071.c | |||
@@ -20,6 +20,9 @@ | |||
20 | 20 | ||
21 | #include "tda10071_priv.h" | 21 | #include "tda10071_priv.h" |
22 | 22 | ||
23 | /* Max transfer size done by I2C transfer functions */ | ||
24 | #define MAX_XFER_SIZE 64 | ||
25 | |||
23 | static struct dvb_frontend_ops tda10071_ops; | 26 | static struct dvb_frontend_ops tda10071_ops; |
24 | 27 | ||
25 | /* write multiple registers */ | 28 | /* write multiple registers */ |
@@ -27,16 +30,23 @@ static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val, | |||
27 | int len) | 30 | int len) |
28 | { | 31 | { |
29 | int ret; | 32 | int ret; |
30 | u8 buf[len+1]; | 33 | u8 buf[MAX_XFER_SIZE]; |
31 | struct i2c_msg msg[1] = { | 34 | struct i2c_msg msg[1] = { |
32 | { | 35 | { |
33 | .addr = priv->cfg.demod_i2c_addr, | 36 | .addr = priv->cfg.demod_i2c_addr, |
34 | .flags = 0, | 37 | .flags = 0, |
35 | .len = sizeof(buf), | 38 | .len = 1 + len, |
36 | .buf = buf, | 39 | .buf = buf, |
37 | } | 40 | } |
38 | }; | 41 | }; |
39 | 42 | ||
43 | if (1 + len > sizeof(buf)) { | ||
44 | dev_warn(&priv->i2c->dev, | ||
45 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | ||
46 | KBUILD_MODNAME, reg, len); | ||
47 | return -EINVAL; | ||
48 | } | ||
49 | |||
40 | buf[0] = reg; | 50 | buf[0] = reg; |
41 | memcpy(&buf[1], val, len); | 51 | memcpy(&buf[1], val, len); |
42 | 52 | ||
@@ -56,7 +66,7 @@ static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val, | |||
56 | int len) | 66 | int len) |
57 | { | 67 | { |
58 | int ret; | 68 | int ret; |
59 | u8 buf[len]; | 69 | u8 buf[MAX_XFER_SIZE]; |
60 | struct i2c_msg msg[2] = { | 70 | struct i2c_msg msg[2] = { |
61 | { | 71 | { |
62 | .addr = priv->cfg.demod_i2c_addr, | 72 | .addr = priv->cfg.demod_i2c_addr, |
@@ -66,11 +76,18 @@ static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val, | |||
66 | }, { | 76 | }, { |
67 | .addr = priv->cfg.demod_i2c_addr, | 77 | .addr = priv->cfg.demod_i2c_addr, |
68 | .flags = I2C_M_RD, | 78 | .flags = I2C_M_RD, |
69 | .len = sizeof(buf), | 79 | .len = len, |
70 | .buf = buf, | 80 | .buf = buf, |
71 | } | 81 | } |
72 | }; | 82 | }; |
73 | 83 | ||
84 | if (len > sizeof(buf)) { | ||
85 | dev_warn(&priv->i2c->dev, | ||
86 | "%s: i2c wr reg=%04x: len=%d is too big!\n", | ||
87 | KBUILD_MODNAME, reg, len); | ||
88 | return -EINVAL; | ||
89 | } | ||
90 | |||
74 | ret = i2c_transfer(priv->i2c, msg, 2); | 91 | ret = i2c_transfer(priv->i2c, msg, 2); |
75 | if (ret == 2) { | 92 | if (ret == 2) { |
76 | memcpy(val, buf, len); | 93 | memcpy(val, buf, len); |