]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ata: libahci_platform: Simplify code with for_each_child_of_node_scoped()
authorZhang Zekun <zhangzekun11@huawei.com>
Sat, 10 Aug 2024 02:34:26 +0000 (10:34 +0800)
committerNiklas Cassel <cassel@kernel.org>
Thu, 15 Aug 2024 11:30:06 +0000 (13:30 +0200)
for_each_child_of_node_scoped() can put the device_node automatically.
So let's use it to make the code simpler by avoiding the need to
explicitly call of_node_put().

Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
Link: https://lore.kernel.org/r/20240810023426.110624-1-zhangzekun11@huawei.com
Signed-off-by: Niklas Cassel <cassel@kernel.org>
drivers/ata/libahci_platform.c

index 581704e61f286bf7f013637d7c8fccd54f14f726..7a8064520a35bd86a1fa82d05c1ecaa8a81b7010 100644 (file)
@@ -410,7 +410,6 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port,
 static int ahci_platform_get_firmware(struct ahci_host_priv *hpriv,
                                      struct device *dev)
 {
-       struct device_node *child;
        u32 port;
 
        if (!of_property_read_u32(dev->of_node, "hba-cap", &hpriv->saved_cap))
@@ -419,14 +418,12 @@ static int ahci_platform_get_firmware(struct ahci_host_priv *hpriv,
        of_property_read_u32(dev->of_node,
                             "ports-implemented", &hpriv->saved_port_map);
 
-       for_each_child_of_node(dev->of_node, child) {
+       for_each_child_of_node_scoped(dev->of_node, child) {
                if (!of_device_is_available(child))
                        continue;
 
-               if (of_property_read_u32(child, "reg", &port)) {
-                       of_node_put(child);
+               if (of_property_read_u32(child, "reg", &port))
                        return -EINVAL;
-               }
 
                if (!of_property_read_u32(child, "hba-port-cap", &hpriv->saved_port_cap[port]))
                        hpriv->saved_port_cap[port] &= PORT_CMD_CAP;
@@ -460,7 +457,6 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
        int child_nodes, rc = -ENOMEM, enabled_ports = 0;
        struct device *dev = &pdev->dev;
        struct ahci_host_priv *hpriv;
-       struct device_node *child;
        u32 mask_port_map = 0;
 
        if (!devres_open_group(dev, NULL, GFP_KERNEL))
@@ -579,7 +575,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
        }
 
        if (child_nodes) {
-               for_each_child_of_node(dev->of_node, child) {
+               for_each_child_of_node_scoped(dev->of_node, child) {
                        u32 port;
                        struct platform_device *port_dev __maybe_unused;
 
@@ -588,7 +584,6 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
 
                        if (of_property_read_u32(child, "reg", &port)) {
                                rc = -EINVAL;
-                               of_node_put(child);
                                goto err_out;
                        }
 
@@ -606,18 +601,14 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
                        if (port_dev) {
                                rc = ahci_platform_get_regulator(hpriv, port,
                                                                &port_dev->dev);
-                               if (rc == -EPROBE_DEFER) {
-                                       of_node_put(child);
+                               if (rc == -EPROBE_DEFER)
                                        goto err_out;
-                               }
                        }
 #endif
 
                        rc = ahci_platform_get_phy(hpriv, port, dev, child);
-                       if (rc) {
-                               of_node_put(child);
+                       if (rc)
                                goto err_out;
-                       }
 
                        enabled_ports++;
                }