Currently the nvmem memory is freed without removing/unregister the nvmem->dev if nvmem_register_cdev() fails. Fix this by unregister the device first, free the memory and return the error code. Signed-off-by: Marco Felsch <m.felsch@xxxxxxxxxxxxxx> --- v2: - new patch drivers/nvmem/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index bf393fc180ab..fe93a2ca5f48 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -234,15 +234,19 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (!config->cdev) { rval = nvmem_register_cdev(nvmem, config->name); - if (rval) { - kfree(nvmem); - return ERR_PTR(rval); - } + if (rval) + goto err_unregister; } list_add_tail(&nvmem->node, &nvmem_devs); return nvmem; + +err_unregister: + unregister_device(&nvmem->dev); + kfree(nvmem); + + return ERR_PTR(rval); } EXPORT_SYMBOL_GPL(nvmem_register); -- 2.39.2