PCI: mediatek: Correct type for virt_to_phys()
PATCH v2 1/1 PCI: mediatek: Correct type for virt_to_phys()
virt_to_phys() takes a regular pointer, while driver supplies __iomem annotated one. Force type to void to make sparse happy, otherwise
pcie-mediatek.c:400:40: sparse: expected void volatile *address
pcie-mediatek.c:400:40: sparse: got void [noderef] __iomem *
pcie-mediatek.c:523:44: sparse: expected void volatile *address
pcie-mediatek.c:523:44: sparse: got void [noderef] __iomem *
--- drivers/pci/controller/pcie-mediatek.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/pcie-mediatek.c +2 -2
@@ -397,7 +397,7 @@ static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)phys_addr_t addr;/* MT2712/MT7622 only support 32-bit MSI addresses */ - addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + addr =virt_to_phys ((__force void *)port->base +PCIE_MSI_VECTOR ); msg->address_hi =0 ; msg->address_lo =lower_32_bits (addr);
@@ -520,7 +520,7 @@ static void mtk_pcie_enable_msi(struct mtk_pcie_port *port)u32 val;phys_addr_t msg_addr; - msg_addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + msg_addr =virt_to_phys ((__force void *)port->base +PCIE_MSI_VECTOR ); val =lower_32_bits (msg_addr);writel (val, port->base +PCIE_IMSI_ADDR );
Signature · 1 line
2.40.0.1.gaa8946217a0b
Quoted 22 lines · Andy Shevchenko
virt_to_phys()takes a regular pointer, while driver supplies__iomemannotated one. Force type to void to make sparse happy, otherwisepcie-mediatek.c:400:40: sparse: expected void volatile *address
pcie-mediatek.c:400:40: sparse: got void [noderef]__iomem*pcie-mediatek.c:523:44: sparse: expected void volatile *address
pcie-mediatek.c:523:44: sparse: got void [noderef]__iomem*Reported-by Huacai Chen <[email protected]>Reported-by kernel test robot <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/pci/controller/pcie-mediatek.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/controller/pcie-mediatek.c +0
-0
drivers/pci/controller/pcie-mediatek.c static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) · line 400
Quoted 5 lines
drivers/pci/controller/pcie-mediatek.c +1
-1@@ -397,7 +397,7 @@ static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)phys_addr_t addr;/* MT2712/MT7622 only support 32-bit MSI addresses */ - addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + addr =virt_to_phys ((__force void *)port->base +PCIE_MSI_VECTOR );
Lots of these drivers use either virt_to_phys() or platform_get_resource_byname() to get a physical address that they then use as the MSI target.
But I don't think that's quite right -- the MSI is a DMA transaction on PCI, and in general there's no guarantee that bus addresses are identical to CPU physical addresses, so shouldn't we use a dma_addr_t obtained from the DMA API?
dw_pcie_msi_host_init() has a complicated version of this that uses dmam_alloc_coherent().
Quoted 20 lines
drivers/pci/controller/pcie-mediatek.c +1
-1msg->address_hi =0 ; msg->address_lo =lower_32_bits (addr);@@ -520,7 +520,7 @@ static void mtk_pcie_enable_msi(struct mtk_pcie_port *port)u32 val;phys_addr_t msg_addr; - msg_addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + msg_addr =virt_to_phys ((__force void *)port->base +PCIE_MSI_VECTOR ); val =lower_32_bits (msg_addr);writel (val, port->base +PCIE_IMSI_ADDR );Signature · 7 lines
2.40.0.1.gaa8946217a0b _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 1 line · Bjorn Helgaas
On Thu, Sep 14, 2023 at 10:23:24PM +0300, Andy Shevchenko wrote:
...
Quoted 7 lines
drivers/pci/controller/pcie-mediatek.c static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) · line 400
Quoted 2 lines
drivers/pci/controller/pcie-mediatek.c +1
-1- addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + addr =virt_to_phys ((__force void *)port->base +PCIE_MSI_VECTOR );Lots of these drivers use either
virt_to_phys()orplatform_get_resource_byname()to get a physical address that they then use as the MSI target.
Quoted 7 lines
But I don't think that's quite right -- the MSI is a DMA transaction on PCI, and in general there's no guarantee that bus addresses are identical to CPU physical addresses, so shouldn't we use a
dma_addr_tobtained from the DMA API?
dw_pcie_msi_host_init()has a complicated version of this that usesdmam_alloc_coherent().
Fair enough. I leave it to you then to get it fixed properly. Consider this as just a heads up for the old report.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 17 lines · Andy Shevchenko
Quoted 1 line · Bjorn Helgaas
On Thu, Sep 14, 2023 at 10:23:24PM +0300, Andy Shevchenko wrote:
...
Quoted 12 lines
drivers/pci/controller/pcie-mediatek.c static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) · line 400
Quoted 2 lines
drivers/pci/controller/pcie-mediatek.c +1
-1- addr =virt_to_phys (port->base +PCIE_MSI_VECTOR ); + addr =virt_to_phys ((__force void *)port->base +PCIE_MSI_VECTOR );Lots of these drivers use either
virt_to_phys()orplatform_get_resource_byname()to get a physical address that they then use as the MSI target.But I don't think that's quite right -- the MSI is a DMA transaction on PCI, and in general there's no guarantee that bus addresses are identical to CPU physical addresses, so shouldn't we use a
dma_addr_tobtained from the DMA API?
Quoted 5 lines
Quoted 2 lines
dw_pcie_msi_host_init()has a complicated version of this that usesdmam_alloc_coherent().Fair enough. I leave it to you then to get it fixed properly. Consider this as just a heads up for the old report.
Sounds good, thanks!
Bjorn