[PATCH v5 04/14] PCI: Use __ffs64() for resource_size_t typed align

From: Ilpo Järvinen

Date: Fri Nov 06 2026 - 08:46:07 EST


__ffs() inputs unsigned long. With some 32-bit configurations
resource_size_t can be 64 bits wide while unsigned long is only 32 bits
wide.

To prevent value truncation, convert __ffs() to __ffs64() when the
input is resource_size_t.

In practice >=4GB resource align is required for the problem to
manifest itself which might not be present on systems running 32-bit
kernels so the problem has not been noticed.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
---
drivers/pci/setup-bus.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 0c27cec83c0d..f4358322f766 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1315,7 +1315,7 @@ static void pbus_size_mem(struct pci_bus *bus, struct resource *b_res,
* keep "order" from being negative for smaller
* resources.
*/
- order = max_t(int, __ffs(align) - __ffs(SZ_1M), 0);
+ order = max_t(int, __ffs64(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);
--
2.47.3