diff mbox series

[v5,09/21] nvmem: core: fix cell removal on error

Message ID 20221206200740.3567551-10-michael@walle.cc (mailing list archive)
State New, archived
Headers show
Series nvmem: core: introduce NVMEM layouts | expand

Commit Message

Michael Walle Dec. 6, 2022, 8:07 p.m. UTC
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.

Signed-off-by: Michael Walle <michael@walle.cc>
---
changes since v4:
 - new patch

 drivers/nvmem/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 7c76e0e0072e..70c3d0a20d0d 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -851,7 +851,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);
@@ -868,7 +868,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_device_del: