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 <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]> --- 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 9357942d0c79b032645035879b2bed3d53305b9f..a71015f1d915340aa01ebfae67196d4d7ccecba8 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) { -- 2.47.3
