Skip to content

Commit

Permalink
media: flexcop-i2c: get rid of KERN_CONT
Browse files Browse the repository at this point in the history
Coverity complains about werid stuff at the debug logic:

	CID 113542 (#1 of 1): Out-of-bounds access (ARRAY_VS_SINGLETON)10.
	callee_ptr_arith: Passing buf to function flexcop_i2c_write4
	which uses it as an array. This might corrupt or misinterpret
	adjacent memory locations.

Instead of directly addressing the issue there, let's rework at
the logic there.

On newer kernels, KERN_CONT does nothing, as the previous message
won't wait for a continuation. Also, both flexcop_i2c_read4() and
flexcop_i2c_write4(), called by it, will print stuff if (debug &4).

So, the way it is is too buggy.

There are two kinds of debug stuff there: deb_i2c() and a code hidden
under #ifdef DUMP_I2C_MESSAGES, with can't be selected without touching
the source code.

Also, if both debug & 0x4 and DUMP_I2C_MESSAGES, flexcop_i2c_request()
will emit two debug messages per call with different data,
with sounds messy.

Simplify it by getting rid of DUMP_I2C_MESSAGES and adding a new
flag to debug (0x40), and making the debug logic there more
consistent.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
  • Loading branch information
Mauro Carvalho Chehab authored and Mauro Carvalho Chehab committed May 4, 2018
1 parent 366b401 commit 25d4aff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
47 changes: 19 additions & 28 deletions drivers/media/common/b2c2/flexcop-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,67 +105,58 @@ static int flexcop_i2c_write4(struct flexcop_device *fc,
}

int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c,
flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len)
flexcop_access_op_t op, u8 chipaddr,
u8 start_addr, u8 *buf, u16 size)
{
int ret;

#ifdef DUMP_I2C_MESSAGES
int i;
#endif
int len = size;
u8 *p;
u8 addr = start_addr;

u16 bytes_to_transfer;
flexcop_ibi_value r100;

deb_i2c("op = %d\n",op);
deb_i2c("port %d %s(%02x): register %02x, size: %d\n",
i2c->port,
op == FC_READ ? "rd" : "wr",
chipaddr, start_addr, size);
r100.raw = 0;
r100.tw_sm_c_100.chipaddr = chipaddr;
r100.tw_sm_c_100.twoWS_rw = op;
r100.tw_sm_c_100.twoWS_port_reg = i2c->port;

#ifdef DUMP_I2C_MESSAGES
printk(KERN_DEBUG "%d ", i2c->port);
if (op == FC_READ)
printk(KERN_CONT "rd(");
else
printk(KERN_CONT "wr(");
printk(KERN_CONT "%02x): %02x ", chipaddr, addr);
#endif

/* in that case addr is the only value ->
* we write it twice as baseaddr and val0
* BBTI is doing it like that for ISL6421 at least */
if (i2c->no_base_addr && len == 0 && op == FC_WRITE) {
buf = &addr;
buf = &start_addr;
len = 1;
}

p = buf;

while (len != 0) {
bytes_to_transfer = len > 4 ? 4 : len;

r100.tw_sm_c_100.total_bytes = bytes_to_transfer - 1;
r100.tw_sm_c_100.baseaddr = addr;

if (op == FC_READ)
ret = flexcop_i2c_read4(i2c, r100, buf);
ret = flexcop_i2c_read4(i2c, r100, p);
else
ret = flexcop_i2c_write4(i2c->fc, r100, buf);

#ifdef DUMP_I2C_MESSAGES
for (i = 0; i < bytes_to_transfer; i++)
printk(KERN_CONT "%02x ", buf[i]);
#endif
ret = flexcop_i2c_write4(i2c->fc, r100, p);

if (ret < 0)
return ret;

buf += bytes_to_transfer;
p += bytes_to_transfer;
addr += bytes_to_transfer;
len -= bytes_to_transfer;
}

#ifdef DUMP_I2C_MESSAGES
printk(KERN_CONT "\n");
#endif
deb_i2c_dump("port %d %s(%02x): register %02x: %*ph\n",
i2c->port,
op == FC_READ ? "rd" : "wr",
chipaddr, start_addr, size, buf);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/common/b2c2/flexcop.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int b2c2_flexcop_debug;
EXPORT_SYMBOL_GPL(b2c2_flexcop_debug);
module_param_named(debug, b2c2_flexcop_debug, int, 0644);
MODULE_PARM_DESC(debug,
"set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg (|-able))."
"set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg,64=i2cdump (|-able))."
DEBSTATUS);
#undef DEBSTATUS

Expand Down
1 change: 1 addition & 0 deletions drivers/media/common/b2c2/flexcop.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ extern int b2c2_flexcop_debug;
#define deb_ts(args...) dprintk(0x08, args)
#define deb_sram(args...) dprintk(0x10, args)
#define deb_rdump(args...) dprintk(0x20, args)
#define deb_i2c_dump(args...) dprintk(0x40, args)

#endif

0 comments on commit 25d4aff

Please sign in to comment.