From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
To: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
Cc: alex.bou9@gmail.com, linux-kernel@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, maddy@linux.ibm.com,
mpe@ellerman.id.au, mporter@kernel.crashing.org,
npiggin@gmail.com
Subject: Re: [PATCH] powerpc/fsl_rio: fix a improper release in fsl_rio_setup()
Date: Sat, 20 Dec 2025 19:01:32 +0100 [thread overview]
Message-ID: <aeab7b8c-cc9a-4db8-a36b-f54b842d3c18@kernel.org> (raw)
In-Reply-To: <20251220134230.712676-1-lihaoxiang@isrc.iscas.ac.cn>
Le 20/12/2025 à 14:42, Haoxiang Li a écrit :
> [Vous ne recevez pas souvent de courriers de lihaoxiang@isrc.iscas.ac.cn. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
>
> On Sat, 20 Dec 2025 11:45:10 +0100, Christophe Leroy wrote:
>> Your explanation is unclear. It is correct that put_device() is the
>> correct way to drop the device reference, and it is already what
>> rio_register_mport() does. Why do you need to move it out of
>> rio_register_mport() ? This is what you have to explain.
>
> Sorry for the unclear changelog. I think if device_register() in
> rio_register_mport() fails, put_device() is already called. Then,
> the error path in fsl_rio_setup() also kfree() the port. I suspected
> a potential double-free issue here, although I am unsure whether this interpretation is correct.
The put_device() in rio_register_mport() releases the reference to
port->dev taken by device_register(). See the documentation in
https://elixir.bootlin.com/linux/v6.18/source/drivers/base/core.c#L3750
The kfree(port) in fsl_rio_setup() is to free the memory allocated by
the kzalloc() at
https://elixir.bootlin.com/linux/v6.18/source/arch/powerpc/sysdev/fsl_rio.c#L583
Those are two independant things.
>
>> AI code review or human code review ?
>
> Human review.
>
>> Why do you remove this kfree() ? By doing this you will leak the port
>> pointer allocated earlier in the loop by kzalloc()
>
> I just thought after device_register(), the cleanup should be done by
> put_device().
You are talking about the cleanup of port->dev. Once you have cleaned up
port->dev you also have to cleanup port.
>
> I would appreciate your clarification.
See above.
I might be wrong but from my point of view the existing code is correct.
Christophe
prev parent reply other threads:[~2025-12-20 18:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-19 14:10 Haoxiang Li
2025-12-20 10:45 ` Christophe Leroy (CS GROUP)
2025-12-20 13:42 ` Haoxiang Li
2025-12-20 18:01 ` Christophe Leroy (CS GROUP) [this message]
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=aeab7b8c-cc9a-4db8-a36b-f54b842d3c18@kernel.org \
--to=chleroy@kernel.org \
--cc=alex.bou9@gmail.com \
--cc=lihaoxiang@isrc.iscas.ac.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=mporter@kernel.crashing.org \
--cc=npiggin@gmail.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®