Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4486140imu; Tue, 29 Jan 2019 02:21:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN45rPVO17I83REXRHUkQ9UUvDp8+WCazTQCd4KzzPzDBb96FrNaSR62A10lTiph6UB624mG X-Received: by 2002:a63:ed03:: with SMTP id d3mr22865967pgi.275.1548757273262; Tue, 29 Jan 2019 02:21:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548757273; cv=none; d=google.com; s=arc-20160816; b=A1PwVtmRsdyNUFd/ol+cWFcBaXB3+K0d6rPyBqqLHC8RYVLa1D7stUmE1p8JLgGnLb GMZU+gyNtXvmOCz3VtD3qX3zyOA9Qpo1Imuhuhz4Y0OPbCusBoF4+ESD/yaVHqINl+h7 rSLfkXoGdlMBSf1toCYzac2Z1vHVU8AhzlO8V4lnzDGiJLLqgBP+yfgtjVJIWL+qmwZX svP3mmSJ7ekNhagN/dDdT7idHtT9+lmlBcrXJoeOybLAX76Bd8UCfLoC9u22PZOptEQm opauriGoa9iGjILjuizPQWJcJ8Hg5pqtWdtROgW1p/IME5Izclw0x2Mqby+xu3jbL6LA m4NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Ws8cfEW/GdK3qAnIerup80pZ7QCUAQ/ikhsMVH1JYMg=; b=Wf81RM+4+ANeUVfGFcQw+54mfNssvyMalThm4FlWe7jjQD6Pd+NgzNWVwX8OwrMtFz PfurrX7R4S6lyC0HZUpzO8LuYZ/TXQSl6plGfY2C+81itQ2Dmd3CGonZpwa3f8GHmegy ymrIVoJEPEZx5ZWnF+AhLdzMReox/5EoizccwfJ+hFe1f7jBPHrDZ9fKL3SXi3uTaKFZ hT05vOE3svm79Sm6Nq+WLLDYdv8fwetqaVWAGxWrpM8P1iNaPVqJrp5IP5Wo4wtTZoMW pPXgvI8FdBbSf8yHSrD5ItYm8TlW5McwoD/Qe3q4pEwOQqTonmRio4ZBhH7RQpg+3y9Z KePA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=tb6+AX1B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si35905338pla.58.2019.01.29.02.20.57; Tue, 29 Jan 2019 02:21:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=tb6+AX1B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727176AbfA2KUw (ORCPT + 99 others); Tue, 29 Jan 2019 05:20:52 -0500 Received: from lelv0143.ext.ti.com ([198.47.23.248]:45900 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbfA2KUv (ORCPT ); Tue, 29 Jan 2019 05:20:51 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0TAKUWE058370; Tue, 29 Jan 2019 04:20:30 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1548757230; bh=Ws8cfEW/GdK3qAnIerup80pZ7QCUAQ/ikhsMVH1JYMg=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=tb6+AX1BmbjyH91s/hiKSJdzczG6BvCc1pWzl0eWbuYfAWdBAEQE8RZhUS5gVotO0 aQbNfeOQrAHwfWdK12biUy6+fdpOWpwi3LBE6clpDMm5eM/pn/NrBAoYgSWbCq7Ffu h0mIWNNzMF0VsH4bIpNEfXbuzPRZDhtQCXDx0CLc= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0TAKTto091224 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 Jan 2019 04:20:29 -0600 Received: from DLEE103.ent.ti.com (157.170.170.33) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Tue, 29 Jan 2019 04:20:29 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Tue, 29 Jan 2019 04:20:29 -0600 Received: from [172.24.190.233] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0TAKNdi014159; Tue, 29 Jan 2019 04:20:24 -0600 Subject: Re: [PATCH 18/24] PCI: dwc: Fix dw_pcie_ep_find_capability to return correct capability offset To: Gustavo Pimentel , Rob Herring , Lorenzo Pieralisi CC: Jingoo Han , Bjorn Helgaas , Mark Rutland , Arnd Bergmann , Greg Kroah-Hartman , Murali Karicheri , Jesper Nilsson , "linux-pci@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-omap@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-arm-kernel@axis.com" References: <20190114132424.6445-1-kishon@ti.com> <20190114132424.6445-19-kishon@ti.com> <13501c15-8f3d-604b-c4fc-bde3fb208745@synopsys.com> From: Kishon Vijay Abraham I Message-ID: Date: Tue, 29 Jan 2019 15:49:51 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <13501c15-8f3d-604b-c4fc-bde3fb208745@synopsys.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Gustavo, On 29/01/19 2:55 PM, Gustavo Pimentel wrote: > Hi Kishon, > > On 14/01/2019 13:24, Kishon Vijay Abraham I wrote: >> commit beb4641a787df79a ("PCI: dwc: Add MSI-X callbacks handler") while >> adding MSI-X callback handler, introduced dw_pcie_ep_find_capability and >> __dw_pcie_ep_find_next_cap for finding the MSI and MSIX capability. >> >> However if MSI or MSIX capability is the last capability (i.e there are >> no additional items in the capabilities list and the Next Capability >> Pointer is set to '0'), __dw_pcie_ep_find_next_cap will return '0' >> even though MSI or MSIX capability may be present. This is because of >> incorrect ordering of "next_cap_ptr" check. Fix it here. >> >> Fixes: beb4641a787df79a142 ("PCI: dwc: Add MSI-X callbacks handler") >> Signed-off-by: Kishon Vijay Abraham I >> --- >> drivers/pci/controller/dwc/pcie-designware-ep.c | 10 +++++----- >> 1 file changed, 5 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c >> index d5144781005b..cd51b008858c 100644 >> --- a/drivers/pci/controller/dwc/pcie-designware-ep.c >> +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c >> @@ -46,16 +46,19 @@ static u8 __dw_pcie_ep_find_next_cap(struct dw_pcie *pci, u8 cap_ptr, >> u8 cap_id, next_cap_ptr; >> u16 reg; >> >> + if (!cap_ptr) >> + return 0; >> + > > Supposedly this was already verified by the function that calls this one. Right, with with this fix cap_ptr is checked only once. This being a recursive function, it makes sense to have the check only here instead of once in the calling function and once here. > >> reg = dw_pcie_readw_dbi(pci, cap_ptr); >> - next_cap_ptr = (reg & 0xff00) >> 8; >> cap_id = (reg & 0x00ff); >> >> - if (!next_cap_ptr || cap_id > PCI_CAP_ID_MAX) >> + if (cap_id > PCI_CAP_ID_MAX) >> return 0; >> >> if (cap_id == cap) >> return cap_ptr; >> >> + next_cap_ptr = (reg & 0xff00) >> 8; > > This fix seems to be a bit overdone, especially when you only need to swap the > if blocks order to achieve the desired goal. No, cap_id > PCI_CAP_ID_MAX is a base error case and it should checked before returning the offset IMO. > >> return __dw_pcie_ep_find_next_cap(pci, next_cap_ptr, cap); >> } >> >> @@ -67,9 +70,6 @@ static u8 dw_pcie_ep_find_capability(struct dw_pcie *pci, u8 cap) >> reg = dw_pcie_readw_dbi(pci, PCI_CAPABILITY_LIST); >> next_cap_ptr = (reg & 0x00ff); >> >> - if (!next_cap_ptr) >> - return 0; >> - > > Why remove it? > If pointer is null, why to jump to another function to check is the the same > pointer is null? so that we check cap_ptr only once. Thanks Kishon