From: Colin King <colin.king@canonical.com>
To: Bjorn Helgaas <bhelgaas@google.com>,
Puranjay Mohan <puranjay12@gmail.com>,
linux-pci@vger.kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH][next] PCI/ASPM: fix an unintended sign extension of a u16
Date: Fri, 2 Oct 2020 17:23:18 +0100 [thread overview]
Message-ID: <20201002162318.93555-1-colin.king@canonical.com> (raw)
From: Colin Ian King <colin.king@canonical.com>
The multiplication of the u16 variable 'value' causes it to be
prompted to a int type and this is then sign extended to a u64.
When the result of the multiplication is > 0x7fffffff the upper
bits are all unitentionally set to 1 on a sign extension operation.
Fix this by explicitly casting value to a u64 to avoid the int
type promotion and the following sign extension.
Addresses-Coverity: ("Unintended sign extension")
Fixes: 5ccf2a6e483f ("PCI/ASPM: Add support for LTR _DSM")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/pci/pci.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index db8feb2033e7..736197f9094b 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3083,8 +3083,8 @@ static u64 pci_ltr_decode(u16 latency)
case 1: return value * 32;
case 2: return value * 1024;
case 3: return value * 32768;
- case 4: return value * 1048576;
- case 5: return value * 33554432;
+ case 4: return (uint64_t)value * 1048576;
+ case 5: return (uint64_t)value * 33554432;
}
return 0;
}
--
2.27.0
reply other threads:[~2020-10-02 16:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20201002162318.93555-1-colin.king@canonical.com \
--to=colin.king@canonical.com \
--cc=bhelgaas@google.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=puranjay12@gmail.com \
/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).