Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ilpo Järvinen and committed by
Bjorn Helgaas
e3bdd2dd 9d3faf22

+7 -6
+7 -6
drivers/pci/setup-bus.c
··· 1894 1894 } 1895 1895 } 1896 1896 1897 + #define ALIGN_DOWN_IF_NONZERO(addr, align) \ 1898 + ((align) ? ALIGN_DOWN((addr), (align)) : (addr)) 1899 + 1897 1900 /* 1898 1901 * io, mmio and mmio_pref contain the total amount of bridge window space 1899 1902 * available. This includes the minimal space needed to cover all the ··· 2008 2005 * what is available). 2009 2006 */ 2010 2007 align = pci_resource_alignment(dev, res); 2011 - resource_set_size(&io, align ? ALIGN_DOWN(io_per_b, align) 2012 - : io_per_b); 2008 + resource_set_size(&io, ALIGN_DOWN_IF_NONZERO(io_per_b, align)); 2013 2009 2014 2010 /* 2015 2011 * The x_per_b holds the extra resource space that can be ··· 2020 2018 2021 2019 res = &dev->resource[PCI_BRIDGE_MEM_WINDOW]; 2022 2020 align = pci_resource_alignment(dev, res); 2023 - resource_set_size(&mmio, align ? ALIGN_DOWN(mmio_per_b, align) 2024 - : mmio_per_b); 2021 + resource_set_size(&mmio, 2022 + ALIGN_DOWN_IF_NONZERO(mmio_per_b,align)); 2025 2023 mmio.start -= resource_size(res); 2026 2024 2027 2025 res = &dev->resource[PCI_BRIDGE_PREF_MEM_WINDOW]; 2028 2026 align = pci_resource_alignment(dev, res); 2029 2027 resource_set_size(&mmio_pref, 2030 - align ? ALIGN_DOWN(mmio_pref_per_b, align) 2031 - : mmio_pref_per_b); 2028 + ALIGN_DOWN_IF_NONZERO(mmio_pref_per_b, align)); 2032 2029 mmio_pref.start -= resource_size(res); 2033 2030 2034 2031 pci_bus_distribute_available_resources(b, add_list, io, mmio,