Message ID | 20200219092218.18143-2-brgl@bgdev.pl |
---|---|
State | New |
Headers | show |
Series | [v3,1/7] nvmem: fix memory leak in error path | expand |
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index ef326f243f36..89974e40d250 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -352,8 +352,11 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) else nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); - if (IS_ERR(nvmem->wp_gpio)) - return ERR_CAST(nvmem->wp_gpio); + if (IS_ERR(nvmem->wp_gpio)) { + ida_simple_remove(&nvmem_ida, nvmem->id); + kfree(nvmem); + return ERR_PTR(rval); + } kref_init(&nvmem->refcnt);