From: Amey Narkhede <ameynarkhede03@gmail.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Leon Romanovsky <leon@kernel.org>,
Amey Narkhede <ameynarkhede03@gmail.com>
Subject: [PATCH v2] PCI: Check value of resource alignment before using __ffs
Date: Thu, 22 Apr 2021 16:25:38 +0530 [thread overview]
Message-ID: <20210422105538.76057-1-ameynarkhede03@gmail.com> (raw)
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@gmail.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
next reply other threads:[~2021-04-22 10:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-22 10:55 Amey Narkhede [this message]
2021-04-22 10:57 ` [PATCH v2] PCI: Check value of resource alignment before using __ffs Leon Romanovsky
2021-05-24 20:32 ` Amey Narkhede
2021-05-25 22:01 ` Bjorn Helgaas
2021-05-26 9:06 ` Amey Narkhede
2021-05-28 0:04 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210422105538.76057-1-ameynarkhede03@gmail.com \
--to=ameynarkhede03@gmail.com \
--cc=bhelgaas@google.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).