Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1208240
| From | Russell King - ARM Linux <linux@arm.linux.org.uk> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] spi: Mediatek: fix endian warnings |
| Date | 2015-08-16 16:10 +0200 |
| Message-ID | <pY6Nj-2kR-1@gated-at.bofh.it> (permalink) |
| References | <pWfi2-2FR-5@gated-at.bofh.it> <pXQ5Q-3xm-13@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] spi: Mediatek: fix endian warnings Leilk Liu <leilk.liu@mediatek.com> - 2015-08-11 12:50 +0200
Re: [PATCH] spi: Mediatek: fix endian warnings Jonas Gorski <jogo@openwrt.org> - 2015-08-12 16:50 +0200
Re: [PATCH] spi: Mediatek: fix endian warnings lei liu <leilk.liu@mediatek.com> - 2015-08-13 04:20 +0200
Re: [PATCH] spi: Mediatek: fix endian warnings Mark Brown <broonie@kernel.org> - 2015-08-13 11:30 +0200
Re: [PATCH] spi: Mediatek: fix endian warnings Arnd Bergmann <arnd@arndb.de> - 2015-08-15 22:20 +0200
Re: [PATCH] spi: Mediatek: fix endian warnings Arnd Bergmann <arnd@arndb.de> - 2015-08-15 22:20 +0200
Re: [PATCH] spi: Mediatek: fix endian warnings Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-08-16 16:10 +0200
Re: [PATCH] spi: Mediatek: fix endian warnings Mark Brown <broonie@kernel.org> - 2015-08-17 05:40 +0200
csiph-web