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

media: flexcop-i2c: get rid of KERN_CONT

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>

authored by

Mauro Carvalho Chehab and committed by
Mauro Carvalho Chehab
25d4affb 366b4010

+21 -29
+19 -28
drivers/media/common/b2c2/flexcop-i2c.c
··· 105 105 } 106 106 107 107 int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c, 108 - flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len) 108 + flexcop_access_op_t op, u8 chipaddr, 109 + u8 start_addr, u8 *buf, u16 size) 109 110 { 110 111 int ret; 111 - 112 - #ifdef DUMP_I2C_MESSAGES 113 - int i; 114 - #endif 112 + int len = size; 113 + u8 *p; 114 + u8 addr = start_addr; 115 115 116 116 u16 bytes_to_transfer; 117 117 flexcop_ibi_value r100; 118 118 119 - deb_i2c("op = %d\n",op); 119 + deb_i2c("port %d %s(%02x): register %02x, size: %d\n", 120 + i2c->port, 121 + op == FC_READ ? "rd" : "wr", 122 + chipaddr, start_addr, size); 120 123 r100.raw = 0; 121 124 r100.tw_sm_c_100.chipaddr = chipaddr; 122 125 r100.tw_sm_c_100.twoWS_rw = op; 123 126 r100.tw_sm_c_100.twoWS_port_reg = i2c->port; 124 127 125 - #ifdef DUMP_I2C_MESSAGES 126 - printk(KERN_DEBUG "%d ", i2c->port); 127 - if (op == FC_READ) 128 - printk(KERN_CONT "rd("); 129 - else 130 - printk(KERN_CONT "wr("); 131 - printk(KERN_CONT "%02x): %02x ", chipaddr, addr); 132 - #endif 133 - 134 128 /* in that case addr is the only value -> 135 129 * we write it twice as baseaddr and val0 136 130 * BBTI is doing it like that for ISL6421 at least */ 137 131 if (i2c->no_base_addr && len == 0 && op == FC_WRITE) { 138 - buf = &addr; 132 + buf = &start_addr; 139 133 len = 1; 140 134 } 135 + 136 + p = buf; 141 137 142 138 while (len != 0) { 143 139 bytes_to_transfer = len > 4 ? 4 : len; ··· 142 146 r100.tw_sm_c_100.baseaddr = addr; 143 147 144 148 if (op == FC_READ) 145 - ret = flexcop_i2c_read4(i2c, r100, buf); 149 + ret = flexcop_i2c_read4(i2c, r100, p); 146 150 else 147 - ret = flexcop_i2c_write4(i2c->fc, r100, buf); 148 - 149 - #ifdef DUMP_I2C_MESSAGES 150 - for (i = 0; i < bytes_to_transfer; i++) 151 - printk(KERN_CONT "%02x ", buf[i]); 152 - #endif 151 + ret = flexcop_i2c_write4(i2c->fc, r100, p); 153 152 154 153 if (ret < 0) 155 154 return ret; 156 155 157 - buf += bytes_to_transfer; 156 + p += bytes_to_transfer; 158 157 addr += bytes_to_transfer; 159 158 len -= bytes_to_transfer; 160 159 } 161 - 162 - #ifdef DUMP_I2C_MESSAGES 163 - printk(KERN_CONT "\n"); 164 - #endif 160 + deb_i2c_dump("port %d %s(%02x): register %02x: %*ph\n", 161 + i2c->port, 162 + op == FC_READ ? "rd" : "wr", 163 + chipaddr, start_addr, size, buf); 165 164 166 165 return 0; 167 166 }
+1 -1
drivers/media/common/b2c2/flexcop.c
··· 42 42 EXPORT_SYMBOL_GPL(b2c2_flexcop_debug); 43 43 module_param_named(debug, b2c2_flexcop_debug, int, 0644); 44 44 MODULE_PARM_DESC(debug, 45 - "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg (|-able))." 45 + "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg,64=i2cdump (|-able))." 46 46 DEBSTATUS); 47 47 #undef DEBSTATUS 48 48
+1
drivers/media/common/b2c2/flexcop.h
··· 26 26 #define deb_ts(args...) dprintk(0x08, args) 27 27 #define deb_sram(args...) dprintk(0x10, args) 28 28 #define deb_rdump(args...) dprintk(0x20, args) 29 + #define deb_i2c_dump(args...) dprintk(0x40, args) 29 30 30 31 #endif