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 <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260706-pdev-fwnode-ref-v3-20-1ff028e33779@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Bartosz Golaszewski 2026-07-06 14:44:32 +02:00 committed by Greg Kroah-Hartman
parent 7a78fc2082
commit 7b5b51b2b0

View File

@ -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) {