Skip to content

Commit

Permalink
Merge branch 'topic/kbuild-fixes-for-next' of git://git.kernel.org/pu…
Browse files Browse the repository at this point in the history
…b/scm/linux/kernel/git/mchehab/linux-media

Pull media build fixes from Mauro Carvalho Chehab:
 "A series of patches that fix compilation on non-x86 archs.

  While most of them are just build fixes, there are some fixes for real
  bugs, as there are a number of drivers using dynamic stack allocation.
  A few of those might be considered a security risk, if the i2c-dev
  module is loaded, as someone could be sending very long I2C data that
  could potentially overflow the Kernel stack.  Ok, as using /dev/i2c-*
  devnodes usually requires root on usual distros, and exploiting it
  would require a DVB board or USB stick, the risk is not high"

* 'topic/kbuild-fixes-for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (28 commits)
  [media] platform drivers: Fix build on frv arch
  [media] lirc_zilog: Don't use dynamic static allocation
  [media] mxl111sf: Don't use dynamic static allocation
  [media] af9035: Don't use dynamic static allocation
  [media] af9015: Don't use dynamic static allocation
  [media] dw2102: Don't use dynamic static allocation
  [media] dibusb-common: Don't use dynamic static allocation
  [media] cxusb: Don't use dynamic static allocation
  [media] v4l2-async: Don't use dynamic static allocation
  [media] cimax2: Don't use dynamic static allocation
  [media] tuner-xc2028: Don't use dynamic static allocation
  [media] tuners: Don't use dynamic static allocation
  [media] av7110_hw: Don't use dynamic static allocation
  [media] stv090x: Don't use dynamic static allocation
  [media] stv0367: Don't use dynamic static allocation
  [media] stb0899_drv: Don't use dynamic static allocation
  [media] dvb-frontends: Don't use dynamic static allocation
  [media] dvb-frontends: Don't use dynamic static allocation
  [media] s5h1420: Don't use dynamic static allocation
  [media] uvc/lirc_serial: Fix some warnings on parisc arch
  ...
  • Loading branch information
Linus Torvalds committed Nov 18, 2013
2 parents a310410 + 3cdcf73 commit 3ea369e
Show file tree
Hide file tree
Showing 47 changed files with 610 additions and 119 deletions.
14 changes: 12 additions & 2 deletions drivers/media/dvb-frontends/af9013.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

#include "af9013_priv.h"

/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64

