[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <fze2ujtmyqnvtoorn6xqsgcvd4vgwqpvn3brqxy4xr5k2ayytc@hbeh53dmybt4>
Date: Wed, 11 Sep 2024 21:46:22 +0200
From: Markus Schneider-Pargmann <msp@...libre.com>
To: Ruihai Zhou <zhou.ruihai@...com>
Cc: srinivas.kandagatla@...aro.org, gregkh@...uxfoundation.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] nvmem: core: Fix memleak in nvmem_add_cells_from_dt
error path
On Wed, Sep 11, 2024 at 08:06:55PM GMT, Ruihai Zhou wrote:
> In the nvmem_add_cells_from_dt(), if the devicetree 'bits' property
> is outside of the valid range, the info.name alloc by kasprintf will
> cause memleak. Just free before return from nvmem_add_cells_from_dt
> in the error path.
Thanks for spotting and fixing this.
Alternative to addding a kfree() I think the info.name allocation can be
moved down behind the if-block so it can't leak when returning inside of
the nested if block.
Both is fine for me.
Reviewed-by: Markus Schneider-Pargmann <msp@...libre.com>
Best
Markus
>
> Fixes: def3173d4f17 ("nvmem: core: Print error on wrong bits DT property")
> Signed-off-by: Ruihai Zhou <zhou.ruihai@...com>
> ---
> drivers/nvmem/core.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 516dfd861b9f..ce71bee5e1a9 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -826,6 +826,7 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod
> info.nbits = be32_to_cpup(addr);
> if (info.bit_offset >= BITS_PER_BYTE || info.nbits < 1) {
> dev_err(dev, "nvmem: invalid bits on %pOF\n", child);
> + kfree(info.name);
> of_node_put(child);
> return -EINVAL;
> }
> --
> 2.31.1
>
Powered by blists - more mailing lists