linux-spi.vger.kernel.org archive mirror
 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-nmGgyN9QBj3QT0dZR+AlfA
  2017-05-18 10:08 ` Leonard Crestez
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: jiada_wang-nmGgyN9QBj3QT0dZR+AlfA @ 2017-05-18 10:01 UTC (permalink / raw)
  To: broonie-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, leonard.crestez-3arQi8VN3Tc,
	Jiada Wang

From: Jiada Wang <jiada_wang-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>

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-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
Reported-by: Leonard Crestez <leonard.crestez-3arQi8VN3Tc@public.gmane.org>
---
 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


--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2017-05-19 17:04 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-nmGgyN9QBj3QT0dZR+AlfA
2017-05-18 10:08 ` Leonard Crestez
     [not found] ` <1495101672-3384-1-git-send-email-jiada_wang-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2017-05-19 12:45   ` Chris Ruehl
     [not found]     ` <94de6e6d-a2fa-6589-151b-660bbcb42773-CR359r9tUDPXPF5Rlphj1Q@public.gmane.org>
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;
as well as URLs for NNTP newsgroup(s).