[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aXSjPNWzsEPhYhv6@stanley.mountain>
Date: Sat, 24 Jan 2026 13:47:24 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Haoxiang Li <lihaoxiang@...c.iscas.ac.cn>
Cc: ioana.ciornei@....com, stuart.yoder@...escale.com, agraf@...e.de,
German.Rivera@...escale.com, gregkh@...uxfoundation.org,
linuxppc-dev@...ts.ozlabs.org, linux-kernel@...r.kernel.org,
stable@...r.kernel.org, Su Hui <suhui@...china.com>,
Christophe Leroy <chleroy@...nel.org>
Subject: Re: [PATCH v3] bus: fsl-mc: fix an error handling in
fsl_mc_device_add()
On Sat, Jan 24, 2026 at 06:20:54PM +0800, Haoxiang Li wrote:
> In fsl_mc_device_add(), device_initialize() is called first.
> put_device() should be called to drop the reference if error
> occurs. And other resources would be released via put_device
> -> fsl_mc_device_release. So remove redundant kfree() in
> error handling path.
>
It is true that we shouldn't free things directly after calling
device_initialize(). I don't know the impact of this bug in
real life. Is it a leak?
> Fixes: bbf9d17d9875 ("staging: fsl-mc: Freescale Management Complex (fsl-mc) bus driver")
> Cc: stable@...r.kernel.org
> Reported-by: Dan Carpenter <dan.carpenter@...aro.org>
> Closes: https://lore.kernel.org/all/b767348e-d89c-416e-acea-1ebbff3bea20@stanley.mountain/
Heh. What was I even talking about when I wrote this???
In my head I remember the code as looking like this:
https://lore.kernel.org/all/20251222074958.992911-1-lihaoxiang@isrc.iscas.ac.cn/
But that's not the version of the code that I copy and pasted into my
email.
The release function looks like this:
drivers/bus/fsl-mc/fsl-mc-bus.c
757 static void fsl_mc_device_release(struct device *dev)
758 {
759 struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
760
761 kfree(mc_dev->regions);
762
763 if (is_fsl_mc_bus_dprc(mc_dev))
764 kfree(to_fsl_mc_bus(mc_dev));
765 else
766 kfree(mc_dev);
767 }
The problem is that if this function call fails:
mc_dev->dev.type = fsl_mc_get_device_type(obj_desc->type);
Then the is_fsl_mc_bus_dprc() check might not work. In the current
code the to_fsl_mc_bus() pointer math is a no-op because mc_dev is
the first struct member of mc_bus. So it works for now, but it
feels wrong.
The fsl_mc_get_device_type() function can't really fail in real
life.
regards,
dan carpenter
Powered by blists - more mailing lists