diff mbox series

[v2] PCI: mediatek: Fix wrong operator used

Message ID 21f722bb80c440b69dd350b48f86cd7d076a8adf.1604443256.git.ryder.lee@mediatek.com (mailing list archive)
State New, archived
Headers show
Series [v2] PCI: mediatek: Fix wrong operator used | expand

Commit Message

Ryder Lee Nov. 3, 2020, 11:10 p.m. UTC
SoCs like MT2701 and MT7623 use mtk_pcie_startup_port() to compute "func",
but from the code, the result we get is incorrect.

	#define PCI_FUNC(devfn)         ((devfn) & 0x07)

	func = PCI_FUNC(port->slot << 3)

The "func" is always 0, which results in other functions may not have been
configured correctly. (i.e. FC credits and FTS)

Addresses-Coverity-ID: 1437218 ("Wrong operator used")
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
---
V2 - revise commit log
---
 drivers/pci/controller/pcie-mediatek.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bjorn Helgaas Nov. 4, 2020, 1:10 p.m. UTC | #1
The subject needs to say something about the user-visible problem
you're fixing, e.g., functions other than 0 aren't configured
correctly.

On Wed, Nov 04, 2020 at 07:10:11AM +0800, Ryder Lee wrote:
> SoCs like MT2701 and MT7623 use mtk_pcie_startup_port() to compute "func",
> but from the code, the result we get is incorrect.

This affects precisely "MT2701 and MT7623", not "SoCs *like* MT2701
and MT7623".  How about this:

  PCI: mediatek: Configure FC and FTS for functions other than 0

  "PCI_FUNC(port->slot << 3)" is always 0, so previously
  mtk_pcie_startup_port() only configured FC credits and FTs for
  function 0.

  Compute "func" correctly so we also configure functions other than
  0.  This affects MT2701 and MT7623.

> 	#define PCI_FUNC(devfn)         ((devfn) & 0x07)
> 
> 	func = PCI_FUNC(port->slot << 3)
> 
> The "func" is always 0, which results in other functions may not have been
> configured correctly. (i.e. FC credits and FTS)
> 
> Addresses-Coverity-ID: 1437218 ("Wrong operator used")
> Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
> ---
> V2 - revise commit log
> ---
>  drivers/pci/controller/pcie-mediatek.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> index cf4c18f0c25a..1980b01cee35 100644
> --- a/drivers/pci/controller/pcie-mediatek.c
> +++ b/drivers/pci/controller/pcie-mediatek.c
> @@ -760,7 +760,7 @@ static struct pci_ops mtk_pcie_ops = {
>  static int mtk_pcie_startup_port(struct mtk_pcie_port *port)
>  {
>  	struct mtk_pcie *pcie = port->pcie;
> -	u32 func = PCI_FUNC(port->slot << 3);
> +	u32 func = PCI_FUNC(port->slot);
>  	u32 slot = PCI_SLOT(port->slot << 3);
>  	u32 val;
>  	int err;
> -- 
> 2.18.0
diff mbox series

Patch

diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index cf4c18f0c25a..1980b01cee35 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -760,7 +760,7 @@  static struct pci_ops mtk_pcie_ops = {
 static int mtk_pcie_startup_port(struct mtk_pcie_port *port)
 {
 	struct mtk_pcie *pcie = port->pcie;
-	u32 func = PCI_FUNC(port->slot << 3);
+	u32 func = PCI_FUNC(port->slot);
 	u32 slot = PCI_SLOT(port->slot << 3);
 	u32 val;
 	int err;