From: Colin King <colin.king@canonical.com>
To: Mark Brown <broonie@kernel.org>, linux-spi@vger.kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] spi: loopback-test: fix potential integer overflow on multiple
Date: Mon, 20 Mar 2017 13:58:05 +0000 [thread overview]
Message-ID: <20170320135805.10182-1-colin.king@canonical.com> (raw)
From: Colin Ian King <colin.king@canonical.com>
A multiplication of 8U * xfer-len with the type of a 32 bit unsigned int
is evaluated using 32 bit arithmetic and then used in a context that
expects an expression of type unsigned long long (64 bits). Avoid any
potential overflow by casting BITS_PER_BYTE to unsigned long long.
Detected by CoverityScan, CID#1419691 ("Unintentional integer overflow")
Fixes: ea9936f324356 ("spi: loopback-test: add elapsed time check")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/spi/spi-loopback-test.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 0d0739142cd3..51c0ceab04cc 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -521,7 +521,8 @@ static int spi_test_check_elapsed_time(struct spi_device *spi,
for (i = 0; i < test->transfer_count; i++) {
struct spi_transfer *xfer = test->transfers + i;
- unsigned long long nbits = BITS_PER_BYTE * xfer->len;
+ unsigned long long nbits = (unsigned long long)BITS_PER_BYTE *
+ xfer->len;
delay_usecs += xfer->delay_usecs;
if (!xfer->speed_hz)
--
2.11.0
next reply other threads:[~2017-03-20 13:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-20 13:58 Colin King [this message]
2017-03-21 18:46 ` Applied "spi: loopback-test: fix potential integer overflow on multiple" to the spi tree Mark Brown
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=20170320135805.10182-1-colin.king@canonical.com \
--to=colin.king@canonical.com \
--cc=broonie@kernel.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@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).