Skip to content

Commit 50fd5e8

Browse files
Hans Verkuilmchehab
Hans Verkuil
authored andcommittedDec 23, 2014
[media] hd29l2: fix sparse error and warnings
drivers/media/dvb-frontends/hd29l2.c:29:18: warning: Variable length array is used. drivers/media/dvb-frontends/hd29l2.c:34:32: error: cannot size expression drivers/media/dvb-frontends/hd29l2.c:125:5: warning: symbol 'hd29l2_rd_reg_mask' was not declared. Should it be static? Variable length arrays are frowned upon, so replace with a fixed length and check that there won't be a buffer overrun. Signed-off-by: Hans Verkuil <[email protected]> Reviewed-by: Antti Palosaari <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 7c424dd commit 50fd5e8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
 

‎drivers/media/dvb-frontends/hd29l2.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,24 @@
2222

2323
#include "hd29l2_priv.h"
2424

25+
#define HD29L2_MAX_LEN (3)
26+
2527
/* write multiple registers */
2628
static int hd29l2_wr_regs(struct hd29l2_priv *priv, u8 reg, u8 *val, int len)
2729
{
2830
int ret;
29-
u8 buf[2 + len];
31+
u8 buf[2 + HD29L2_MAX_LEN];
3032
struct i2c_msg msg[1] = {
3133
{
3234
.addr = priv->cfg.i2c_addr,
3335
.flags = 0,
34-
.len = sizeof(buf),
36+
.len = 2 + len,
3537
.buf = buf,
3638
}
3739
};
3840

41+
if (len > HD29L2_MAX_LEN)
42+
return -EINVAL;
3943
buf[0] = 0x00;
4044
buf[1] = reg;
4145
memcpy(&buf[2], val, len);
@@ -118,7 +122,7 @@ static int hd29l2_wr_reg_mask(struct hd29l2_priv *priv, u8 reg, u8 val, u8 mask)
118122
}
119123

120124
/* read single register with mask */
121-
int hd29l2_rd_reg_mask(struct hd29l2_priv *priv, u8 reg, u8 *val, u8 mask)
125+
static int hd29l2_rd_reg_mask(struct hd29l2_priv *priv, u8 reg, u8 *val, u8 mask)
122126
{
123127
int ret, i;
124128
u8 tmp;

0 commit comments

Comments
 (0)