FAILED: patch "[PATCH] nvmem: core: fix registration vs use race" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
Possible dependencies:
ab3428cfd9aa ("nvmem: core: fix registration vs use race")560181d3ace6 ("nvmem: core: fix cleanup after dev_set_name()") 569653f022a2 ("nvmem: core: remove nvmem_config wp_gpio")3bd747c7ea13 ("nvmem: core: initialise nvmem->id early")5544e90c8126 ("nvmem: core: add error handling for dev_set_name") bd1244561fa2 ("nvmem: core: Fix memleak in nvmem_register()") f6c052afe6f8 ("nvmem: core: Fix a conflict between MTD and NVMEM on wp-gpios property") de0534df9347 ("nvmem: core: fix error handling while validating keepout regions") 1333a6779501 ("nvmem: core: allow specifying of_node")fd3bb8f54a88 ("nvmem: core: Add support for keepout regions")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ab3428cfd9aa2f3463ee4b2909b5bb2193bd0c4a Mon Sep 17 00:00:00 2001
From: "Russell King (Oracle)" <[email protected]>
Date: Fri, 27 Jan 2023 10:40:11 +0000
Subject: [PATCH] nvmem: core: fix registration vs use race
The i.MX6 CPU frequency driver sometimes fails to register at boot time due to nvmem_cell_read_u32() sporadically returning -ENOENT.
This happens because there is a window where __nvmem_device_get() in of_nvmem_cell_get() is able to return the nvmem device, but as cells have been setup, nvmem_find_cell_entry_by_node() returns NULL.
The occurs because the nvmem core registration code violates one of the fundamental principles of kernel programming: do not publish data structures before their setup is complete.
Fix this by making nvmem core code conform with this principle.
drivers/nvmem/core.c +8 -10
@@ -832,22 +832,16 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->dev.groups = nvmem_dev_groups;#endif -dev_dbg (&nvmem->dev,"Registering nvmem device %s\n" , config->name); - - rval =device_add (&nvmem->dev); -if (rval) - goto err_put_device; -if (nvmem->nkeepout) { rval =nvmem_validate_keepouts (nvmem);if (rval) - goto err_device_del; + goto err_put_device; }if (config->compat) { rval =nvmem_sysfs_setup_compat (nvmem, config);if (rval) - goto err_device_del; + goto err_put_device; }if (config->cells) {
@@ -864,6 +858,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)if (rval) goto err_remove_cells; +dev_dbg (&nvmem->dev,"Registering nvmem device %s\n" , config->name); + + rval =device_add (&nvmem->dev); +if (rval) + goto err_remove_cells; +blocking_notifier_call_chain (&nvmem_notifier,NVMEM_ADD , nvmem);return nvmem;
@@ -873,8 +873,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_teardown_compat:if (config->compat)nvmem_sysfs_remove_compat (nvmem, config); -err_device_del: -device_del (&nvmem->dev); err_put_device:put_device (&nvmem->dev);