All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
To: linux-pci@vger.kernel.org
Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Kishon Vijay Abraham I <kishon@ti.com>,
	stable@vger.kernel.org
Subject: [PATCH] PCI: dwc: Fix stop condition on __dw_pcie_ep_find_next_cap()
Date: Mon, 28 Jan 2019 19:22:59 +0100	[thread overview]
Message-ID: <9780b57125c83d6742bae3405d95e6b52686c450.1548699779.git.gustavo.pimentel@synopsys.com> (raw)

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


             reply	other threads:[~2019-01-28 18:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-28 18:22 Gustavo Pimentel [this message]
2019-01-29  4:12 ` [PATCH] PCI: dwc: Fix stop condition on __dw_pcie_ep_find_next_cap() Kishon Vijay Abraham I

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9780b57125c83d6742bae3405d95e6b52686c450.1548699779.git.gustavo.pimentel@synopsys.com \
    --to=gustavo.pimentel@synopsys.com \
    --cc=kishon@ti.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.