diff mbox series

[3/5] PCI: mt7621: Use helper function for_each_available_child_of_node_scoped()

Message ID 20240828073825.43072-4-zhangzekun11@huawei.com (mailing list archive)
State Superseded
Headers show
Series Simplify code with _scoped() helper functions | expand

Commit Message

zhangzekun (A) Aug. 28, 2024, 7:38 a.m. UTC
for_each_available_child_of_node_scoped() provides a scope-based cleanup
functinality to put the device_node automatically, and we don't need to
call of_node_put() directly.  Let's simplify the code a bit with the use
of these functions.

Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
---
 drivers/pci/controller/pcie-mt7621.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Sergio Paracuellos Aug. 28, 2024, 9:18 a.m. UTC | #1
Hi Zhang,

On Wed, Aug 28, 2024 at 9:51 AM Zhang Zekun <zhangzekun11@huawei.com> wrote:
>
> for_each_available_child_of_node_scoped() provides a scope-based cleanup
> functinality to put the device_node automatically, and we don't need to

typo: s/functinality/functionality/g

> call of_node_put() directly.  Let's simplify the code a bit with the use
> of these functions.
>
> Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
> ---
>  drivers/pci/controller/pcie-mt7621.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>

With the typo fixed:
Reviewed-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>

Thanks,
    Sergio Paracuellos
Jonathan Cameron Aug. 28, 2024, 12:17 p.m. UTC | #2
On Wed, 28 Aug 2024 15:38:23 +0800
Zhang Zekun <zhangzekun11@huawei.com> wrote:

> for_each_available_child_of_node_scoped() provides a scope-based cleanup
> functinality to put the device_node automatically, and we don't need to
> call of_node_put() directly.  Let's simplify the code a bit with the use
> of these functions.
> 
> Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
Another case in here where return dev_err_probe()
would be nice, but looks good to me either way.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/pci/controller/pcie-mt7621.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-mt7621.c b/drivers/pci/controller/pcie-mt7621.c
> index 9b4754a45515..16c3df1c49a1 100644
> --- a/drivers/pci/controller/pcie-mt7621.c
> +++ b/drivers/pci/controller/pcie-mt7621.c
> @@ -258,19 +258,18 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
>  {
>  	struct device *dev = pcie->dev;
>  	struct platform_device *pdev = to_platform_device(dev);
> -	struct device_node *node = dev->of_node, *child;
> +	struct device_node *node = dev->of_node;
>  	int err;
>  
>  	pcie->base = devm_platform_ioremap_resource(pdev, 0);
>  	if (IS_ERR(pcie->base))
>  		return PTR_ERR(pcie->base);
>  
> -	for_each_available_child_of_node(node, child) {
> +	for_each_available_child_of_node_scoped(node, child) {
>  		int slot;
>  
>  		err = of_pci_get_devfn(child);
>  		if (err < 0) {
> -			of_node_put(child);
>  			dev_err(dev, "failed to parse devfn: %d\n", err);
>  			return err;
>  		}
> @@ -278,10 +277,8 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
>  		slot = PCI_SLOT(err);
>  
>  		err = mt7621_pcie_parse_port(pcie, child, slot);
> -		if (err) {
> -			of_node_put(child);
> +		if (err)
>  			return err;
> -		}
>  	}
>  
>  	return 0;
diff mbox series

Patch

diff --git a/drivers/pci/controller/pcie-mt7621.c b/drivers/pci/controller/pcie-mt7621.c
index 9b4754a45515..16c3df1c49a1 100644
--- a/drivers/pci/controller/pcie-mt7621.c
+++ b/drivers/pci/controller/pcie-mt7621.c
@@ -258,19 +258,18 @@  static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
 {
 	struct device *dev = pcie->dev;
 	struct platform_device *pdev = to_platform_device(dev);
-	struct device_node *node = dev->of_node, *child;
+	struct device_node *node = dev->of_node;
 	int err;
 
 	pcie->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
 
-	for_each_available_child_of_node(node, child) {
+	for_each_available_child_of_node_scoped(node, child) {
 		int slot;
 
 		err = of_pci_get_devfn(child);
 		if (err < 0) {
-			of_node_put(child);
 			dev_err(dev, "failed to parse devfn: %d\n", err);
 			return err;
 		}
@@ -278,10 +277,8 @@  static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
 		slot = PCI_SLOT(err);
 
 		err = mt7621_pcie_parse_port(pcie, child, slot);
-		if (err) {
-			of_node_put(child);
+		if (err)
 			return err;
-		}
 	}
 
 	return 0;