linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/3] SPI: spi_sh_msiof: fix wrong address calculation, which leads to an Oops
@ 2011-01-21 15:56 Guennadi Liakhovetski
  2011-01-21 16:27 ` Grant Likely
  0 siblings, 1 reply; 3+ messages in thread
From: Guennadi Liakhovetski @ 2011-01-21 15:56 UTC (permalink / raw)
  To: spi-devel-general; +Cc: linux-sh

NULL + <small offset> != NULL, but reading from that <small offset> address
is usually not a very good idea and often leads to problems, like kernel
Oopses in this case, easily reproducible by writing to an SD-card, used in
SPI mode.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
 drivers/spi/spi_sh_msiof.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi_sh_msiof.c b/drivers/spi/spi_sh_msiof.c
index 658bd05..6d30829 100644
--- a/drivers/spi/spi_sh_msiof.c
+++ b/drivers/spi/spi_sh_msiof.c
@@ -568,9 +568,11 @@ static int sh_msiof_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
 	bytes_done = 0;
 
 	while (bytes_done < t->len) {
+		void *rx_buf = t->rx_buf ? t->rx_buf + bytes_done : NULL;
+		const void *tx_buf = t->tx_buf ? t->tx_buf + bytes_done : NULL;
 		n = sh_msiof_spi_txrx_once(p, tx_fifo, rx_fifo,
-					   t->tx_buf + bytes_done,
-					   t->rx_buf + bytes_done,
+					   tx_buf,
+					   rx_buf,
 					   words, bits);
 		if (n < 0)
 			break;
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-22  3:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-21 15:56 [PATCH 3/3] SPI: spi_sh_msiof: fix wrong address calculation, which leads to an Oops Guennadi Liakhovetski
2011-01-21 16:27 ` Grant Likely
2011-01-22  3:26   ` Paul Mundt

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).