Skip to content

Commit f42c970

Browse files
Daniel OkazakiBartosz Golaszewski
authored andcommitted
eeprom: at24: fix memory corruption race condition
If the eeprom is not accessible, an nvmem device will be registered, the read will fail, and the device will be torn down. If another driver accesses the nvmem device after the teardown, it will reference invalid memory. Move the failure point before registering the nvmem device. Signed-off-by: Daniel Okazaki <dtokazaki@google.com> Fixes: b20eb4c ("eeprom: at24: drop unnecessary label") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240422174337.2487142-1-dtokazaki@google.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent b3de7b4 commit f42c970

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/misc/eeprom/at24.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -758,15 +758,6 @@ static int at24_probe(struct i2c_client *client)
758758
}
759759
pm_runtime_enable(dev);
760760

761-
at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
762-
if (IS_ERR(at24->nvmem)) {
763-
pm_runtime_disable(dev);
764-
if (!pm_runtime_status_suspended(dev))
765-
regulator_disable(at24->vcc_reg);
766-
return dev_err_probe(dev, PTR_ERR(at24->nvmem),
767-
"failed to register nvmem\n");
768-
}
769-
770761
/*
771762
* Perform a one-byte test read to verify that the chip is functional,
772763
* unless powering on the device is to be avoided during probe (i.e.
@@ -782,6 +773,15 @@ static int at24_probe(struct i2c_client *client)
782773
}
783774
}
784775

776+
at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
777+
if (IS_ERR(at24->nvmem)) {
778+
pm_runtime_disable(dev);
779+
if (!pm_runtime_status_suspended(dev))
780+
regulator_disable(at24->vcc_reg);
781+
return dev_err_probe(dev, PTR_ERR(at24->nvmem),
782+
"failed to register nvmem\n");
783+
}
784+
785785
/* If this a SPD EEPROM, probe for DDR3 thermal sensor */
786786
if (cdata == &at24_data_spd)
787787
at24_probe_temp_sensor(client);

0 commit comments

Comments
 (0)