public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: spidev: fix possible NULL dereference
@ 2015-09-10 11:18 Sudip Mukherjee
  2015-09-11 12:11 ` Jarkko Nikula
  0 siblings, 1 reply; 5+ messages in thread
From: Sudip Mukherjee @ 2015-09-10 11:18 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, linux-spi, Sudip Mukherjee

During the last close we are freeing spidev if spidev->spi is NULL, but
just before checking if spidev->spi is NULL we are dereferencing it.
Lets add a check there to avoid the NULL dereference.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
 drivers/spi/spidev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index fba92a5..ef008e5 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -651,7 +651,8 @@ static int spidev_release(struct inode *inode, struct file *filp)
 		kfree(spidev->rx_buffer);
 		spidev->rx_buffer = NULL;
 
-		spidev->speed_hz = spidev->spi->max_speed_hz;
+		if (spidev->spi)
+			spidev->speed_hz = spidev->spi->max_speed_hz;
 
 		/* ... after we unbound from the underlying device? */
 		spin_lock_irq(&spidev->spi_lock);
-- 
1.9.1


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

end of thread, other threads:[~2015-09-11 14:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-10 11:18 [PATCH] spi: spidev: fix possible NULL dereference Sudip Mukherjee
2015-09-11 12:11 ` Jarkko Nikula
2015-09-11 12:25   ` Mark Brown
2015-09-11 12:49     ` Sudip Mukherjee
2015-09-11 14:21       ` Mark Brown

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