From 7b5b51b2b05cf2b49eaa3808b1c2953cfb8e1cae Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 6 Jul 2026 14:44:32 +0200 Subject: [PATCH] driver core: platform: count references to all kinds of firmware nodes When using platform_device_register_full(), we currently only increase the reference count of the OF node associated with a platform device. We symmetrically decrease it in platform_device_release(). With all users in tree now converted to using provided platform device helpers for assigning OF and firmware nodes, we can now switch to counting references of all kinds of firmware nodes. Reviewed-by: Andy Shevchenko Signed-off-by: Bartosz Golaszewski Link: https://patch.msgid.link/20260706-pdev-fwnode-ref-v3-20-1ff028e33779@oss.qualcomm.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 9357942d0c79..a71015f1d915 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -599,7 +599,7 @@ static void platform_device_release(struct device *dev) struct platform_object *pa = container_of(dev, struct platform_object, pdev.dev); - of_node_put(pa->pdev.dev.of_node); + fwnode_handle_put(pa->pdev.dev.fwnode); kfree(pa->pdev.dev.platform_data); kfree(pa->pdev.mfd_cell); kfree(pa->pdev.resource); @@ -712,9 +712,7 @@ EXPORT_SYMBOL_GPL(platform_device_add_data); void platform_device_set_of_node(struct platform_device *pdev, struct device_node *np) { - of_node_put(pdev->dev.of_node); - pdev->dev.of_node = of_node_get(np); - pdev->dev.fwnode = of_fwnode_handle(np); + platform_device_set_fwnode(pdev, of_fwnode_handle(np)); } EXPORT_SYMBOL_GPL(platform_device_set_of_node); @@ -730,10 +728,8 @@ EXPORT_SYMBOL_GPL(platform_device_set_of_node); void platform_device_set_fwnode(struct platform_device *pdev, struct fwnode_handle *fwnode) { - if (is_of_node(fwnode)) - platform_device_set_of_node(pdev, to_of_node(fwnode)); - else - pdev->dev.fwnode = fwnode; + fwnode_handle_put(pdev->dev.fwnode); + device_set_node(&pdev->dev, fwnode_handle_get(fwnode)); } EXPORT_SYMBOL_GPL(platform_device_set_fwnode); @@ -928,8 +924,7 @@ struct platform_device *platform_device_register_full(const struct platform_devi return ERR_PTR(-ENOMEM); pdev->dev.parent = pdevinfo->parent; - pdev->dev.fwnode = pdevinfo->fwnode; - pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode)); + device_set_node(&pdev->dev, fwnode_handle_get(pdevinfo->fwnode)); dev_assign_of_node_reused(&pdev->dev, pdevinfo->of_node_reused); if (pdevinfo->dma_mask) {