Skip to content

Commit aa3ca1f

Browse files
Zhang Zekunfloatious
authored andcommitted
ata: libahci_platform: Simplify code with for_each_child_of_node_scoped()
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Cassel <[email protected]>
1 parent 6773e05 commit aa3ca1f

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

drivers/ata/libahci_platform.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port,
410410
static int ahci_platform_get_firmware(struct ahci_host_priv *hpriv,
411411
struct device *dev)
412412
{
413-
struct device_node *child;
414413
u32 port;
415414

416415
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,
419418
of_property_read_u32(dev->of_node,
420419
"ports-implemented", &hpriv->saved_port_map);
421420

422-
for_each_child_of_node(dev->of_node, child) {
421+
for_each_child_of_node_scoped(dev->of_node, child) {
423422
if (!of_device_is_available(child))
424423
continue;
425424

426-
if (of_property_read_u32(child, "reg", &port)) {
427-
of_node_put(child);
425+
if (of_property_read_u32(child, "reg", &port))
428426
return -EINVAL;
429-
}
430427

431428
if (!of_property_read_u32(child, "hba-port-cap", &hpriv->saved_port_cap[port]))
432429
hpriv->saved_port_cap[port] &= PORT_CMD_CAP;
@@ -460,7 +457,6 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
460457
int child_nodes, rc = -ENOMEM, enabled_ports = 0;
461458
struct device *dev = &pdev->dev;
462459
struct ahci_host_priv *hpriv;
463-
struct device_node *child;
464460
u32 mask_port_map = 0;
465461

466462
if (!devres_open_group(dev, NULL, GFP_KERNEL))
@@ -579,7 +575,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
579575
}
580576

581577
if (child_nodes) {
582-
for_each_child_of_node(dev->of_node, child) {
578+
for_each_child_of_node_scoped(dev->of_node, child) {
583579
u32 port;
584580
struct platform_device *port_dev __maybe_unused;
585581

@@ -588,7 +584,6 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
588584

589585
if (of_property_read_u32(child, "reg", &port)) {
590586
rc = -EINVAL;
591-
of_node_put(child);
592587
goto err_out;
593588
}
594589

@@ -606,18 +601,14 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
606601
if (port_dev) {
607602
rc = ahci_platform_get_regulator(hpriv, port,
608603
&port_dev->dev);
609-
if (rc == -EPROBE_DEFER) {
610-
of_node_put(child);
604+
if (rc == -EPROBE_DEFER)
611605
goto err_out;
612-
}
613606
}
614607
#endif
615608

616609
rc = ahci_platform_get_phy(hpriv, port, dev, child);
617-
if (rc) {
618-
of_node_put(child);
610+
if (rc)
619611
goto err_out;
620-
}
621612

622613
enabled_ports++;
623614
}

0 commit comments

Comments
 (0)