Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] stb0899_drv: 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/stb0899_drv.c:540:1: warning: 'stb0899_write_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>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>

+11 -1
+11 -1
drivers/media/dvb-frontends/stb0899_drv.c
··· 32 32 #include "stb0899_priv.h" 33 33 #include "stb0899_reg.h" 34 34 35 + /* Max transfer size done by I2C transfer functions */ 36 + #define MAX_XFER_SIZE 64 37 + 35 38 static unsigned int verbose = 0;//1; 36 39 module_param(verbose, int, 0644); 37 40 ··· 502 499 int stb0899_write_regs(struct stb0899_state *state, unsigned int reg, u8 *data, u32 count) 503 500 { 504 501 int ret; 505 - u8 buf[2 + count]; 502 + u8 buf[MAX_XFER_SIZE]; 506 503 struct i2c_msg i2c_msg = { 507 504 .addr = state->config->demod_address, 508 505 .flags = 0, 509 506 .buf = buf, 510 507 .len = 2 + count 511 508 }; 509 + 510 + if (2 + count > sizeof(buf)) { 511 + printk(KERN_WARNING 512 + "%s: i2c wr reg=%04x: len=%d is too big!\n", 513 + KBUILD_MODNAME, reg, count); 514 + return -EINVAL; 515 + } 512 516 513 517 buf[0] = reg >> 8; 514 518 buf[1] = reg & 0xff;