PCI: endpoint: Cast the page number to phys_addr_t
Subsystems (2)
PATCH v2 1/1 PCI: endpoint: Cast the page number to phys_addr_t
From: Alan Mikhak <[email protected]>
Modify pci_epc_mem_alloc_addr() to cast the variable 'pageno' from type 'int' to 'phys_addr_t' before shifting left. This cast is needed to avoid treating bit 31 of 'pageno' as the sign bit which would otherwise get sign-extended to produce a negative value. When added to the base address of PCI memory space, the negative value would produce an invalid physical address which falls before the start of the PCI memory space.
--- drivers/pci/endpoint/pci-epc-mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/pci-epc-mem.c +1 -1
@@ -134,7 +134,7 @@ void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,if (pageno <0 )return NULL ; - *phys_addr = mem->phys_base + (pageno << page_shift); + *phys_addr = mem->phys_base + ((phys_addr_t )pageno << page_shift); virt_addr =ioremap (*phys_addr, size);if (!virt_addr)bitmap_release_region (mem->bitmap, pageno, order);
Signature · 1 line
2.7.4
Lorenzo Pieralisi
AppliedQuoted 10 lines · Alan Mikhak
From: Alan Mikhak <[email protected]>
Modify
pci_epc_mem_alloc_addr()to cast the variable 'pageno' from type 'int' to 'phys_addr_t' before shifting left. This cast is needed to avoid treating bit 31 of 'pageno' as the sign bit which would otherwise get sign-extended to produce a negative value. When added to the base address of PCI memory space, the negative value would produce an invalid physical address which falls before the start of the PCI memory space.
Quoted 5 lines
Signed-off-by Alan Mikhak <[email protected]>--- drivers/pci/endpoint/pci-epc-mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to pci/endpoint, thanks.
Lorenzo
Quoted 16 lines
drivers/pci/endpoint/pci-epc-mem.c +1
-1@@ -134,7 +134,7 @@ void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,if (pageno <0 )return NULL ; - *phys_addr = mem->phys_base + (pageno << page_shift); + *phys_addr = mem->phys_base + ((phys_addr_t )pageno << page_shift); virt_addr =ioremap (*phys_addr, size);if (!virt_addr)bitmap_release_region (mem->bitmap, pageno, order);Signature · 1 line
2.7.4