struct af9013_state {
struct i2c_adapter *i2c;
struct dvb_frontend fe;
Expand All @@ -50,16 +53,23 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
const u8 *val, int len)
{
int ret;
u8 buf[3+len];
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[1] = {
{
.addr = priv->config.i2c_addr,
.flags = 0,
.len = sizeof(buf),
.len = 3 + len,
.buf = buf,
}
};

if (3 + len > sizeof(buf)) {
dev_warn(&priv->i2c->dev,
"%s: i2c wr reg=%04x: len=%d is too big!\n",
KBUILD_MODNAME, reg, len);
return -EINVAL;
}

buf[0] = (reg >> 8) & 0xff;
buf[1] = (reg >> 0) & 0xff;
buf[2] = mbox;
Expand Down
23 changes: 20 additions & 3 deletions drivers/media/dvb-frontends/af9033.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

#include "af9033_priv.h"

/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64

struct af9033_state {
struct i2c_adapter *i2c;
struct dvb_frontend fe;
Expand All @@ -40,16 +43,23 @@ static int af9033_wr_regs(struct af9033_state *state, u32 reg, const u8 *val,
int len)
{
int ret;
u8 buf[3 + len];
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[1] = {
{
.addr = state->cfg.i2c_addr,
.flags = 0,
.len = sizeof(buf),
.len = 3 + len,
.buf = buf,
}
};

if (3 + len > sizeof(buf)) {
dev_warn(&state->i2c->dev,
"%s: i2c wr reg=%04x: len=%d is too big!\n",
KBUILD_MODNAME, reg, len);
return -EINVAL;
}

buf[0] = (reg >> 16) & 0xff;
buf[1] = (reg >> 8) & 0xff;
buf[2] = (reg >> 0) & 0xff;
Expand Down Expand Up @@ -161,7 +171,14 @@ static int af9033_wr_reg_val_tab(struct af9033_state *state,
const struct reg_val *tab, int tab_len)
{
int ret, i, j;
u8 buf[tab_len];
u8 buf[MAX_XFER_SIZE];

if (tab_len > sizeof(buf)) {
dev_warn(&state->i2c->dev,
"%s: i2c wr len=%d is too big!\n",
KBUILD_MODNAME, tab_len);
return -EINVAL;
}

dev_dbg(&state->i2c->dev, "%s: tab_len=%d\n", __func__, tab_len);

Expand Down
15 changes: 14 additions & 1 deletion drivers/media/dvb-frontends/bcm3510.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#include "bcm3510.h"
#include "bcm3510_priv.h"

/* Max transfer size done by bcm3510_do_hab_cmd() function */
#define MAX_XFER_SIZE 128

struct bcm3510_state {

struct i2c_adapter* i2c;
Expand Down Expand Up @@ -201,9 +204,19 @@ static int bcm3510_hab_send_request(struct bcm3510_state *st, u8 *buf, int len)

static int bcm3510_do_hab_cmd(struct bcm3510_state *st, u8 cmd, u8 msgid, u8 *obuf, u8 olen, u8 *ibuf, u8 ilen)
{
u8 ob[olen+2],ib[ilen+2];
u8 ob[MAX_XFER_SIZE], ib[MAX_XFER_SIZE];
int ret = 0;

if (ilen + 2 > sizeof(ib)) {
deb_hab("do_hab_cmd: ilen=%d is too big!\n", ilen);
return -EINVAL;
}

if (olen + 2 > sizeof(ob)) {
deb_hab("do_hab_cmd: olen=%d is too big!\n", olen);
return -EINVAL;
}

ob[0] = cmd;
ob[1] = msgid;
memcpy(&ob[2],obuf,olen);
Expand Down
21 changes: 19 additions & 2 deletions drivers/media/dvb-frontends/cxd2820r_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

#include "cxd2820r_priv.h"

/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64

/* write multiple registers */
static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
u8 *val, int len)
{
int ret;
u8 buf[len+1];
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[1] = {
{
.addr = i2c,
Expand All @@ -36,6 +39,13 @@ static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
}
};

if (1 + len > sizeof(buf)) {
dev_warn(&priv->i2c->dev,
"%s: i2c wr reg=%04x: len=%d is too big!\n",
KBUILD_MODNAME, reg, len);
return -EINVAL;
}

buf[0] = reg;
memcpy(&buf[1], val, len);

Expand All @@ -55,7 +65,7 @@ static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
u8 *val, int len)
{
int ret;
u8 buf[len];
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[2] = {
{
.addr = i2c,
Expand All @@ -70,6 +80,13 @@ static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
}
};

if (len > sizeof(buf)) {
dev_warn(&priv->i2c->dev,
"%s: i2c wr reg=%04x: len=%d is too big!\n",
KBUILD_MODNAME, reg, len);
return -EINVAL;
}

ret = i2c_transfer(priv->i2c, msg, 2);
if (ret == 2) {
memcpy(val, buf, len);
Expand Down
13 changes: 12 additions & 1 deletion drivers/media/dvb-frontends/itd1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "itd1000.h"
#include "itd1000_priv.h"

/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64

static int debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
Expand All @@ -52,10 +55,18 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
/* don't write more than one byte with flexcop behind */
static int itd1000_write_regs(struct itd1000_state *state, u8 reg, u8 v[], u8 len)
{
u8 buf[1+len];
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg = {
.addr = state->cfg->i2c_address, .flags = 0, .buf = buf, .len = len+1
};

if (1 + len > sizeof(buf)) {
printk(KERN_WARNING
"itd1000: i2c wr reg=%04x: len=%d is too big!\n",
reg, len);
return -EINVAL;
}

buf[0] = reg;
memcpy(&buf[1], v, len);

Expand Down
10 changes: 9 additions & 1 deletion drivers/media/dvb-frontends/mt312.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "mt312_priv.h"
#include "mt312.h"

/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64

struct mt312_state {
struct i2c_adapter *i2c;
Expand Down Expand Up @@ -96,9 +98,15 @@ static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg,
const u8 *src, const size_t count)
{
int ret;
u8 buf[count + 1];
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg;

if (1 + count > sizeof(buf)) {
printk(KERN_WARNING
"mt312: write: len=%zd is too big!\n", count);
return -EINVAL;
}

if (debug) {
int i;
dprintk("W(%d):", reg & 0x7f);
Expand Down
11 changes: 10 additions & 1 deletion drivers/media/dvb-frontends/nxt200x.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64

#define NXT2002_DEFAULT_FIRMWARE "dvb-fe-nxt2002.fw"
#define NXT2004_DEFAULT_FIRMWARE "dvb-fe-nxt2004.fw"
#define CRC_CCIT_MASK 0x1021
Expand Down Expand Up @@ -95,10 +98,16 @@ static int i2c_readbytes(struct nxt200x_state *state, u8 addr, u8 *buf, u8 len)
static int nxt200x_writebytes (struct nxt200x_state* state, u8 reg,
const u8 *buf, u8 len)
{
u8 buf2 [len+1];
u8 buf2[MAX_XFER_SIZE];
int err;
struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf2, .len = len + 1 };

if (1 + len > sizeof(buf2)) {
pr_warn("%s: i2c wr reg=%04x: len=%d is too big!\n",
__func__, reg, len);
return -EINVAL;
}

buf2[0] = reg;
memcpy(&buf2[1], buf, len);

Expand Down
14 changes: 12 additions & 2 deletions drivers/media/dvb-frontends/rtl2830.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,30 @@

#include "rtl2830_priv.h"

/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64

/* write multiple hardware registers */
static int rtl2830_wr(struct rtl2830_priv *priv, u8 reg, const u8 *val, int len)
{
int ret;
u8 buf[1+len];
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[1] = {
{
.addr = priv->cfg.i2c_addr,
.flags = 0,
.len = 1+len,
.len = 1 + len,
.buf = buf,
}
};

if (1 + len > sizeof(buf)) {
dev_warn(&priv->i2c->dev,
"%s: i2c wr reg=%04x: len=%d is too big!\n",
KBUILD_MODNAME, reg, len);
return -EINVAL;
}

buf[0] = reg;
memcpy(&buf[1], val, len);

Expand Down
14 changes: 12 additions & 2 deletions drivers/media/dvb-frontends/rtl2832.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "dvb_math.h"
#include <linux/bitops.h>

/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64

int rtl2832_debug;
module_param_named(debug, rtl2832_debug, int, 0644);
MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
Expand Down Expand Up @@ -162,16 +165,23 @@ static const struct rtl2832_reg_entry registers[] = {
static int rtl2832_wr(struct rtl2832_priv *priv, u8 reg, u8 *val, int len)
{
int ret;
u8 buf[1+len];
u8 buf[MAX_XFER_SIZE];
struct i2c_msg msg[1] = {
{
.addr = priv->cfg.i2c_addr,
.flags = 0,
.len = 1+len,
.len = 1 + len,
.buf = buf,
}
};

if (1 + len > sizeof(buf)) {
dev_warn(&priv->i2c->dev,
"%s: i2c wr reg=%04x: len=%d is too big!\n",
KBUILD_MODNAME, reg, len);
return -EINVAL;
}

buf[0] = reg;
memcpy(&buf[1], val, len);

Expand Down
11 changes: 9 additions & 2 deletions drivers/media/dvb-frontends/s5h1420.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,16 @@ static u32 s5h1420_tuner_i2c_func(struct i2c_adapter *adapter)
static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
{
struct s5h1420_state *state = i2c_get_adapdata(i2c_adap);
struct i2c_msg m[1 + num];
struct i2c_msg m[3];
u8 tx_open[2] = { CON_1, state->CON_1_val | 1 }; /* repeater stops once there was a stop condition */

if (1 + num > ARRAY_SIZE(m)) {
printk(KERN_WARNING
"%s: i2c xfer: num=%d is too big!\n",
KBUILD_MODNAME, num);
return -EOPNOTSUPP;
}

memset(m, 0, sizeof(struct i2c_msg) * (1 + num));

m[0].addr = state->config->demod_address;
Expand All @@ -847,7 +854,7 @@ static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c

memcpy(&m[1], msg, sizeof(struct i2c_msg) * num);

return i2c_transfer(state->i2c, m, 1+num) == 1 + num ? num : -EIO;
return i2c_transfer(state->i2c, m, 1 + num) == 1 + num ? num : -EIO;
}

static struct i2c_algorithm s5h1420_tuner_i2c_algo = {
Expand Down
12 changes: 11 additions & 1 deletion drivers/media/dvb-frontends/stb0899_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "stb0899_priv.h"
#include "stb0899_reg.h"

/* Max transfer size done by I2C transfer functions */
#define MAX_XFER_SIZE 64

static unsigned int verbose = 0;//1;
module_param(verbose, int, 0644);

Expand Down Expand Up @@ -499,14 +502,21 @@ int stb0899_read_regs(struct stb0899_state *state, unsigned int reg, u8 *buf, u3
int stb0899_write_regs(struct stb0899_state *state, unsigned int reg, u8 *data, u32 count)
{
int ret;
u8 buf[2 + count];
u8 buf[MAX_XFER_SIZE];
struct i2c_msg i2c_msg = {
.addr = state->config->demod_address,
.flags = 0,
.buf = buf,
.len = 2 + count
};

if (2 + count > sizeof(buf)) {
printk(KERN_WARNING
"%s: i2c wr reg=%04x: len=%d is too big!\n",
KBUILD_MODNAME, reg, count);
return -EINVAL;
}

buf[0] = reg >> 8;
buf[1] = reg & 0xff;
memcpy(&buf[2], data, count);
Expand Down
Loading

0 comments on commit 3ea369e

Please sign in to comment.