Skip to content

Commit d4f09ea

Browse files
sumitsemwalgregkh
authored andcommitted
PCI: Update BARs using property bits appropriate for type
From: Bjorn Helgaas <bhelgaas@google.com> [ Upstream commit 45d004f4afefdd8d79916ee6d97a9ecd94bb1ffe ] The BAR property bits (0-3 for memory BARs, 0-1 for I/O BARs) are supposed to be read-only, but we do save them in res->flags and include them when updating the BAR. Mask the I/O property bits with ~PCI_BASE_ADDRESS_IO_MASK (0x3) instead of PCI_REGION_FLAG_MASK (0xf) to make it obvious that we can't corrupt bits 2-3 of I/O addresses. Use PCI_ROM_ADDRESS_MASK for ROM BARs. This means we'll only check the top 21 bits (instead of the 28 bits we used to check) of a ROM BAR to see if the update was successful. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 131f796 commit d4f09ea

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

drivers/pci/setup-res.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,17 @@ static void pci_std_update_resource(struct pci_dev *dev, int resno)
5858
return;
5959

6060
pcibios_resource_to_bus(dev->bus, &region, res);
61+
new = region.start;
6162

62-
new = region.start | (res->flags & PCI_REGION_FLAG_MASK);
63-
if (res->flags & IORESOURCE_IO)
63+
if (res->flags & IORESOURCE_IO) {
6464
mask = (u32)PCI_BASE_ADDRESS_IO_MASK;
65-
else
65+
new |= res->flags & ~PCI_BASE_ADDRESS_IO_MASK;
66+
} else if (resno == PCI_ROM_RESOURCE) {
67+
mask = (u32)PCI_ROM_ADDRESS_MASK;
68+
} else {
6669
mask = (u32)PCI_BASE_ADDRESS_MEM_MASK;
70+
new |= res->flags & ~PCI_BASE_ADDRESS_MEM_MASK;
71+
}
6772

6873
if (resno < PCI_ROM_RESOURCE) {
6974
reg = PCI_BASE_ADDRESS_0 + 4 * resno;

0 commit comments

Comments
 (0)