With no drivers that manually assign software nodes to platform devices
created with platform_device_alloc(), we can now unify the release path
and remove platform_device_release_full().

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
 drivers/base/platform.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 
a19dd22deef2f3edf7cddcf824d02b4e09091852..22834be0a3aeabf538f57ec6815ab3cd6851c16b
 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -599,6 +599,7 @@ static void platform_device_release(struct device *dev)
        struct platform_object *pa = container_of(dev, struct platform_object,
                                                  pdev.dev);
 
+       device_remove_software_node(dev);
        of_node_put(pa->pdev.dev.of_node);
        kfree(pa->pdev.dev.platform_data);
        kfree(pa->pdev.mfd_cell);
@@ -606,12 +607,6 @@ static void platform_device_release(struct device *dev)
        kfree(pa);
 }
 
-static void platform_device_release_full(struct device *dev)
-{
-       device_remove_software_node(dev);
-       platform_device_release(dev);
-}
-
 /**
  * platform_device_alloc - create a platform device
  * @name: base name of the device we're adding
@@ -878,6 +873,16 @@ struct platform_device 
*platform_device_register_full(const struct platform_devi
                pdev->dev.coherent_dma_mask = pdevinfo->dma_mask;
        }
 
+       /*
+        * If the primary firmware node is a software node and there's no
+        * secondary firmware node, the primary will be affected by the call
+        * to device_remove_software_node() in platform_device_release() and
+        * its reference count will be dropped by one. Take another reference
+        * here to make it have no effect.
+        */
+       if (is_software_node(pdevinfo->fwnode))
+               fwnode_handle_get(pdevinfo->fwnode);
+
        ret = platform_device_add_resources(pdev, pdevinfo->res, 
pdevinfo->num_res);
        if (ret)
                goto err;
@@ -890,8 +895,6 @@ struct platform_device *platform_device_register_full(const 
struct platform_devi
                ret = device_add_software_node(&pdev->dev, pdevinfo->swnode);
                if (ret)
                        goto err;
-
-               pdev->dev.release = platform_device_release_full;
        } else if (pdevinfo->properties) {
                ret = device_create_managed_software_node(&pdev->dev,
                                                          pdevinfo->properties, 
NULL);

-- 
2.47.3


Reply via email to