All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: dwc: Fix stop condition on __dw_pcie_ep_find_next_cap()
@ 2019-01-28 18:22 Gustavo Pimentel
  2019-01-29  4:12 ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo Pimentel @ 2019-01-28 18:22 UTC (permalink / raw)
  To: linux-pci
  Cc: Gustavo Pimentel, Lorenzo Pieralisi, Kishon Vijay Abraham I, stable

The combination of __dw_pcie_ep_find_next_cap() and
dw_pcie_ep_find_capability() allows to search on the Endpoint
configuration space for a specific capability ID.

This search is done recursively by __dw_pcie_ep_find_next_cap() jumping
from capability to capability (using the next offset register to calculate
next jump address), stopping until the next offset register is null or
the current capability meets the desired ID.

However, if the desired capability is at the end of that list, the
recursive search will be returning because the next offset will
be null (thus filling the first stop condition) and not because it
has reached the desired ID and therefore reporting capability "not
found".

This fix will swap the stop conditions order of
__dw_pcie_ep_find_next_cap(), allowing to find the desired capability ID,
if it encounters at the end of the list.

Fixes: beb4641a787d ("PCI: dwc: Add MSI-X callbacks handler")
Reported-by: Jian Wang <jianwang@ra.rockwell.com>
Signed-off-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: stable@vger.kernel.org
---
 drivers/pci/controller/dwc/pcie-designware-ep.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
index a543c45..0258894 100644
--- a/drivers/pci/controller/dwc/pcie-designware-ep.c
+++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
@@ -50,12 +50,12 @@ static u8 __dw_pcie_ep_find_next_cap(struct dw_pcie *pci, u8 cap_ptr,
 	next_cap_ptr = (reg & 0xff00) >> 8;
 	cap_id = (reg & 0x00ff);
 
-	if (!next_cap_ptr || cap_id > PCI_CAP_ID_MAX)
-		return 0;
-
 	if (cap_id == cap)
 		return cap_ptr;
 
+	if (!next_cap_ptr || cap_id > PCI_CAP_ID_MAX)
+		return 0;
+
 	return __dw_pcie_ep_find_next_cap(pci, next_cap_ptr, cap);
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] PCI: dwc: Fix stop condition on __dw_pcie_ep_find_next_cap()
  2019-01-28 18:22 [PATCH] PCI: dwc: Fix stop condition on __dw_pcie_ep_find_next_cap() Gustavo Pimentel
@ 2019-01-29  4:12 ` Kishon Vijay Abraham I
  0 siblings, 0 replies; 2+ messages in thread
From: Kishon Vijay Abraham I @ 2019-01-29  4:12 UTC (permalink / raw)
  To: Gustavo Pimentel, linux-pci; +Cc: Lorenzo Pieralisi, stable

Hi Gustavo,

On 28/01/19 11:52 PM, Gustavo Pimentel wrote:
> The combination of __dw_pcie_ep_find_next_cap() and
> dw_pcie_ep_find_capability() allows to search on the Endpoint
> configuration space for a specific capability ID.
> 
> This search is done recursively by __dw_pcie_ep_find_next_cap() jumping
> from capability to capability (using the next offset register to calculate
> next jump address), stopping until the next offset register is null or
> the current capability meets the desired ID.
> 
> However, if the desired capability is at the end of that list, the
> recursive search will be returning because the next offset will
> be null (thus filling the first stop condition) and not because it
> has reached the desired ID and therefore reporting capability "not
> found".
> 
> This fix will swap the stop conditions order of
> __dw_pcie_ep_find_next_cap(), allowing to find the desired capability ID,
> if it encounters at the end of the list.
> 
> Fixes: beb4641a787d ("PCI: dwc: Add MSI-X callbacks handler")
> Reported-by: Jian Wang <jianwang@ra.rockwell.com>
> Signed-off-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Kishon Vijay Abraham I <kishon@ti.com>
> Cc: stable@vger.kernel.org

I had already posted a patch fixing it as part of my AM654 PCIe support series [1].

Thanks
Kishon
[1] -> https://lore.kernel.org/lkml/20190114132424.6445-19-kishon@ti.com/T/#u
> ---
>  drivers/pci/controller/dwc/pcie-designware-ep.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
> index a543c45..0258894 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-ep.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
> @@ -50,12 +50,12 @@ static u8 __dw_pcie_ep_find_next_cap(struct dw_pcie *pci, u8 cap_ptr,
>  	next_cap_ptr = (reg & 0xff00) >> 8;
>  	cap_id = (reg & 0x00ff);
>  
> -	if (!next_cap_ptr || cap_id > PCI_CAP_ID_MAX)
> -		return 0;
> -
>  	if (cap_id == cap)
>  		return cap_ptr;
>  
> +	if (!next_cap_ptr || cap_id > PCI_CAP_ID_MAX)
> +		return 0;
> +
>  	return __dw_pcie_ep_find_next_cap(pci, next_cap_ptr, cap);
>  }
>  
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-29  4:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-28 18:22 [PATCH] PCI: dwc: Fix stop condition on __dw_pcie_ep_find_next_cap() Gustavo Pimentel
2019-01-29  4:12 ` Kishon Vijay Abraham I

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.