From: Michael Walle Date: Fri, 27 Jan 2023 10:40:13 +0000 (+0000) Subject: nvmem: core: fix cell removal on error X-Git-Tag: baikal/aarch64/sdk6.1~21 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=76cb940e57a184724b63d7862959c8aa8e07d64c;p=kernel.git nvmem: core: fix cell removal on error commit db3546d58b5a0fa581d9c9f2bdc2856fa6c5e43e upstream. nvmem_add_cells() could return an error after some cells are already added to the provider. In this case, the added cells are not removed. Remove any registered cells if nvmem_add_cells() fails. Fixes: 800431f5fa423 ("nvmem: check the return value of nvmem_add_cells()") Cc: stable@vger.kernel.org Signed-off-by: Michael Walle Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20230127104015.23839-9-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index cbe5df99db823..563116405b3df 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -847,7 +847,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); if (rval) - goto err_teardown_compat; + goto err_remove_cells; } rval = nvmem_add_cells_from_table(nvmem); @@ -870,7 +870,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); -err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: