power_supply: fix up olpc_battery's eeprom read function
PATCH 2/5 power_supply: fix up olpc_battery's eeprom read function
The eeprom read function was placing values into the wrong place in 'buf'; we were starting from buf[off], rather than buf[0].
Also, the for loop that we were using was much uglier than it needed to be. This cleans it up a bit.
Signed-off-by Andres Salomon <[email protected]>
--- drivers/power/olpc_battery.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
drivers/power/olpc_battery.c +6 -8
@@ -343,21 +343,19 @@ static ssize_t olpc_bat_eeprom_read(struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { uint8_t ec_byte; -int ret, end; +int ret, i;if (off >=EEPROM_SIZE )return 0 ;if (off + count >EEPROM_SIZE ) count =EEPROM_SIZE - off; - end =EEPROM_START + off + count; -for (ec_byte =EEPROM_START + off; ec_byte < end; ec_byte++) { - ret =olpc_ec_cmd (EC_BAT_EEPROM , &ec_byte,1 , - &buf[ec_byte -EEPROM_START ],1 ); +for (i =0 ; i < count; i++) { + ec_byte =EEPROM_START + off + i; + ret =olpc_ec_cmd (EC_BAT_EEPROM , &ec_byte,1 , &buf[i],1 );if (ret) { -printk (KERN_ERR "olpc-battery: EC command " -"EC_BAT_EEPROM @ 0x%x failed -" -" %d!\n" , ec_byte, ret); +printk (KERN_ERR "olpc-battery: EC_BAT_EEPROM cmd @ 0x%x failed - %d!\n" , + ec_byte, ret);return -EIO ; } }
Signature · 1 line
1.5.6.5
Anton Vorontsov
AppliedQuoted 8 lines · Andres Salomon
The eeprom read function was placing values into the wrong place in 'buf'; we were starting from buf[off], rather than buf[0].
Also, the for loop that we were using was much uglier than it needed to be. This cleans it up a bit.
Signed-off-by Andres Salomon <[email protected]>
Applied to battery-2.6.31.git w/ some cosmtic changes. Please ensure that everything is OK.
Thanks!
Quoted 39 lines
--- drivers/power/olpc_battery.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)drivers/power/olpc_battery.c +6
-8@@ -343,21 +343,19 @@ static ssize_t olpc_bat_eeprom_read(struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { uint8_t ec_byte; -int ret, end; +int ret, i;if (off >=EEPROM_SIZE )return 0 ;if (off + count >EEPROM_SIZE ) count =EEPROM_SIZE - off; - end =EEPROM_START + off + count; -for (ec_byte =EEPROM_START + off; ec_byte < end; ec_byte++) { - ret =olpc_ec_cmd (EC_BAT_EEPROM , &ec_byte,1 , - &buf[ec_byte -EEPROM_START ],1 ); +for (i =0 ; i < count; i++) { + ec_byte =EEPROM_START + off + i; + ret =olpc_ec_cmd (EC_BAT_EEPROM , &ec_byte,1 , &buf[i],1 );if (ret) { -printk (KERN_ERR "olpc-battery: EC command " -"EC_BAT_EEPROM @ 0x%x failed -" -" %d!\n" , ec_byte, ret); +printk (KERN_ERR "olpc-battery: EC_BAT_EEPROM cmd @ 0x%x failed - %d!\n" , + ec_byte, ret);return -EIO ; } }Signature · 1 line
1.5.6.5
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2