Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: spear13xx: Avoid invalid address space conversions

The sparse checker complains about converting pointers between address
spaces. We correctly stored an __iomem pointer in struct spear13xx_pcie,
but discarded the __iomem when extracting app_base, causing one warning.
Then we passed the non-__iomem pointer to writel(), which expects an
__iomem pointer, causing another warning.

Add the appropriate annotations.

The sparse warnings look like this:

$ make C=2 drivers/pci/controller/
drivers/pci/controller/dwc/pcie-spear13xx.c:72:54: warning: incorrect type in initializer (different address spaces)
drivers/pci/controller/dwc/pcie-spear13xx.c:72:54: expected struct pcie_app_reg *app_reg
drivers/pci/controller/dwc/pcie-spear13xx.c:72:54: got void [noderef] __iomem *app_base
drivers/pci/controller/dwc/pcie-spear13xx.c:78:26: warning: incorrect type in argument 2 (different address spaces)
drivers/pci/controller/dwc/pcie-spear13xx.c:78:26: expected void volatile [noderef] __iomem *addr
drivers/pci/controller/dwc/pcie-spear13xx.c:78:26: got unsigned int *

Link: https://lore.kernel.org/r/20211223213749.1314142-3-helgaas@kernel.org
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Pratyush Anand <pratyush.anand@gmail.com>

+4 -4
+4 -4
drivers/pci/controller/dwc/pcie-spear13xx.c
··· 69 69 static int spear13xx_pcie_start_link(struct dw_pcie *pci) 70 70 { 71 71 struct spear13xx_pcie *spear13xx_pcie = to_spear13xx_pcie(pci); 72 - struct pcie_app_reg *app_reg = spear13xx_pcie->app_base; 72 + struct pcie_app_reg __iomem *app_reg = spear13xx_pcie->app_base; 73 73 74 74 /* enable ltssm */ 75 75 writel(DEVICE_TYPE_RC | (1 << MISCTRL_EN_ID) ··· 83 83 static irqreturn_t spear13xx_pcie_irq_handler(int irq, void *arg) 84 84 { 85 85 struct spear13xx_pcie *spear13xx_pcie = arg; 86 - struct pcie_app_reg *app_reg = spear13xx_pcie->app_base; 86 + struct pcie_app_reg __iomem *app_reg = spear13xx_pcie->app_base; 87 87 struct dw_pcie *pci = spear13xx_pcie->pci; 88 88 struct pcie_port *pp = &pci->pp; 89 89 unsigned int status; ··· 102 102 103 103 static void spear13xx_pcie_enable_interrupts(struct spear13xx_pcie *spear13xx_pcie) 104 104 { 105 - struct pcie_app_reg *app_reg = spear13xx_pcie->app_base; 105 + struct pcie_app_reg __iomem *app_reg = spear13xx_pcie->app_base; 106 106 107 107 /* Enable MSI interrupt */ 108 108 if (IS_ENABLED(CONFIG_PCI_MSI)) ··· 113 113 static int spear13xx_pcie_link_up(struct dw_pcie *pci) 114 114 { 115 115 struct spear13xx_pcie *spear13xx_pcie = to_spear13xx_pcie(pci); 116 - struct pcie_app_reg *app_reg = spear13xx_pcie->app_base; 116 + struct pcie_app_reg __iomem *app_reg = spear13xx_pcie->app_base; 117 117 118 118 if (readl(&app_reg->app_status_1) & XMLH_LINK_UP) 119 119 return 1;