Skip to content

Commit

Permalink
nvmem: core: fix cell removal on error
Browse files Browse the repository at this point in the history
commit db3546d 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: fa72d84 ("nvmem: check the return value of nvmem_add_cells()")
Cc: stable@vger.kernel.org
Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230127104015.23839-9-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
mwalle authored and gregkh committed Feb 9, 2023
1 parent d78f5d4 commit 1dcd68c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/nvmem/core.c
Expand Up @@ -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);
Expand All @@ -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:
Expand Down

0 comments on commit 1dcd68c

Please sign in to comment.