From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>,
ioana.ciornei@nxp.com, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org, Su Hui <suhui@nfschina.com>
Subject: Re: [PATCH] bus: fsl-mc: fix an error handling in fsl_mc_device_add()
Date: Wed, 24 Dec 2025 10:57:52 +0100 [thread overview]
Message-ID: <ad465fd1-4b5a-4fa1-b4fc-1ca7bd6fe5b4@kernel.org> (raw)
In-Reply-To: <aUucPsDoPQJE5Ucj@stanley.mountain>
Le 24/12/2025 à 08:54, Dan Carpenter a écrit :
> On Tue, Dec 23, 2025 at 04:34:44PM +0100, Christophe Leroy (CS GROUP) wrote:
>>
>>
>> Le 22/12/2025 à 08:49, Haoxiang Li a écrit :
>>> If device_add() fails, call put_device() to drop the device
>>> reference and do the cleanp.
>>>
>>> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
>>> Closes: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2Fb767348e-d89c-416e-acea-1ebbff3bea20%40stanley.mountain%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cfd3865935a164c2083cc08de42c1b5a5%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C639021596902232212%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=j5%2BqptzXvrxcnaaH3PIDorAYMexoPmf3PWi5GbpVD9s%3D&reserved=0
>>> Signed-off-by: Su Hui <suhui@nfschina.com>
>>> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
>>> ---
>>> drivers/bus/fsl-mc/fsl-mc-bus.c | 3 ++-
>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
>>> index 25845c04e562..90a2107a9905 100644
>>> --- a/drivers/bus/fsl-mc/fsl-mc-bus.c
>>> +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
>>> @@ -896,7 +896,8 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
>>> dev_err(parent_dev,
>>> "device_add() failed for device %s: %d\n",
>>> dev_name(&mc_dev->dev), error);
>>> - goto error_cleanup_dev;
>>> + put_device(&mc_dev->dev)
>>
>> This change has obviously not been tested, not even built.
>>
>
> Yeah, it doesn't build.
>
>> And by droping the goto, the kfree() are not done anymore, leaking
>> mc_bus/mc_dev p kzalloced areas.
>>
>
> Calling put_device() triggers fsl_mc_device_release() which does the
> free.
Ok, then this needs to be said in the commit message.
By the way I'm a bit puzzled by the device_add() doc versus the
put_device(), because it looks like device_add() already calls
put_device() in its error path, see
https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/base/core.c#L3716
>
> regards,
> dan carpenter
>
>>> + return error;
>>> }
>>> dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev));
next prev parent reply other threads:[~2025-12-24 9:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-22 7:49 Haoxiang Li
2025-12-22 23:13 ` kernel test robot
2025-12-23 15:23 ` kernel test robot
2025-12-23 15:34 ` Christophe Leroy (CS GROUP)
2025-12-24 7:54 ` Dan Carpenter
2025-12-24 9:57 ` Christophe Leroy (CS GROUP) [this message]
2025-12-24 10:52 ` Haoxiang Li
2025-12-24 11:07 ` Christophe Leroy (CS GROUP)
2025-12-24 11:26 ` Haoxiang Li
2025-12-26 9:39 ` Dan Carpenter
2025-12-26 9:35 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ad465fd1-4b5a-4fa1-b4fc-1ca7bd6fe5b4@kernel.org \
--to=chleroy@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=ioana.ciornei@nxp.com \
--cc=lihaoxiang@isrc.iscas.ac.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=suhui@nfschina.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®