Skip to contentSkip to conversation

cmd: eeprom: Zero-initialize eeprom_dev_spec

PATCH In review Aksel Lunde Aase 2 participants 2 messages Oct 15 – Oct 28

lore
Share & tools
lore
#0 lore raw

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 1000

This 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.

Fixes 57a9e8d86fde ("cmd: eeprom: Extend to EEPROMs probed via driver model")
Cc Marek Behún <[email protected]>
---
 cmd/eeprom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/eeprom.c +1 -1
index cf89cfce3e4..7998a7c05c8 100644
@@ -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]>
#1 lore raw
Quoted 5 lines · Aksel Lunde Aase

With CONFIG_I2C_EEPROM enabled, 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_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.

[...]

Applied to u-boot/main, thanks!

[1/1] cmd: eeprom: Zero-initialize eeprom_dev_spec

      commit: d11e0b30ec96a1307e6238f28a1252d715e1e896
Signature · 1 line
Tom