]> git.itanic.dy.fi Git - linux-stable/commitdiff
nvmem: core: fix cell removal on error
authorMichael Walle <michael@walle.cc>
Fri, 27 Jan 2023 10:40:13 +0000 (10:40 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 28 Jan 2023 13:38:49 +0000 (14:38 +0100)
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: fa72d847d68d7 ("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>
drivers/nvmem/core.c

index cbe5df99db82333bdcb116279c841a8234db985e..563116405b3df51eca956ad915a74eb388e8aa87 100644 (file)
@@ -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: