* [PATCH] spi: Mediatek: fix endian warnings
@ 2015-08-11 10:43 Leilk Liu
2015-08-12 14:45 ` Jonas Gorski
[not found] ` <1439289789-29026-1-git-send-email-leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
0 siblings, 2 replies; 8+ messages in thread
From: Leilk Liu @ 2015-08-11 10:43 UTC (permalink / raw)
To: Mark Brown
Cc: Mark Rutland, Matthias Brugger, Sascha Hauer, devicetree,
linux-kernel, linux-arm-kernel, linux-spi, linux-mediatek,
Leilk Liu
This patch fixes endian warnings detected by sparse:
- sparse: incorrect type in argument 1 (different base types)
expected unsigned int [unsigned] val
got restricted __le32 [usertype] <noident>
- sparse: incorrect type in argument 1 (different base types)
expected unsigned int [unsigned] val
got restricted __le32 [usertype] <noident>
Signed-off-by: Leilk Liu <leilk.liu@mediatek.com>
---
drivers/spi/spi-mt65xx.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
index 4676b01..ae645fa 100644
--- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c
@@ -359,9 +359,11 @@ static void mtk_spi_setup_dma_addr(struct spi_master *master,
struct mtk_spi *mdata = spi_master_get_devdata(master);
if (mdata->tx_sgl)
- writel(cpu_to_le32(xfer->tx_dma), mdata->base + SPI_TX_SRC_REG);
+ writel((__force u32)cpu_to_le32(xfer->tx_dma),
+ mdata->base + SPI_TX_SRC_REG);
if (mdata->rx_sgl)
- writel(cpu_to_le32(xfer->rx_dma), mdata->base + SPI_RX_DST_REG);
+ writel((__force u32)cpu_to_le32(xfer->rx_dma),
+ mdata->base + SPI_RX_DST_REG);
}
static int mtk_spi_fifo_transfer(struct spi_master *master,
--
1.8.1.1.dirty
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] spi: Mediatek: fix endian warnings
2015-08-11 10:43 [PATCH] spi: Mediatek: fix endian warnings Leilk Liu
@ 2015-08-12 14:45 ` Jonas Gorski
[not found] ` <CAOiHx=mrDhxkMd5WVTpayyyxXHUDRTELubErynN3qd-v5qpCfw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
[not found] ` <1439289789-29026-1-git-send-email-leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
1 sibling, 1 reply; 8+ messages in thread
From: Jonas Gorski @ 2015-08-12 14:45 UTC (permalink / raw)
To: Leilk Liu
Cc: Mark Brown, Mark Rutland, Matthias Brugger, Sascha Hauer,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-spi, linux-mediatek
Hi,
On Tue, Aug 11, 2015 at 12:43 PM, Leilk Liu <leilk.liu@mediatek.com> wrote:
> This patch fixes endian warnings detected by sparse:
> - sparse: incorrect type in argument 1 (different base types)
> expected unsigned int [unsigned] val
> got restricted __le32 [usertype] <noident>
> - sparse: incorrect type in argument 1 (different base types)
> expected unsigned int [unsigned] val
> got restricted __le32 [usertype] <noident>
This doesn't "fix" the warning, it only hides the warning and leaves
the actual issue unfixed.
>
> Signed-off-by: Leilk Liu <leilk.liu@mediatek.com>
> ---
> drivers/spi/spi-mt65xx.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
> index 4676b01..ae645fa 100644
> --- a/drivers/spi/spi-mt65xx.c
> +++ b/drivers/spi/spi-mt65xx.c
> @@ -359,9 +359,11 @@ static void mtk_spi_setup_dma_addr(struct spi_master *master,
> struct mtk_spi *mdata = spi_master_get_devdata(master);
>
> if (mdata->tx_sgl)
> - writel(cpu_to_le32(xfer->tx_dma), mdata->base + SPI_TX_SRC_REG);
> + writel((__force u32)cpu_to_le32(xfer->tx_dma),
> + mdata->base + SPI_TX_SRC_REG);
> if (mdata->rx_sgl)
> - writel(cpu_to_le32(xfer->rx_dma), mdata->base + SPI_RX_DST_REG);
> + writel((__force u32)cpu_to_le32(xfer->rx_dma),
> + mdata->base + SPI_RX_DST_REG);
The issue here is that writel already does a cpu_to_le32 conversion,
so the extra cpu_to_le32 calls are actually bogus and need to be
removed. Else it will do a double conversion on big endian systems,
resulting in the data being written in big endian.
Jonas
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <1439289789-29026-1-git-send-email-leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>]
* Re: [PATCH] spi: Mediatek: fix endian warnings
[not found] ` <1439289789-29026-1-git-send-email-leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
@ 2015-08-15 20:16 ` Arnd Bergmann
2015-08-15 20:17 ` Arnd Bergmann
2015-08-16 14:06 ` Russell King - ARM Linux
0 siblings, 2 replies; 8+ messages in thread
From: Arnd Bergmann @ 2015-08-15 20:16 UTC (permalink / raw)
To: Leilk Liu
Cc: Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA, Sascha Hauer,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-spi-u79uwXL29TY76Z2rM5mHXA, Mark Brown,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Matthias Brugger,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On Tuesday 11 August 2015 18:43:09 Leilk Liu wrote:
> @@ -359,9 +359,11 @@ static void mtk_spi_setup_dma_addr(struct spi_master *master,
> struct mtk_spi *mdata = spi_master_get_devdata(master);
>
> if (mdata->tx_sgl)
> - writel(cpu_to_le32(xfer->tx_dma), mdata->base + SPI_TX_SRC_REG);
> + writel((__force u32)cpu_to_le32(xfer->tx_dma),
> + mdata->base + SPI_TX_SRC_REG);
> if (mdata->rx_sgl)
> - writel(cpu_to_le32(xfer->rx_dma), mdata->base + SPI_RX_DST_REG);
> + writel((__force u32)cpu_to_le32(xfer->rx_dma),
> + mdata->base + SPI_RX_DST_REG);
> }
>
This looks wrong: writel takes a CPU-endian argument, so the value returned
from cpu_to_le32() is not appropriate.
The warning is correct, and you have to remove the cpu_to_le32() conversion
in order to get the driver to behave correctly when the kernel is built
as big-endian.
Arnd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] spi: Mediatek: fix endian warnings
2015-08-15 20:16 ` Arnd Bergmann
@ 2015-08-15 20:17 ` Arnd Bergmann
2015-08-16 14:06 ` Russell King - ARM Linux
1 sibling, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2015-08-15 20:17 UTC (permalink / raw)
To: Leilk Liu
Cc: Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA, Sascha Hauer,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-spi-u79uwXL29TY76Z2rM5mHXA, Mark Brown,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Matthias Brugger,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On Saturday 15 August 2015 22:16:03 Arnd Bergmann wrote:
> On Tuesday 11 August 2015 18:43:09 Leilk Liu wrote:
> > @@ -359,9 +359,11 @@ static void mtk_spi_setup_dma_addr(struct spi_master *master,
> > struct mtk_spi *mdata = spi_master_get_devdata(master);
> >
> > if (mdata->tx_sgl)
> > - writel(cpu_to_le32(xfer->tx_dma), mdata->base + SPI_TX_SRC_REG);
> > + writel((__force u32)cpu_to_le32(xfer->tx_dma),
> > + mdata->base + SPI_TX_SRC_REG);
> > if (mdata->rx_sgl)
> > - writel(cpu_to_le32(xfer->rx_dma), mdata->base + SPI_RX_DST_REG);
> > + writel((__force u32)cpu_to_le32(xfer->rx_dma),
> > + mdata->base + SPI_RX_DST_REG);
> > }
> >
>
> This looks wrong: writel takes a CPU-endian argument, so the value returned
> from cpu_to_le32() is not appropriate.
>
> The warning is correct, and you have to remove the cpu_to_le32() conversion
> in order to get the driver to behave correctly when the kernel is built
> as big-endian.
Nevermind, I now saw the issue has already been raised.
Arnd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] spi: Mediatek: fix endian warnings
2015-08-15 20:16 ` Arnd Bergmann
2015-08-15 20:17 ` Arnd Bergmann
@ 2015-08-16 14:06 ` Russell King - ARM Linux
[not found] ` <20150816140639.GE7557-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
1 sibling, 1 reply; 8+ messages in thread
From: Russell King - ARM Linux @ 2015-08-16 14:06 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Leilk Liu, Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA,
Sascha Hauer, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-spi-u79uwXL29TY76Z2rM5mHXA, Mark Brown,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Matthias Brugger,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On Sat, Aug 15, 2015 at 10:16:03PM +0200, Arnd Bergmann wrote:
> On Tuesday 11 August 2015 18:43:09 Leilk Liu wrote:
> > @@ -359,9 +359,11 @@ static void mtk_spi_setup_dma_addr(struct spi_master *master,
> > struct mtk_spi *mdata = spi_master_get_devdata(master);
> >
> > if (mdata->tx_sgl)
> > - writel(cpu_to_le32(xfer->tx_dma), mdata->base + SPI_TX_SRC_REG);
> > + writel((__force u32)cpu_to_le32(xfer->tx_dma),
> > + mdata->base + SPI_TX_SRC_REG);
> > if (mdata->rx_sgl)
> > - writel(cpu_to_le32(xfer->rx_dma), mdata->base + SPI_RX_DST_REG);
> > + writel((__force u32)cpu_to_le32(xfer->rx_dma),
> > + mdata->base + SPI_RX_DST_REG);
> > }
> >
>
> This looks wrong: writel takes a CPU-endian argument, so the value returned
> from cpu_to_le32() is not appropriate.
>
> The warning is correct, and you have to remove the cpu_to_le32() conversion
> in order to get the driver to behave correctly when the kernel is built
> as big-endian.
Indeed, it's about time people started thinking more about the warnings
and why we have coded things in the way we have.
Look people. cpu_to_le32() takes a value in the CPU endian, and
converts it to a little endian 32-bit number. See, the clue is in
the name.
All writel() implementations take a CPU number and write it in little
endian format. Hence, writel() almost always uses cpu_to_le32()
internally.
Now think about what you're saying with "cpu_to_le32(cpu_to_le32())".
It's utter rubbish, total crap. It's wrong no matter which way you
look at it.
We have le32_to_cpu() which does what it says on the tin. Same with
be32_to_cpu() and cpu_to_be32().
Don't hack around this stuff with __force. If you're having to use
__force to get rid of a warning here, you _ARE_ doing something wrong,
no questions about that. __force in driver code is a definite sign
that you are doing something wrong. Don't do it. Ask the question
if you think you need it.
--
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-08-17 3:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-11 10:43 [PATCH] spi: Mediatek: fix endian warnings Leilk Liu
2015-08-12 14:45 ` Jonas Gorski
[not found] ` <CAOiHx=mrDhxkMd5WVTpayyyxXHUDRTELubErynN3qd-v5qpCfw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-13 2:11 ` lei liu
2015-08-13 9:19 ` Mark Brown
[not found] ` <1439289789-29026-1-git-send-email-leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2015-08-15 20:16 ` Arnd Bergmann
2015-08-15 20:17 ` Arnd Bergmann
2015-08-16 14:06 ` Russell King - ARM Linux
[not found] ` <20150816140639.GE7557-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2015-08-17 3:30 ` Mark Brown
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).