[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b7f7e968-a683-4e1e-8ccc-5dd19f0f15c5@kernel.org>
Date: Wed, 24 Dec 2025 12:07:22 +0100
From: "Christophe Leroy (CS GROUP)" <chleroy@...nel.org>
To: Haoxiang Li <lihaoxiang@...c.iscas.ac.cn>
Cc: dan.carpenter@...aro.org, ioana.ciornei@....com,
linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
suhui@...china.com
Subject: Re: [PATCH] bus: fsl-mc: fix an error handling in fsl_mc_device_add()
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;
}
Powered by blists - more mailing lists