[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250828101237.1359212-1-anders.roxell@linaro.org>
Date: Thu, 28 Aug 2025 12:12:37 +0200
From: Anders Roxell <anders.roxell@...aro.org>
To: bhelgaas@...gle.com
Cc: kees@...nel.org,
ojeda@...nel.org,
linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org,
arnd@...db.de,
dan.carpenter@...aro.org,
benjamin.copeland@...aro.org,
Anders Roxell <anders.roxell@...aro.org>,
Linux Kernel Functional Testing <lkft@...aro.org>
Subject: [PATCH] drivers/pci: Fix FIELD_PREP compilation error with gcc-8
Commit cbc654d18d37 ("bitops: Add __attribute_const__ to generic
ffs()-family implementations") causes a compilation failure on ARM
footbridge_defconfig with gcc-8:
FIELD_PREP: value too large for the field
The error occurs in pcie_set_readrq() at:
v = FIELD_PREP(PCI_EXP_DEVCTL_READRQ, ffs(rq) - 8);
With __attribute_const__, gcc-8 now performs wrong compile-time
validation in FIELD_PREP and cannot guarantee that ffs(rq) - 8 will
always produce values that fit in the 3-bit PCI_EXP_DEVCTL_READRQ field.
Avoid FIELD_PREP entirely by using direct bit manipulation. Replace
FIELD_PREP(PCI_EXP_DEVCTL_READRQ, ffs(rq) - 8) with the equivalent
manual bit operations: ((ffs(rq) - 8) << 12) & PCI_EXP_DEVCTL_READRQ.
This bypasses the compile-time validation while maintaining identical
runtime behavior and functionality.
Fixes: cbc654d18d37 ("bitops: Add __attribute_const__ to generic ffs()-family implementations")
Reported-by: Linux Kernel Functional Testing <lkft@...aro.org>
Closes: https://lore.kernel.org/linux-pci/CA+G9fYuysVr6qT8bjF6f08WLyCJRG7aXAeSd2F7=zTaHHd7L+Q@mail.gmail.com/T/#u
Signed-off-by: Anders Roxell <anders.roxell@...aro.org>
---
drivers/pci/pci.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e698278229f2..9f9607bd9f51 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5893,7 +5893,8 @@ int pcie_set_readrq(struct pci_dev *dev, int rq)
rq = mps;
}
- v = FIELD_PREP(PCI_EXP_DEVCTL_READRQ, ffs(rq) - 8);
+ /* Ideally we would used FIELD_PREP() but this is a work around for gcc-8 */
+ v = ((ffs(rq) - 8) << 12) & PCI_EXP_DEVCTL_READRQ;
if (bridge->no_inc_mrrs) {
int max_mrrs = pcie_get_readrq(dev);
--
2.50.1
Powered by blists - more mailing lists