🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Coia Prant Mon, 23 Nov 2026 12:30
[PATCH net-next] net: pcs: xpcs-rk: use cleanup.h for platform_device reference
#20948
Author: Coia Prant
Date: Mon, 23 Nov 2026 12:30
76 lines
13213 bytes
Use the __free(platform_device_put) cleanup action to manage the
platform_device reference obtained from of_find_device_by_node().

This removes the need for explicit put_device() calls on every failure
path and at the end of the successful path, simplifying the function
and reducing the chance of reference leaks or double puts.

Signed-off-by: Coia Prant <coiaprant@gmail.com>
---
 drivers/net/pcs/pcs-xpcs-rk.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/net/pcs/pcs-xpcs-rk.c b/drivers/net/pcs/pcs-xpcs-rk.c
index e0057545329a..8539caff6725 100644
--- a/drivers/net/pcs/pcs-xpcs-rk.c
+++ b/drivers/net/pcs/pcs-xpcs-rk.c
@@ -481,7 +481,6 @@ MODULE_DEVICE_TABLE(of, xpcs_rk_of_ids);
 struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int port)
 {
 	DECLARE_PHY_INTERFACE_MASK(supported_interfaces) = { 0, };
-	struct platform_device *pdev;
 	struct dw_xpcs_rk *pxpcs;
 	struct dw_xpcs *xpcs;
 
@@ -494,7 +493,7 @@ struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int
 	if (!xpcs_rk_mdio_addr_validate(port))
 		return ERR_PTR(-EINVAL);
 
-	pdev = of_find_device_by_node(pcs);
+	struct platform_device *pdev __free(platform_device_put) = of_find_device_by_node(pcs);
 	if (!pdev)
 		return ERR_PTR(-EPROBE_DEFER);
 
@@ -515,27 +514,19 @@ struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int
 	 * destroyed (DL_FLAG_AUTOREMOVE_CONSUMER), so no explicit
 	 * device_link_remove() is needed on the failure paths.
 	 */
-	if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) {
-		put_device(&pdev->dev);
+	if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER))
 		return ERR_PTR(-EPROBE_DEFER);
-	}
 
-	if (READ_ONCE(pdev->dev.links.status) != DL_DEV_DRIVER_BOUND) {
-		put_device(&pdev->dev);
+	if (READ_ONCE(pdev->dev.links.status) != DL_DEV_DRIVER_BOUND)
 		return ERR_PTR(-EPROBE_DEFER);
-	}
 
 	pxpcs = platform_get_drvdata(pdev);
-	if (!pxpcs || !pxpcs->bus) {
-		put_device(&pdev->dev);
+	if (!pxpcs || !pxpcs->bus)
 		return ERR_PTR(-EPROBE_DEFER);
-	}
 
 	xpcs = xpcs_create_mdiodev(pxpcs->bus, port);
-	if (IS_ERR(xpcs)) {
-		put_device(&pdev->dev);
+	if (IS_ERR(xpcs))
 		return xpcs;
-	}
 
 	/*
 	 * The RK3568 XPCS supports 1000BASE-X, SGMII and QSGMII.
@@ -547,7 +538,6 @@ struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *pcs, int
 			  supported_interfaces);
 
 	xpcs_config_eee_mult_fact(xpcs, pxpcs->eee_mult_fact);
-	put_device(&pdev->dev);
 	return xpcs;
 }
 EXPORT_SYMBOL_GPL(xpcs_rk_create);
-- 
2.47.3
Re: [PATCH net-next] net: pcs: xpcs-rk: use cleanup.h for platform_device reference
#21111
Author: Andrew Lunn
Date: Mon, 23 Nov 2026 15:11
22 lines
9006 bytes
On Mon, Nov 23, 2026 at 08:30:53PM +0800, Coia Prant wrote:
> Use the __free(platform_device_put) cleanup action to manage the
> platform_device reference obtained from of_find_device_by_node().
> 
> This removes the need for explicit put_device() calls on every failure
> path and at the end of the successful path, simplifying the function
> and reducing the chance of reference leaks or double puts.
> 
> Signed-off-by: Coia Prant <coiaprant@gmail.com>

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

Low level cleanup constructs (such as __free()) can be used when
building APIs and helpers, especially scoped iterators. However,
direct use of __free() within networking core and drivers is
discouraged.

    Andrew

---
pw-bot: cr
Re: [PATCH net-next] net: pcs: xpcs-rk: use cleanup.h for platform_device reference
#21113
Author: Coia Prant
Date: Mon, 23 Nov 2026 15:15
31 lines
12074 bytes
On November 23, 2026 11:11:00 PM GMT+08:00, Andrew Lunn <andrew@lunn.ch> wrote:
>On Mon, Nov 23, 2026 at 08:30:53PM +0800, Coia Prant wrote:
>> Use the __free(platform_device_put) cleanup action to manage the
>> platform_device reference obtained from of_find_device_by_node().
>> 
>> This removes the need for explicit put_device() calls on every failure
>> path and at the end of the successful path, simplifying the function
>> and reducing the chance of reference leaks or double puts.
>> 
>> Signed-off-by: Coia Prant <coiaprant@gmail.com>
>
>https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
>
>Low level cleanup constructs (such as __free()) can be used when
>building APIs and helpers, especially scoped iterators. However,
>direct use of __free() within networking core and drivers is
>discouraged.
>
>    Andrew
>
>---
>pw-bot: cr

Understood, thanks for the pointer. I have no plan to change this and will
keep the explicit put_device() calls as-is. Dropping this patch.

- Coia
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads