* [PATCH v2] spi/xilinx: Fix access invalid memory on xilinx_spi_tx
@ 2015-02-02 10:06 Ricardo Ribalda Delgado
2015-02-02 12:17 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-02-02 10:06 UTC (permalink / raw)
To: Mark Brown, Michal Simek, Sören Brinkmann, linux-spi,
linux-arm-kernel, linux-kernel
Cc: Ricardo Ribalda Delgado
On 1 and 2 bytes per word, the transfer of the 3 last bytes will access
memory outside tx_ptr.
Although this has not trigger any error on real hardware, we should
better fix this.
Fixes: 24ba5e593f391507 Remove rx_fn and tx_fn pointer
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
v2:
v1 was completely wrong, sorry about that :(. This v2 has been tested on x86
1 byte per word
drivers/spi/spi-xilinx.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c
index d1901d5..133f53a 100644
--- a/drivers/spi/spi-xilinx.c
+++ b/drivers/spi/spi-xilinx.c
@@ -117,11 +117,26 @@ static unsigned int xspi_read32_be(void __iomem *addr)
static void xilinx_spi_tx(struct xilinx_spi *xspi)
{
+ u32 data = 0;
+
if (!xspi->tx_ptr) {
xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET);
return;
}
- xspi->write_fn(*(u32 *)(xspi->tx_ptr), xspi->regs + XSPI_TXD_OFFSET);
+
+ switch (xspi->bytes_per_word) {
+ case 1:
+ data = *(u8 *)(xspi->tx_ptr);
+ break;
+ case 2:
+ data = *(u16 *)(xspi->tx_ptr);
+ break;
+ case 4:
+ data = *(u32 *)(xspi->tx_ptr);
+ break;
+ }
+
+ xspi->write_fn(data, xspi->regs + XSPI_TXD_OFFSET);
xspi->tx_ptr += xspi->bytes_per_word;
}
--
2.1.4
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] spi/xilinx: Fix access invalid memory on xilinx_spi_tx
2015-02-02 10:06 [PATCH v2] spi/xilinx: Fix access invalid memory on xilinx_spi_tx Ricardo Ribalda Delgado
@ 2015-02-02 12:17 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2015-02-02 12:17 UTC (permalink / raw)
To: Ricardo Ribalda Delgado
Cc: Michal Simek, Sören Brinkmann, linux-spi, linux-arm-kernel,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 400 bytes --]
On Mon, Feb 02, 2015 at 11:06:56AM +0100, Ricardo Ribalda Delgado wrote:
> On 1 and 2 bytes per word, the transfer of the 3 last bytes will access
> memory outside tx_ptr.
>
> Although this has not trigger any error on real hardware, we should
> better fix this.
>
> Fixes: 24ba5e593f391507 Remove rx_fn and tx_fn pointer
Applied, thanks. Fixes: usually has () around the commit title.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-02-02 12:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-02 10:06 [PATCH v2] spi/xilinx: Fix access invalid memory on xilinx_spi_tx Ricardo Ribalda Delgado
2015-02-02 12:17 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®