* [PATCH -next] net: pcs: Add missing put_device call in miic_create
@ 2023-08-07 13:47 Xiang Yang
2023-08-08 10:53 ` Vladimir Oltean
2023-08-08 10:54 ` Vladimir Oltean
0 siblings, 2 replies; 4+ messages in thread
From: Xiang Yang @ 2023-08-07 13:47 UTC (permalink / raw)
To: clement.leger, hkallweit1, linux, davem, edumazet, kuba, pabeni,
olteanv, f.fainelli
Cc: linux-renesas-soc, netdev, xiangyang3
From: Xiang Yang <xiangyang3@huawei.com>
The reference of pdev->dev is taken by of_find_device_by_node, so
it should be released when error out.
Fixes: 7dc54d3b8d91 ("net: pcs: add Renesas MII converter driver")
Signed-off-by: Xiang Yang <xiangyang3@huawei.com>
---
drivers/net/pcs/pcs-rzn1-miic.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c
index e5d642c67a2c..d097f123635a 100644
--- a/drivers/net/pcs/pcs-rzn1-miic.c
+++ b/drivers/net/pcs/pcs-rzn1-miic.c
@@ -318,8 +318,10 @@ struct phylink_pcs *miic_create(struct device *dev, struct device_node *np)
return ERR_PTR(-EPROBE_DEFER);
miic_port = kzalloc(sizeof(*miic_port), GFP_KERNEL);
- if (!miic_port)
+ if (!miic_port) {
+ put_device(&pdev->dev);
return ERR_PTR(-ENOMEM);
+ }
miic = platform_get_drvdata(pdev);
device_link_add(dev, miic->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next] net: pcs: Add missing put_device call in miic_create
2023-08-07 13:47 [PATCH -next] net: pcs: Add missing put_device call in miic_create Xiang Yang
@ 2023-08-08 10:53 ` Vladimir Oltean
2023-08-08 10:54 ` Vladimir Oltean
1 sibling, 0 replies; 4+ messages in thread
From: Vladimir Oltean @ 2023-08-08 10:53 UTC (permalink / raw)
To: Xiang Yang
Cc: clement.leger, hkallweit1, linux, davem, edumazet, kuba, pabeni,
f.fainelli, linux-renesas-soc, netdev, xiangyang3
On Mon, Aug 07, 2023 at 01:47:14PM +0000, Xiang Yang wrote:
> From: Xiang Yang <xiangyang3@huawei.com>
>
> The reference of pdev->dev is taken by of_find_device_by_node, so
> it should be released when error out.
>
> Fixes: 7dc54d3b8d91 ("net: pcs: add Renesas MII converter driver")
> Signed-off-by: Xiang Yang <xiangyang3@huawei.com>
> ---
Ok, but if of_find_device_by_node() requires a subsequent call to
put_device(), then doesn't this mean that in the non-error case, the
pdev refcount remains elevated, and will thus never be freed?
I would expect another put_device(&pdev->dev) after the device_link_add(),
which itself takes another set of references on the supplier and
consumer devs, which are sufficient for this driver's runtime operation.
Also, "if (!pdev)" and "if (!platform_get_drvdata(pdev)" here need
different treatment. One needs to call put_device(&pdev->dev) and the
other one doesn't.
pdev = of_find_device_by_node(pcs_np);
of_node_put(pcs_np);
if (!pdev || !platform_get_drvdata(pdev))
return ERR_PTR(-EPROBE_DEFER);
pw-bot: cr
> drivers/net/pcs/pcs-rzn1-miic.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c
> index e5d642c67a2c..d097f123635a 100644
> --- a/drivers/net/pcs/pcs-rzn1-miic.c
> +++ b/drivers/net/pcs/pcs-rzn1-miic.c
> @@ -318,8 +318,10 @@ struct phylink_pcs *miic_create(struct device *dev, struct device_node *np)
> return ERR_PTR(-EPROBE_DEFER);
>
> miic_port = kzalloc(sizeof(*miic_port), GFP_KERNEL);
> - if (!miic_port)
> + if (!miic_port) {
> + put_device(&pdev->dev);
> return ERR_PTR(-ENOMEM);
> + }
>
> miic = platform_get_drvdata(pdev);
> device_link_add(dev, miic->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] net: pcs: Add missing put_device call in miic_create
2023-08-07 13:47 [PATCH -next] net: pcs: Add missing put_device call in miic_create Xiang Yang
2023-08-08 10:53 ` Vladimir Oltean
@ 2023-08-08 10:54 ` Vladimir Oltean
2023-08-08 11:56 ` Xiang Yang
1 sibling, 1 reply; 4+ messages in thread
From: Vladimir Oltean @ 2023-08-08 10:54 UTC (permalink / raw)
To: Xiang Yang
Cc: clement.leger, hkallweit1, linux, davem, edumazet, kuba, pabeni,
f.fainelli, linux-renesas-soc, netdev, xiangyang3
On Mon, Aug 07, 2023 at 01:47:14PM +0000, Xiang Yang wrote:
> From: Xiang Yang <xiangyang3@huawei.com>
>
> The reference of pdev->dev is taken by of_find_device_by_node, so
> it should be released when error out.
>
> Fixes: 7dc54d3b8d91 ("net: pcs: add Renesas MII converter driver")
> Signed-off-by: Xiang Yang <xiangyang3@huawei.com>
> ---
Also, the patch subject prefix needs to be "[PATCH net]" (indicative of
the fact that you want it to go to https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git)
and not "[PATCH -next]".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] net: pcs: Add missing put_device call in miic_create
2023-08-08 10:54 ` Vladimir Oltean
@ 2023-08-08 11:56 ` Xiang Yang
0 siblings, 0 replies; 4+ messages in thread
From: Xiang Yang @ 2023-08-08 11:56 UTC (permalink / raw)
To: Vladimir Oltean
Cc: clement.leger, hkallweit1, linux, davem, edumazet, kuba, pabeni,
f.fainelli, linux-renesas-soc, netdev, xiangyang3
在 2023/8/8 18:54, Vladimir Oltean 写道:
> On Mon, Aug 07, 2023 at 01:47:14PM +0000, Xiang Yang wrote:
>> From: Xiang Yang <xiangyang3@huawei.com>
>>
>> The reference of pdev->dev is taken by of_find_device_by_node, so
>> it should be released when error out.
>>
>> Fixes: 7dc54d3b8d91 ("net: pcs: add Renesas MII converter driver")
>> Signed-off-by: Xiang Yang <xiangyang3@huawei.com>
>> ---
>
> Also, the patch subject prefix needs to be "[PATCH net]" (indicative of
> the fact that you want it to go to https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git)
> and not "[PATCH -next]".
Thanks, I will change the patch subject prefix and resend the patch of
v2 with your advice.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-08 16:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-07 13:47 [PATCH -next] net: pcs: Add missing put_device call in miic_create Xiang Yang
2023-08-08 10:53 ` Vladimir Oltean
2023-08-08 10:54 ` Vladimir Oltean
2023-08-08 11:56 ` Xiang Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox