]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
PCI: designware: Require config accesses to be naturally aligned
authorGabriele Paoloni <gabriele.paoloni@huawei.com>
Thu, 8 Oct 2015 19:27:53 +0000 (14:27 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 2 Nov 2015 20:48:45 +0000 (14:48 -0600)
Add sanity checks on "addr" input parameter in dw_pcie_cfg_read() and
dw_pcie_cfg_write().  These checks make sure that accesses are aligned on
their size, e.g., a 4-byte config access is aligned on a 4-byte boundary.

[bhelgaas: changelog, set *val = 0 in failure case]
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
drivers/pci/host/pcie-designware.c

index 759cd0a509104c1078c0df10242c4e8579329f7a..b77535f3967b98a031024aab5c9fd6d627ef6ad0 100644 (file)
@@ -82,6 +82,11 @@ static inline struct pcie_port *sys_to_pcie(struct pci_sys_data *sys)
 
 int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val)
 {
+       if ((uintptr_t)addr & (size - 1)) {
+               *val = 0;
+               return PCIBIOS_BAD_REGISTER_NUMBER;
+       }
+
        if (size == 4)
                *val = readl(addr);
        else if (size == 2)
@@ -98,6 +103,9 @@ int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val)
 
 int dw_pcie_cfg_write(void __iomem *addr, int size, u32 val)
 {
+       if ((uintptr_t)addr & (size - 1))
+               return PCIBIOS_BAD_REGISTER_NUMBER;
+
        if (size == 4)
                writel(val, addr);
        else if (size == 2)