[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <656ca826-cb81-4b46-8e15-ec0b1044db8d@stanley.mountain>
Date: Thu, 14 Nov 2024 11:41:25 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Su Hui <suhui@...china.com>
Cc: stuyoder@...il.com, laurentiu.tudor@....com, nathan@...nel.org,
ndesaulniers@...gle.com, morbo@...gle.com, justinstitt@...gle.com,
gregkh@...uxfoundation.org, linux-kernel@...r.kernel.org,
llvm@...ts.linux.dev, kernel-janitors@...r.kernel.org
Subject: Re: [PATCH] bus: fsl-mc: Fix the double free in fsl_mc_device_add()
On Thu, Nov 14, 2024 at 04:27:52PM +0800, Su Hui wrote:
> Clang static checker(scan-build) warning:
> drivers/bus/fsl-mc/fsl-mc-bus.c: line 909, column 2
> Attempt to free released memory.
>
> When 'obj_desc->type' == "dprc" and begin to free 'mc_bus' and 'mc_dev',
> there is a double free problem because of 'mc_dev = &mc_bus->mc_dev'.
> Add a judgment to fix this problem.
>
> Fixes: a042fbed0290 ("staging: fsl-mc: simplify couple of deallocations")
> Signed-off-by: Su Hui <suhui@...china.com>
> ---
> drivers/bus/fsl-mc/fsl-mc-bus.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
> index 930d8a3ba722..8d2d5d3cc782 100644
> --- a/drivers/bus/fsl-mc/fsl-mc-bus.c
> +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
> @@ -905,8 +905,10 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
>
> error_cleanup_dev:
> kfree(mc_dev->regions);
> - kfree(mc_bus);
> - kfree(mc_dev);
> + if (strcmp(mc_dev->obj_desc.type, "dprc") == 0)
This works, but it would probably be nicer to write this as:
if (is_fsl_mc_bus_dprc(mc_dev))
kfree(mc_bus);
else
kfree(mc_dev);
That way it would match the release function.
regards,
dan carpenter
Powered by blists - more mailing lists