lkml.org 
[lkml]   [2020]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2 2/7] nvmem: fix another memory leak in error path
From
Date


On 18/02/2020 09:42, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> The nvmem struct is only freed on the first error check after its
> allocation and leaked after that. Fix it with a new label.
>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

looks like 1/7 introduced the bug and 2/7 fixes it.
IMO, you should 1/7 and 2/7 should be single patch.

--srini

> ---
> drivers/nvmem/core.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index b0be03d5f240..c9b3f4047154 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -343,10 +343,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
> return ERR_PTR(-ENOMEM);
>
> rval = ida_simple_get(&nvmem_ida, 0, 0, GFP_KERNEL);
> - if (rval < 0) {
> - kfree(nvmem);
> - return ERR_PTR(rval);
> - }
> + if (rval < 0)
> + goto err_free_nvmem;
> if (config->wp_gpio)
> nvmem->wp_gpio = config->wp_gpio;
> else
> @@ -432,6 +430,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
> put_device(&nvmem->dev);
> err_ida_remove:
> ida_simple_remove(&nvmem_ida, nvmem->id);
> +err_free_nvmem:
> + kfree(nvmem);
>
> return ERR_PTR(rval);
> }
>

\
 
 \ /
  Last update: 2020-02-18 10:48    [W:0.071 / U:0.788 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site