public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
To: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
Cc: dan.carpenter@linaro.org, ioana.ciornei@nxp.com,
	linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	suhui@nfschina.com
Subject: Re: [PATCH] bus: fsl-mc: fix an error handling in fsl_mc_device_add()
Date: Wed, 24 Dec 2025 12:07:22 +0100	[thread overview]
Message-ID: <b7f7e968-a683-4e1e-8ccc-5dd19f0f15c5@kernel.org> (raw)
In-Reply-To: <20251224105240.1588158-1-lihaoxiang@isrc.iscas.ac.cn>



Le 24/12/2025 à 11:52, Haoxiang Li a écrit :
> On Wed, 24 Dec 2025 10:57:52 +0100, Christophe Leroy wrote:
>> Ok, then this needs to be said in the commit message.
> 
> I will add it in the patch v2.
> 
>> 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
> 
> I think this is because device_add() increment the reference in the
> beginning, see
> https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/base/core.c#L3580
> and if device_add() fails, another put_device() should be called to decrement
> the reference which is obtained by device_initialize().

Ah yes, I see.

But then all exit paths in fsl_mc_device_add() after device_initialize() 
should call put_device() ?

Then in fact the fix should instead be the following, shouldn't it ?

diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c 
b/drivers/bus/fsl-mc/fsl-mc-bus.c
index 25845c04e562..6d132144ce25 100644
--- a/drivers/bus/fsl-mc/fsl-mc-bus.c
+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
@@ -905,11 +905,7 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
  	return 0;

  error_cleanup_dev:
-	kfree(mc_dev->regions);
-	if (mc_bus)
-		kfree(mc_bus);
-	else
-		kfree(mc_dev);
+	put_device(&mc_dev->dev);

  	return error;
  }


  reply	other threads:[~2025-12-24 11:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-22  7:49 [PATCH] bus: fsl-mc: fix an error handling in fsl_mc_device_add() 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)
2025-12-24 10:52       ` Haoxiang Li
2025-12-24 11:07         ` Christophe Leroy (CS GROUP) [this message]
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=b7f7e968-a683-4e1e-8ccc-5dd19f0f15c5@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