Skip to content

Commit e3bdd2d

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: Add ALIGN_DOWN_IF_NONZERO() helper
pci_bus_distribute_available_resources() performs alignment in case of non-zero alignment requirement on three occasions. Add ALIGN_DOWN_IF_NONZERO() helper to avoid coding the non-zero check three times. Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/20240614100606.15830-5-ilpo.jarvinen@linux.intel.com Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 9d3faf2 commit e3bdd2d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/pci/setup-bus.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,9 @@ static void remove_dev_resources(struct pci_dev *dev, struct resource *io,
18941894
}
18951895
}
18961896

1897+
#define ALIGN_DOWN_IF_NONZERO(addr, align) \
1898+
((align) ? ALIGN_DOWN((addr), (align)) : (addr))
1899+
18971900
/*
18981901
* io, mmio and mmio_pref contain the total amount of bridge window space
18991902
* available. This includes the minimal space needed to cover all the
@@ -2005,8 +2008,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
20052008
* what is available).
20062009
*/
20072010
align = pci_resource_alignment(dev, res);
2008-
resource_set_size(&io, align ? ALIGN_DOWN(io_per_b, align)
2009-
: io_per_b);
2011+
resource_set_size(&io, ALIGN_DOWN_IF_NONZERO(io_per_b, align));
20102012

20112013
/*
20122014
* The x_per_b holds the extra resource space that can be
@@ -2018,15 +2020,14 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
20182020

20192021
res = &dev->resource[PCI_BRIDGE_MEM_WINDOW];
20202022
align = pci_resource_alignment(dev, res);
2021-
resource_set_size(&mmio, align ? ALIGN_DOWN(mmio_per_b, align)
2022-
: mmio_per_b);
2023+
resource_set_size(&mmio,
2024+
ALIGN_DOWN_IF_NONZERO(mmio_per_b,align));
20232025
mmio.start -= resource_size(res);
20242026

20252027
res = &dev->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
20262028
align = pci_resource_alignment(dev, res);
20272029
resource_set_size(&mmio_pref,
2028-
align ? ALIGN_DOWN(mmio_pref_per_b, align)
2029-
: mmio_pref_per_b);
2030+
ALIGN_DOWN_IF_NONZERO(mmio_pref_per_b, align));
20302031
mmio_pref.start -= resource_size(res);
20312032

20322033
pci_bus_distribute_available_resources(b, add_list, io, mmio,

0 commit comments

Comments
 (0)