aboutsummaryrefslogtreecommitdiff
path: root/drivers/base
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>2026-07-06 14:44:14 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-07-10 16:07:08 +0200
commit714cfe9e143feb2136e9dc331c43e2453b3c3d4d (patch)
tree4681ae4e65d2ce73380ca8abfbaf93959cddfec7 /drivers/base
parentbd0abfe6b013aeb2a1aebc5fbc7ceeb50355bda3 (diff)
driver core: platform: provide platform_device_set_of_node()
Encapsulate the reference counting logic for OF nodes assigned to platform devices created with platform_device_alloc() in a helper function. Make the kerneldoc state that this is the proper interface for assigning OF nodes to dynamically allocated platform devices. This will allow us to switch to counting the references of the device's firmware nodes, not only the OF nodes. Reviewed-by: Manuel Ebner <manuelebner@mailbox.org> 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-2-1ff028e33779@oss.qualcomm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/platform.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index fb9120b0bcfe..3188d5aba5f9 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -694,6 +694,24 @@ int platform_device_add_data(struct platform_device *pdev, const void *data,
EXPORT_SYMBOL_GPL(platform_device_add_data);
/**
+ * platform_device_set_of_node - assign an OF node to device
+ * @pdev: platform device to add the node for
+ * @np: new device node
+ *
+ * Assign an OF node to this platform device. Internally keep track of the
+ * reference count. Devices created with platform_device_alloc() must use this
+ * function instead of assigning the node manually.
+ */
+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);
+}
+EXPORT_SYMBOL_GPL(platform_device_set_of_node);
+
+/**
* platform_device_add - add a platform device to device hierarchy
* @pdev: platform device we're adding
*