cmd: eeprom: Zero-initialize eeprom_dev_spec
PATCH 1/1 cmd: eeprom: Zero-initialize eeprom_dev_spec
With CONFIG_I2C_EEPROM enabled, passing both bus and address to the eeprom command causes a data abort:
eeprom write 0 52 ${loadaddr} 0 1000This is due to the eeprom_dev_spec in do_eeprom() being partially uninitialized. When given a bus and address, parse_eeprom_dev_spec() sets i2c_bus and i2c_addr but never assigns dev->dev. eeprom_dev_spec_write() then sees a non-NULL dev->dev and calls i2c_eeprom_write() with a garbage udevice pointer. Reads are affected the same way.
Zero-initialize the struct so that dev->dev is NULL unless a driver model device was actually found.
--- cmd/eeprom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/eeprom.c +1 -1
@@ -449,7 +449,7 @@ static int eeprom_action_expected_argc(enum eeprom_action action)int do_eeprom (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]) {enum eeprom_action action =EEPROM_ACTION_INVALID ; -struct eeprom_dev_spec dev; +struct eeprom_dev_spec dev = {};ulong addr =0 , cnt =0 , off =0 ;int ret, index =0 ;#ifdef CONFIG_CMD_EEPROM_LAYOUT
---
base-commit: 32ebe922e574a733d01c3f106fa77d9176bfecad
change-id: 20261014-eeprom-zero-init-cbf3df5d52ce
Best regards,
Signature · 1 line
Aksel Lunde Aase <[email protected]>
Quoted 5 lines · Aksel Lunde Aase
With
CONFIG_I2C_EEPROMenabled, passing both bus and address to the eeprom command causes a data abort:eeprom write 0 52 ${loadaddr} 0 1000
Quoted 8 lines
This is due to the
eeprom_dev_specindo_eeprom()being partially uninitialized. When given a bus and address,parse_eeprom_dev_spec()setsi2c_busandi2c_addrbut never assignsdev->dev.eeprom_dev_spec_write()then sees a non-NULLdev->devand callsi2c_eeprom_write()with a garbage udevice pointer. Reads are affected the same way.[...]
Applied to u-boot/main, thanks!
[1/1] cmd: eeprom: Zero-initialize eeprom_dev_spec
commit: d11e0b30ec96a1307e6238f28a1252d715e1e896
Signature · 1 line
Tom