summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>2025-12-19 19:40:25 +0200
committerBjorn Helgaas <bhelgaas@google.com>2026-01-27 16:36:52 -0600
commitc10fe0c0e6977254e2b7d4fed18e71501c958d65 (patch)
treea4336d6ee96afa29fde7d30f599c1bf7893b2d07
parent9629f71722bb994f4b95088bc37a14f9aeaa5f90 (diff)
PCI: Check invalid align earlier in pbus_size_mem()
Check for invalid align before any bridge window sizing actions in pbus_size_mem() to avoid need to roll back any sizing calculations. Placing the check earlier will make it easier to add more optional size related calculations at where the SR-IOV logic currently is in pbus_size_mem(). Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Link: https://patch.msgid.link/20251219174036.16738-13-ilpo.jarvinen@linux.intel.com
-rw-r--r--drivers/pci/setup-bus.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index a5b6c555a45b..3d1d3cefcdba 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -19,6 +19,7 @@
#include <linux/bug.h>
#include <linux/init.h>
#include <linux/kernel.h>
+#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/errno.h>
@@ -1311,31 +1312,29 @@ static void pbus_size_mem(struct pci_bus *bus, struct resource *b_res,
continue;
r_size = resource_size(r);
-
- /* Put SRIOV requested res to the optional list */
- if (realloc_head && pci_resource_is_optional(dev, i)) {
- add_align = max(pci_resource_alignment(dev, r), add_align);
- add_to_list(realloc_head, dev, r, 0, 0 /* Don't care */);
- children_add_size += r_size;
- continue;
- }
-
+ align = pci_resource_alignment(dev, r);
/*
* aligns[0] is for 1MB (since bridge memory
* windows are always at least 1MB aligned), so
* keep "order" from being negative for smaller
* resources.
*/
- align = pci_resource_alignment(dev, r);
- order = __ffs(align) - __ffs(SZ_1M);
- if (order < 0)
- order = 0;
+ order = max_t(int, __ffs(align) - __ffs(SZ_1M), 0);
if (order >= ARRAY_SIZE(aligns)) {
pci_warn(dev, "%s %pR: disabling; bad alignment %#llx\n",
r_name, r, (unsigned long long) align);
r->flags = 0;
continue;
}
+
+ /* Put SRIOV requested res to the optional list */
+ if (realloc_head && pci_resource_is_optional(dev, i)) {
+ add_align = max(align, add_align);
+ add_to_list(realloc_head, dev, r, 0, 0 /* Don't care */);
+ children_add_size += r_size;
+ continue;
+ }
+
size += max(r_size, align);
aligns[order] += align;