diff mbox series

PCI: cadence: Fix erroneous early return from an iterator

Message ID 20210216205935.3112661-1-kw@linux.com
State New
Headers show
Series PCI: cadence: Fix erroneous early return from an iterator | expand

Commit Message

Krzysztof Wilczyński Feb. 16, 2021, 8:59 p.m. UTC
Function cdns_pcie_host_map_dma_ranges() iterates over a PCIe host
bridge DMA ranges using the resource_list_for_each_entry() iterator.

With every iteration it calls cdns_pcie_host_bar_config() on each entry
in the list, and performs error checking following execution of said
function.

Normally, should there be an error, the iteration would be interrupted
and the function would terminate returning an error, but following the
merge commit 49e427e6bdd1 ("Merge branch 'pci/host-probe-refactor'")
that also had to resolve a merge conflict of the pcie-cadence-host.c
file, where an if-statement involved in the error handling has been
unintentionally altered causing a return statement to be outside of the
code block, and thus an undesired early return takes place on first
iteration.

Fix the if-statement and move the return statement inside the correct
code block so that the error checking works correctly, and to prevent
undesired early return.

Fixes: 49e427e6bdd1 ("Merge branch 'pci/host-probe-refactor'")
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
---
 drivers/pci/controller/cadence/pcie-cadence-host.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Bjorn Helgaas Feb. 17, 2021, 8:57 p.m. UTC | #1
On Tue, Feb 16, 2021 at 08:59:35PM +0000, Krzysztof Wilczyński wrote:
> Function cdns_pcie_host_map_dma_ranges() iterates over a PCIe host
> bridge DMA ranges using the resource_list_for_each_entry() iterator.
> 
> With every iteration it calls cdns_pcie_host_bar_config() on each entry
> in the list, and performs error checking following execution of said
> function.
> 
> Normally, should there be an error, the iteration would be interrupted
> and the function would terminate returning an error, but following the
> merge commit 49e427e6bdd1 ("Merge branch 'pci/host-probe-refactor'")
> that also had to resolve a merge conflict of the pcie-cadence-host.c
> file, where an if-statement involved in the error handling has been
> unintentionally altered causing a return statement to be outside of the
> code block, and thus an undesired early return takes place on first
> iteration.
> 
> Fix the if-statement and move the return statement inside the correct
> code block so that the error checking works correctly, and to prevent
> undesired early return.
> 
> Fixes: 49e427e6bdd1 ("Merge branch 'pci/host-probe-refactor'")
> Signed-off-by: Krzysztof Wilczyński <kw@linux.com>

Reviewed-by: Bjorn Helgaas <bhelgaas@google.com>

Ouch, I really botched that merge, sorry!

> ---
>  drivers/pci/controller/cadence/pcie-cadence-host.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/cadence/pcie-cadence-host.c b/drivers/pci/controller/cadence/pcie-cadence-host.c
> index 811c1cb2e8de..1cb7cfc75d6e 100644
> --- a/drivers/pci/controller/cadence/pcie-cadence-host.c
> +++ b/drivers/pci/controller/cadence/pcie-cadence-host.c
> @@ -321,9 +321,10 @@ static int cdns_pcie_host_map_dma_ranges(struct cdns_pcie_rc *rc)
>  
>  	resource_list_for_each_entry(entry, &bridge->dma_ranges) {
>  		err = cdns_pcie_host_bar_config(rc, entry);
> -		if (err)
> +		if (err) {
>  			dev_err(dev, "Fail to configure IB using dma-ranges\n");
> -		return err;
> +			return err;
> +		}
>  	}
>  
>  	return 0;
> -- 
> 2.30.0
>
Bjorn Helgaas Feb. 18, 2021, 5 p.m. UTC | #2
On Tue, Feb 16, 2021 at 08:59:35PM +0000, Krzysztof Wilczyński wrote:
> Function cdns_pcie_host_map_dma_ranges() iterates over a PCIe host
> bridge DMA ranges using the resource_list_for_each_entry() iterator.
> 
> With every iteration it calls cdns_pcie_host_bar_config() on each entry
> in the list, and performs error checking following execution of said
> function.
> 
> Normally, should there be an error, the iteration would be interrupted
> and the function would terminate returning an error, but following the
> merge commit 49e427e6bdd1 ("Merge branch 'pci/host-probe-refactor'")
> that also had to resolve a merge conflict of the pcie-cadence-host.c
> file, where an if-statement involved in the error handling has been
> unintentionally altered causing a return statement to be outside of the
> code block, and thus an undesired early return takes place on first
> iteration.
> 
> Fix the if-statement and move the return statement inside the correct
> code block so that the error checking works correctly, and to prevent
> undesired early return.
> 
> Fixes: 49e427e6bdd1 ("Merge branch 'pci/host-probe-refactor'")
> Signed-off-by: Krzysztof Wilczyński <kw@linux.com>

Applied to pci/host-probe-refactor for v5.12, thanks!

> ---
>  drivers/pci/controller/cadence/pcie-cadence-host.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/cadence/pcie-cadence-host.c b/drivers/pci/controller/cadence/pcie-cadence-host.c
> index 811c1cb2e8de..1cb7cfc75d6e 100644
> --- a/drivers/pci/controller/cadence/pcie-cadence-host.c
> +++ b/drivers/pci/controller/cadence/pcie-cadence-host.c
> @@ -321,9 +321,10 @@ static int cdns_pcie_host_map_dma_ranges(struct cdns_pcie_rc *rc)
>  
>  	resource_list_for_each_entry(entry, &bridge->dma_ranges) {
>  		err = cdns_pcie_host_bar_config(rc, entry);
> -		if (err)
> +		if (err) {
>  			dev_err(dev, "Fail to configure IB using dma-ranges\n");
> -		return err;
> +			return err;
> +		}
>  	}
>  
>  	return 0;
> -- 
> 2.30.0
>
diff mbox series

Patch

diff --git a/drivers/pci/controller/cadence/pcie-cadence-host.c b/drivers/pci/controller/cadence/pcie-cadence-host.c
index 811c1cb2e8de..1cb7cfc75d6e 100644
--- a/drivers/pci/controller/cadence/pcie-cadence-host.c
+++ b/drivers/pci/controller/cadence/pcie-cadence-host.c
@@ -321,9 +321,10 @@  static int cdns_pcie_host_map_dma_ranges(struct cdns_pcie_rc *rc)
 
 	resource_list_for_each_entry(entry, &bridge->dma_ranges) {
 		err = cdns_pcie_host_bar_config(rc, entry);
-		if (err)
+		if (err) {
 			dev_err(dev, "Fail to configure IB using dma-ranges\n");
-		return err;
+			return err;
+		}
 	}
 
 	return 0;