Skip to content

Commit b6b18f5

Browse files
g00308965bjorn-helgaas
authored andcommitted
PCI: designware: Require config accesses to be naturally aligned
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>
1 parent 4c45852 commit b6b18f5

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎drivers/pci/host/pcie-designware.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ static inline struct pcie_port *sys_to_pcie(struct pci_sys_data *sys)
8282

8383
int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val)
8484
{
85+
if ((uintptr_t)addr & (size - 1)) {
86+
*val = 0;
87+
return PCIBIOS_BAD_REGISTER_NUMBER;
88+
}
89+
8590
if (size == 4)
8691
*val = readl(addr);
8792
else if (size == 2)
@@ -98,6 +103,9 @@ int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val)
98103

99104
int dw_pcie_cfg_write(void __iomem *addr, int size, u32 val)
100105
{
106+
if ((uintptr_t)addr & (size - 1))
107+
return PCIBIOS_BAD_REGISTER_NUMBER;
108+
101109
if (size == 4)
102110
writel(val, addr);
103111
else if (size == 2)

0 commit comments

Comments
 (0)