Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: eeprom: at24: register nvmem only after eeprom is ready to use

During nvmem_register() the nvmem core sends notifications when:

- cell added
- nvmem added

and during these notifications some callback func may access the nvmem
device, which will fail in case of at24 eeprom because regulator and pm
are enabled after nvmem_register().

Fixes: cd5676db0574 ("misc: eeprom: at24: support pm_runtime control")
Fixes: b20eb4c1f026 ("eeprom: at24: drop unnecessary label")
Cc: stable@vger.kernel.org
Signed-off-by: Vadym Kochan <vadym.kochan@plvision.eu>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

authored by

Vadym Kochan and committed by
Bartosz Golaszewski
45df80d7 9123e3a7

+7 -4
+7 -4
drivers/misc/eeprom/at24.c
··· 692 692 nvmem_config.word_size = 1; 693 693 nvmem_config.size = byte_len; 694 694 695 - at24->nvmem = devm_nvmem_register(dev, &nvmem_config); 696 - if (IS_ERR(at24->nvmem)) 697 - return PTR_ERR(at24->nvmem); 698 - 699 695 i2c_set_clientdata(client, at24); 700 696 701 697 err = regulator_enable(at24->vcc_reg); ··· 703 707 /* enable runtime pm */ 704 708 pm_runtime_set_active(dev); 705 709 pm_runtime_enable(dev); 710 + 711 + at24->nvmem = devm_nvmem_register(dev, &nvmem_config); 712 + if (IS_ERR(at24->nvmem)) { 713 + pm_runtime_disable(dev); 714 + regulator_disable(at24->vcc_reg); 715 + return PTR_ERR(at24->nvmem); 716 + } 706 717 707 718 /* 708 719 * Perform a one-byte test read to verify that the