Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <zhangzekun11@huawei.com>
Link: https://lore.kernel.org/r/20240810023426.110624-1-zhangzekun11@huawei.com
Signed-off-by: Niklas Cassel <cassel@kernel.org>

authored by

Zhang Zekun and committed by
Niklas Cassel
aa3ca1fa 6773e058

+5 -14
+5 -14
drivers/ata/libahci_platform.c
··· 410 410 static int ahci_platform_get_firmware(struct ahci_host_priv *hpriv, 411 411 struct device *dev) 412 412 { 413 - struct device_node *child; 414 413 u32 port; 415 414 416 415 if (!of_property_read_u32(dev->of_node, "hba-cap", &hpriv->saved_cap)) ··· 418 419 of_property_read_u32(dev->of_node, 419 420 "ports-implemented", &hpriv->saved_port_map); 420 421 421 - for_each_child_of_node(dev->of_node, child) { 422 + for_each_child_of_node_scoped(dev->of_node, child) { 422 423 if (!of_device_is_available(child)) 423 424 continue; 424 425 425 - if (of_property_read_u32(child, "reg", &port)) { 426 - of_node_put(child); 426 + if (of_property_read_u32(child, "reg", &port)) 427 427 return -EINVAL; 428 - } 429 428 430 429 if (!of_property_read_u32(child, "hba-port-cap", &hpriv->saved_port_cap[port])) 431 430 hpriv->saved_port_cap[port] &= PORT_CMD_CAP; ··· 457 460 int child_nodes, rc = -ENOMEM, enabled_ports = 0; 458 461 struct device *dev = &pdev->dev; 459 462 struct ahci_host_priv *hpriv; 460 - struct device_node *child; 461 463 u32 mask_port_map = 0; 462 464 463 465 if (!devres_open_group(dev, NULL, GFP_KERNEL)) ··· 575 579 } 576 580 577 581 if (child_nodes) { 578 - for_each_child_of_node(dev->of_node, child) { 582 + for_each_child_of_node_scoped(dev->of_node, child) { 579 583 u32 port; 580 584 struct platform_device *port_dev __maybe_unused; 581 585 ··· 584 588 585 589 if (of_property_read_u32(child, "reg", &port)) { 586 590 rc = -EINVAL; 587 - of_node_put(child); 588 591 goto err_out; 589 592 } 590 593 ··· 601 606 if (port_dev) { 602 607 rc = ahci_platform_get_regulator(hpriv, port, 603 608 &port_dev->dev); 604 - if (rc == -EPROBE_DEFER) { 605 - of_node_put(child); 609 + if (rc == -EPROBE_DEFER) 606 610 goto err_out; 607 - } 608 611 } 609 612 #endif 610 613 611 614 rc = ahci_platform_get_phy(hpriv, port, dev, child); 612 - if (rc) { 613 - of_node_put(child); 615 + if (rc) 614 616 goto err_out; 615 - } 616 617 617 618 enabled_ports++; 618 619 }