From: Michal Nazarewicz <mpn@google.com>
To: Laxman Dewangan <ldewangan@nvidia.com>, Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-tegra@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] spi: tegra: avoid unsigned->signed->unsigned promotion
Date: Fri, 29 Nov 2013 18:12:44 +0100 [thread overview]
Message-ID: <1385745164-10534-1-git-send-email-mpn@google.com> (raw)
From: Michal Nazarewicz <mina86@mina86.com>
u8 type, which is unsigned, is promoted to int, which is singned, when
doing a binary shift. Then, on 64-bit machines, it is further promoted
to unsigned long which may lead to more significant half of the value
to be all ones. To avoid this, explicitly promote to an unsigned type.
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
---
drivers/spi/spi-tegra114.c | 4 ++--
drivers/spi/spi-tegra20-slink.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c
index aaecfb3..2dadc3f 100644
--- a/drivers/spi/spi-tegra114.c
+++ b/drivers/spi/spi-tegra114.c
@@ -315,7 +315,7 @@ static unsigned tegra_spi_fill_tx_fifo_from_client_txbuf(
for (count = 0; count < max_n_32bit; count++) {
x = 0;
for (i = 0; (i < 4) && nbytes; i++, nbytes--)
- x |= (*tx_buf++) << (i*8);
+ x |= (unsigned)(*tx_buf++) << (i*8);
tegra_spi_writel(tspi, x, SPI_TX_FIFO);
}
} else {
@@ -326,7 +326,7 @@ static unsigned tegra_spi_fill_tx_fifo_from_client_txbuf(
x = 0;
for (i = 0; nbytes && (i < tspi->bytes_per_word);
i++, nbytes--)
- x |= ((*tx_buf++) << i*8);
+ x |= (unsigned)(*tx_buf++) << (i*8);
tegra_spi_writel(tspi, x, SPI_TX_FIFO);
}
}
diff --git a/drivers/spi/spi-tegra20-slink.c b/drivers/spi/spi-tegra20-slink.c
index e66715b..0fc4f7d 100644
--- a/drivers/spi/spi-tegra20-slink.c
+++ b/drivers/spi/spi-tegra20-slink.c
@@ -331,7 +331,7 @@ static unsigned tegra_slink_fill_tx_fifo_from_client_txbuf(
for (count = 0; count < max_n_32bit; count++) {
x = 0;
for (i = 0; (i < 4) && nbytes; i++, nbytes--)
- x |= (*tx_buf++) << (i*8);
+ x |= (unsigned)(*tx_buf++) << (i*8);
tegra_slink_writel(tspi, x, SLINK_TX_FIFO);
}
} else {
@@ -342,7 +342,7 @@ static unsigned tegra_slink_fill_tx_fifo_from_client_txbuf(
x = 0;
for (i = 0; nbytes && (i < tspi->bytes_per_word);
i++, nbytes--)
- x |= ((*tx_buf++) << i*8);
+ x |= (unsigned)(*tx_buf++) << (i*8);
tegra_slink_writel(tspi, x, SLINK_TX_FIFO);
}
}
--
1.8.4.1
next reply other threads:[~2013-11-29 17:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-29 17:12 Michal Nazarewicz [this message]
2013-11-29 21:43 ` Thierry Reding
2013-12-02 13:05 ` Michal Nazarewicz
2013-12-08 15:35 ` [PATCH 0/3] spi: tegra: use u32 for 32-bit register values Michal Nazarewicz
2013-12-08 15:35 ` [PATCH 1/3] spi: tegra114: " Michal Nazarewicz
2013-12-08 15:35 ` [PATCH 2/3] spi: tegra20-slink: " Michal Nazarewicz
2013-12-08 15:35 ` [PATCH 3/3] spi: tegra20-sflash: " Michal Nazarewicz
2013-12-09 18:00 ` [PATCH 0/3] spi: tegra: " Stephen Warren
2013-12-09 18:14 ` 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=1385745164-10534-1-git-send-email-mpn@google.com \
--to=mpn@google.com \
--cc=broonie@kernel.org \
--cc=ldewangan@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=linux-tegra@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
Powered by JetHome