PCI: mvebu: Simplify with scoped for each OF child loop
Subsystems (5)
PATCH v2 1/4 PCI: mvebu: Simplify with scoped for each OF child loop
Use scoped for-each loop when iterating over device nodes to make code a bit simpler.
---
Changes in v2:
None
v1:
https://lore.kernel.org/all/[email protected]/
--- drivers/pci/controller/pci-mvebu.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/pci/controller/pci-mvebu.c +4 -6
@@ -1452,7 +1452,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)struct mvebu_pcie *pcie;struct pci_host_bridge *bridge;struct device_node *np = dev->of_node; -struct device_node *child;int num, i, ret; bridge =devm_pci_alloc_host_bridge (dev,sizeof (struct mvebu_pcie ));
@@ -1474,16 +1473,14 @@ static int mvebu_pcie_probe(struct platform_device *pdev)return -ENOMEM ; i =0 ; -for_each_available_child_of_node (np, child) { +for_each_available_child_of_node_scoped (np, child) {struct mvebu_pcie_port *port = &pcie->ports[i]; ret =mvebu_pcie_parse_port (pcie, port, child); -if (ret <0 ) { -of_node_put (child); +if (ret <0 )return ret; - }else if (ret ==0 ) { +else if (ret ==0 )continue ; - } port->dn = child; i++;
@@ -1493,6 +1490,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)for (i =0 ; i < pcie->nports; i++) {struct mvebu_pcie_port *port = &pcie->ports[i];int irq = port->intx_irq; +struct device_node *child; child = port->dn;if (!child)
Signature · 1 line
2.51.0
PATCH v2 2/4 PCI: mvebu: Keep child node refcnt for probe duration
Driver in probe() first iterates over child device nodes, storing the OF node pointer but does not take the reference to it for the remaining part of the probe where it is used.
The pointer thus could become invalid if children OF nodes are being removed from the Devicetree, e.g. by removing OF overlay, while the probe is being executed. That's is highly theoretical issue, thus it does not look like bug with any effect.
Nevertheless, make the code logically correct, so acquire the OF node refcnt for entire lifetime of the device, since the pointer is stored in each port state container structure.
---
Changes in v2:
1. New patch
Note: Not a fix, because practical impact is absolutely zero since of_node_get is a noop.
--- drivers/pci/controller/pci-mvebu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/pci/controller/pci-mvebu.c +10 -1
@@ -1236,6 +1236,11 @@ static void mvebu_pcie_port_clk_put(void *data)clk_put (port->clk); } +static void mvebu_pcie_port_of_node_put (void *data) +{ +of_node_put (data); +} +static int mvebu_pcie_parse_port (struct mvebu_pcie *pcie,struct mvebu_pcie_port *port,struct device_node *child) {
@@ -1482,7 +1487,11 @@ static int mvebu_pcie_probe(struct platform_device *pdev)else if (ret ==0 )continue ; - port->dn = child; + port->dn =of_node_get (child); + ret =devm_add_action_or_reset (dev, mvebu_pcie_port_of_node_put, + child); +if (ret) +return ret; i++; } pcie->nports = i;
Signature · 1 line
2.51.0
PATCH v2 3/4 PCI: pnv_php: Simplify with scoped for each OF child loop
In reply to Krzysztof KozlowskiUse scoped for-each loop when iterating over device nodes to make code a bit simpler.
---
Changes in v2:
Tags
--- drivers/pci/hotplug/pnv_php.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/pci/hotplug/pnv_php.c +7 -12
@@ -215,24 +215,19 @@ static void pnv_php_reverse_nodes(struct device_node *parent)static int pnv_php_populate_changeset (struct of_changeset *ocs,struct device_node *dn) { -struct device_node *child; -int ret =0 ; +int ret; -for_each_child_of_node (dn, child) { +for_each_child_of_node_scoped (dn, child) { ret =of_changeset_attach_node (ocs, child); -if (ret) { -of_node_put (child); -break ; - } +if (ret) +return ret; ret =pnv_php_populate_changeset (ocs, child); -if (ret) { -of_node_put (child); -break ; - } +if (ret) +return ret; } -return ret; +return 0 ; }static void *pnv_php_add_one_pdn (struct device_node *dn,void *data)
Signature · 1 line
2.51.0
Re: [PATCH v2 3/4] PCI: pnv_php: Simplify with scoped for each OF child loop
Quoted 41 lines · Krzysztof Kozlowski
Use scoped for-each loop when iterating over device nodes to make code a bit simpler.
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Krzysztof Kozlowski <[email protected]>---
Changes in v2:
Tags--- drivers/pci/hotplug/pnv_php.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)drivers/pci/hotplug/pnv_php.c +4
-10@@ -215,24 +215,19 @@ static void pnv_php_reverse_nodes(struct device_node *parent)static int pnv_php_populate_changeset (struct of_changeset *ocs,struct device_node *dn) { -struct device_node *child; -int ret =0 ; +int ret; -for_each_child_of_node (dn, child) { +for_each_child_of_node_scoped (dn, child) { ret =of_changeset_attach_node (ocs, child); -if (ret) { -of_node_put (child); -break ; - } +if (ret) +return ret; ret =pnv_php_populate_changeset (ocs, child); -if (ret) { -of_node_put (child); -break ;
drivers/pci/hotplug/pnv_php.c static void pnv_php_reverse_nodes(struct device_node *parent) · line 233
Quoted 10 lines
drivers/pci/hotplug/pnv_php.c +3
-2- } +if (ret) +return ret; } -return ret; +return 0 ; }static void *pnv_php_add_one_pdn (struct device_node *dn,void *data)
Signature · 1 line
i.
Bjorn Helgaas
AppliedRe: [PATCH v2 3/4] PCI: pnv_php: Simplify with scoped for each OF child loop
In reply to Krzysztof KozlowskiQuoted 5 lines · Krzysztof Kozlowski
Use scoped for-each loop when iterating over device nodes to make code a bit simpler.
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Krzysztof Kozlowski <[email protected]>
Applied patches 3 and 4 to pci/hotplug for v7.1, thanks!
Mani will take care of patches 1 and 2.
Quoted 47 lines
---
Changes in v2:
Tags--- drivers/pci/hotplug/pnv_php.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)drivers/pci/hotplug/pnv_php.c +7
-12@@ -215,24 +215,19 @@ static void pnv_php_reverse_nodes(struct device_node *parent)static int pnv_php_populate_changeset (struct of_changeset *ocs,struct device_node *dn) { -struct device_node *child; -int ret =0 ; +int ret; -for_each_child_of_node (dn, child) { +for_each_child_of_node_scoped (dn, child) { ret =of_changeset_attach_node (ocs, child); -if (ret) { -of_node_put (child); -break ; - } +if (ret) +return ret; ret =pnv_php_populate_changeset (ocs, child); -if (ret) { -of_node_put (child); -break ; - } +if (ret) +return ret; } -return ret; +return 0 ; }static void *pnv_php_add_one_pdn (struct device_node *dn,void *data)Signature · 1 line
2.51.0
PATCH v2 4/4 PCI: rpaphp: Simplify with scoped for each OF child loop
In reply to Krzysztof KozlowskiUse scoped for-each loop when iterating over device nodes to make code a bit simpler.
---
Changes in v2:
Tags
--- drivers/pci/hotplug/rpaphp_slot.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pci/hotplug/rpaphp_slot.c +1 -3
@@ -82,7 +82,6 @@ EXPORT_SYMBOL_GPL(rpaphp_deregister_slot);int rpaphp_register_slot (struct slot *slot) {struct hotplug_slot *php_slot = &slot->hotplug_slot; -struct device_node *child;u32 my_index;int retval;int slotno =-1 ;
@@ -97,11 +96,10 @@ int rpaphp_register_slot(struct slot *slot)return -EAGAIN ; } -for_each_child_of_node (slot->dn, child) { +for_each_child_of_node_scoped (slot->dn, child) { retval =of_property_read_u32 (child,"ibm,my-drc-index" , &my_index);if (my_index == slot->index) { slotno =PCI_SLOT (PCI_DN (child)->devfn); -of_node_put (child);break ; } }
Signature · 1 line
2.51.0
Re: [PATCH v2 4/4] PCI: rpaphp: Simplify with scoped for each OF child loop
Quoted 30 lines · Krzysztof Kozlowski
Use scoped for-each loop when iterating over device nodes to make code a bit simpler.
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Krzysztof Kozlowski <[email protected]>---
Changes in v2:
Tags--- drivers/pci/hotplug/rpaphp_slot.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/pci/hotplug/rpaphp_slot.c +0
-1@@ -82,7 +82,6 @@ EXPORT_SYMBOL_GPL(rpaphp_deregister_slot);int rpaphp_register_slot (struct slot *slot) {struct hotplug_slot *php_slot = &slot->hotplug_slot; -struct device_node *child;u32 my_index;int retval;int slotno =-1 ;@@ -97,11 +96,10 @@ int rpaphp_register_slot(struct slot *slot)return -EAGAIN ; }
drivers/pci/hotplug/rpaphp_slot.c int rpaphp_register_slot(struct slot *slot) · line 105
Quoted 10 lines
drivers/pci/hotplug/rpaphp_slot.c +1
-2-for_each_child_of_node (slot->dn, child) { +for_each_child_of_node_scoped (slot->dn, child) { retval =of_property_read_u32 (child,"ibm,my-drc-index" , &my_index);if (my_index == slot->index) { slotno =PCI_SLOT (PCI_DN (child)->devfn); -of_node_put (child);break ; } }
Signature · 1 line
i.