public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] spi: imx: fix issue when tx_buf or rx_buf is NULL
@ 2017-05-18 10:01 jiada_wang
  2017-05-18 10:08 ` Leonard Crestez
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: jiada_wang @ 2017-05-18 10:01 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel, leonard.crestez, Jiada Wang

From: Jiada Wang <jiada_wang@mentor.com>

In case either transfer->tx_buf or transfer->rx_buf is NULL,
manipulation of buffer in spi_imx_u32_swap_u[8|16]() will cause
NULL pointer dereference crash.

Add buffer check at very beginning of spi_imx_u32_swap_u[8|16](),
to avoid such crash.

Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
Reported-by: Leonard Crestez <leonard.crestez@nxp.com>
---
 drivers/spi/spi-imx.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 782045f..19b30cf 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -288,6 +288,9 @@ static void spi_imx_u32_swap_u8(struct spi_transfer *transfer, u32 *buf)
 {
 	int i;
 
+	if (!buf)
+		return;
+
 	for (i = 0; i < transfer->len / 4; i++)
 		*(buf + i) = cpu_to_be32(*(buf + i));
 }
@@ -296,6 +299,9 @@ static void spi_imx_u32_swap_u16(struct spi_transfer *transfer, u32 *buf)
 {
 	int i;
 
+	if (!buf)
+		return;
+
 	for (i = 0; i < transfer->len / 4; i++) {
 		u16 *temp = (u16 *)buf;
 
-- 
2.7.4

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

end of thread, other threads:[~2017-05-19 17:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-18 10:01 [PATCH 1/1] spi: imx: fix issue when tx_buf or rx_buf is NULL jiada_wang
2017-05-18 10:08 ` Leonard Crestez
2017-05-19 12:45 ` Chris Ruehl
2017-05-19 13:15   ` Andy Shevchenko
2017-05-19 16:56     ` Mark Brown
2017-05-19 17:04 ` Applied "spi: imx: fix issue when tx_buf or rx_buf is NULL" to the spi tree Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox