I2C updates for 2.4.28
Hi Marcelo, hi all,
I have a number of I2C updates for 2.4.28 waiting. All of them are rather small and independent, gathered during the 2.4.27 cycle as user reported problems and we fixed them in i2c CVS.
Individual patches follow, please apply.
Thanks.
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
PATCH 1/1 I2C updates for 2.4.28 (1/5)
Original report and discussion:
http://archives.andrew.net.au/lm-sensors/msg18839.html
Bottom line:i2c_register_entry shouldn't rely on the procname field to detect the end of the control table, but on the ctl_name field. The latter is guaranteed to be non-zero except for the table terminator, the former can be null even in the middle of the table.
The bug wasn't caught so far because all users of this function (basically the lm_sensors project's drivers) were exporting all entries through /proc so procname was never null (except for the table terminator, obviously).
Credits go to Louis-Martin Cote for discovering the bug and proposing a fix.
drivers/i2c/i2c-proc.c renamed from drivers/i2c/i2c-proc.c.orig +1 -1
@@ -152,7 +152,7 @@ id +=256 ; len =0 ; -while (ctl_template[len].procname) +while (ctl_template[len].ctl_name) len++; len +=7 ;if (!(new_table =kmalloc (sizeof (ctl_table) * len,GFP_KERNEL ))) {
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
PATCH 1/1 I2C updates for 2.4.28 (2/5)
In reply to Jean DelvareOriginal report and discussion:
http://archives.andrew.net.au/lm-sensors/msg28053.html
Bottom line:
The real parser in i2c-proc is partly broken, but in a way it will go unnoticed in most cases (thus unspotted so far). Still worth fixing IMHO.
drivers/i2c/i2c-proc.c renamed from drivers/i2c/i2c-proc.c.orig +1 -1
@@ -540,7 +540,7 @@/* Skip everything until we hit whitespace */ while (bufsize && !((ret=get_user (nextchar, (char *) buffer))) && -isspace ((int ) nextchar)) { + !isspace ((int ) nextchar)) { bufsize--; ((char *) buffer)++; }
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
PATCH 1/1 I2C updates for 2.4.28 (3/5)
In reply to Jean DelvareOriginal report and discussion:
http://marc.theaimsgroup.com/?l=linux-arm-kernel&m=109816546827995&w=2
http://marc.theaimsgroup.com/?l=linux-arm-kernel&m=109926079025024&w=2
Bottom line:
Two hardcoded buffer sizes in i2c_smbus_xfer_emulated (i2c-core) should depend on I2C_SMBUS_BLOCK_MAX. Else increasing I2C_SMBUS_BLOCK_MAX (in include/linux/i2c.h) will result in buffer overflows.
Credits go to Tehn Yit Chin for noticing the suspicious hardcoded values.
drivers/i2c/i2c-core.c renamed from drivers/i2c/i2c-core.c.orig +2 -2
@@ -1098,8 +1098,8 @@need to use only one message; when reading, we need two. We initialize most things with sane defaults, to keep the code below somewhat simpler. */ -unsigned char msgbuf0[34 ]; -unsigned char msgbuf1[34 ]; +unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX +2 ]; +unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX +2 ];int num = read_write ==I2C_SMBUS_READ ?2 :1 ;struct i2c_msg msg[2 ] = { { addr, flags,1 , msgbuf0 }, { addr, flags |I2C_M_RD ,0 , msgbuf1 }
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
PATCH 1/1 I2C updates for 2.4.28 (5/5)
In reply to Jean DelvareOriginal report and discussion:
http://archives.andrew.net.au/lm-sensors/msg28295.html
Bottom line:
Some debug messages in the i2c-core lack their trailing newline, which breaks the logs.
drivers/i2c/i2c-core.c renamed from drivers/i2c.orig/i2c-core.c +1 -1
@@ -901,7 +901,7 @@if (addr == address_data->normal_i2c[i]) { found =1 ;DEB2 (printk (KERN_DEBUG "i2c-core.o: found normal i2c entry for adapter %d, " -"addr %02x" , adap_id,addr)); +"addr %02x\n" , adap_id, addr)); } }
drivers/i2c/i2c-proc.c renamed from drivers/i2c.orig/i2c-proc.c +2 -2
@@ -762,7 +762,7 @@#ifdef DEBUG printk (KERN_DEBUG "i2c-proc.o: found normal isa_range entry for adapter %d, " -"addr %04x" , adapter_id, addr); +"addr %04x\n" , adapter_id, addr);#endif found =1 ; }
@@ -776,7 +776,7 @@#ifdef DEBUG printk (KERN_DEBUG "i2c-proc.o: found normal i2c entry for adapter %d, " -"addr %02x" , adapter_id, addr); +"addr %02x\n" , adapter_id, addr);#endif } }
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/