linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: spi_mpc8xxx.c: fix potential memory corruption.
@ 2010-05-12 15:50 Joakim Tjernlund
       [not found] ` <1273679450-4185-1-git-send-email-Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Joakim Tjernlund @ 2010-05-12 15:50 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	avorontsov-hkdhdckH98+B+jHODAdFcQ
  Cc: Joakim Tjernlund

tx_dma/rx_dma are already set to a dummy buffer when no
tx/rx buffer and t->tx_dma/t->rx_dma does not contain a dma
address, but NULL.
This may lead to corruption of kernel memory. Fix this by
leaving tx_dma/rx_dma alone.

Do not INIT_TX_RX while controller is enabled, this is bad according
to the MPC8321 manual.

Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org>
---
 drivers/spi/spi_mpc8xxx.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_mpc8xxx.c
index e1d8045..c312d0e 100644
--- a/drivers/spi/spi_mpc8xxx.c
+++ b/drivers/spi/spi_mpc8xxx.c
@@ -240,7 +240,6 @@ static void mpc8xxx_spi_change_mode(struct spi_device *spi)
 
 	/* Turn off SPI unit prior changing mode */
 	mpc8xxx_spi_write_reg(mode, cs->hw_mode & ~SPMODE_ENABLE);
-	mpc8xxx_spi_write_reg(mode, cs->hw_mode);
 
 	/* When in CPM mode, we need to reinit tx and rx. */
 	if (mspi->flags & SPI_CPM_MODE) {
@@ -257,7 +256,7 @@ static void mpc8xxx_spi_change_mode(struct spi_device *spi)
 			}
 		}
 	}
-
+	mpc8xxx_spi_write_reg(mode, cs->hw_mode);
 	local_irq_restore(flags);
 }
 
@@ -437,7 +436,7 @@ static int mpc8xxx_spi_cpm_bufs(struct mpc8xxx_spi *mspi,
 			dev_err(dev, "unable to map tx dma\n");
 			return -ENOMEM;
 		}
-	} else {
+	} else if (t->tx_buf) {
 		mspi->tx_dma = t->tx_dma;
 	}
 
@@ -448,7 +447,7 @@ static int mpc8xxx_spi_cpm_bufs(struct mpc8xxx_spi *mspi,
 			dev_err(dev, "unable to map rx dma\n");
 			goto err_rx_dma;
 		}
-	} else {
+	} else if (t->rx_buf) {
 		mspi->rx_dma = t->rx_dma;
 	}
 
-- 
1.6.4.4


------------------------------------------------------------------------------

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

end of thread, other threads:[~2010-05-14 12:30 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-12 15:50 [PATCH] spi: spi_mpc8xxx.c: fix potential memory corruption Joakim Tjernlund
     [not found] ` <1273679450-4185-1-git-send-email-Joakim.Tjernlund-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org>
2010-05-12 16:22   ` Anton Vorontsov
     [not found]     ` <20100512162231.GA449-wnGakbxT3iijyJ0x5qLZdcN33GVbZNy3@public.gmane.org>
2010-05-12 16:28       ` Joakim Tjernlund
     [not found]         ` <OFB1D6A895.8E381278-ONC1257721.005A1E7B-C1257721.005A885D-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org>
2010-05-12 16:43           ` Anton Vorontsov
     [not found]             ` <20100512164321.GA5522-wnGakbxT3iijyJ0x5qLZdcN33GVbZNy3@public.gmane.org>
2010-05-13  7:53               ` Joakim Tjernlund
2010-05-13  9:36               ` Joakim Tjernlund
     [not found]                 ` <OFD4A1BD4A.1E890808-ONC1257722.00336F58-C1257722.0034C1F5-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org>
2010-05-13  9:55                   ` Anton Vorontsov
     [not found]                     ` <20100513095545.GA11506-wnGakbxT3iijyJ0x5qLZdcN33GVbZNy3@public.gmane.org>
2010-05-13 12:33                       ` Joakim Tjernlund
2010-05-13 13:50                       ` Joakim Tjernlund
2010-05-13 15:55                       ` Joakim Tjernlund
     [not found]                         ` <OF224832EB.3B3694C0-ONC1257722.00574009-C1257722.00577791-SNLAxHN9vbcOP4wsBPIw7w@public.gmane.org>
2010-05-13 16:18                           ` Anton Vorontsov
     [not found]                             ` <20100513161851.GA23404-wnGakbxT3iijyJ0x5qLZdcN33GVbZNy3@public.gmane.org>
2010-05-13 19:47                               ` Joakim Tjernlund
2010-05-13 21:13               ` Grant Likely
     [not found]                 ` <AANLkTillcDbtpIcq7ZYID9xBpHuGfcBQNNSZJFuyqHYM-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-05-14 12:30                   ` Joakim Tjernlund

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