[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210422105538.76057-1-ameynarkhede03@gmail.com>
Date: Thu, 22 Apr 2021 16:25:38 +0530
From: Amey Narkhede <ameynarkhede03@...il.com>
To: Bjorn Helgaas <bhelgaas@...gle.com>
Cc: linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
Leon Romanovsky <leon@...nel.org>,
Amey Narkhede <ameynarkhede03@...il.com>
Subject: [PATCH v2] PCI: Check value of resource alignment before using __ffs
Return value of __ffs is undefined if no set bit exists in
its argument. This indicates that the associated BAR has
invalid alignment.
Signed-off-by: Amey Narkhede <ameynarkhede03@...il.com>
---
drivers/pci/setup-bus.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 2ce636937c6e..ce5380bdd2fd 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1044,10 +1044,11 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
* resources.
*/
align = pci_resource_alignment(dev, r);
- order = __ffs(align) - 20;
- if (order < 0)
- order = 0;
- if (order >= ARRAY_SIZE(aligns)) {
+ if (align) {
+ order = __ffs(align) - 20;
+ order = (order < 0) ? 0 : order;
+ }
+ if (!align || order >= ARRAY_SIZE(aligns)) {
pci_warn(dev, "disabling BAR %d: %pR (bad alignment %#llx)\n",
i, r, (unsigned long long) align);
r->flags = 0;
--
2.31.1
Powered by blists - more mailing lists