Skip to contentSkip to conversation

iio: buffer: check if a buffer has been set up when poll is called

PATCH Applied Stefan Windfeldt-Prytz 2 participants 2 messages Feb 15, 2018 – Feb 17, 2018 IIO

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 iio: buffer: check if a buffer has been set up when poll is called

If no iio buffer has been set up and poll is called return 0. Without this check there will be a null pointer dereference when calling poll on a iio driver without an iio buffer.

---
Changes in v3:
- Added consequences of missing the check

drivers/iio/industrialio-buffer.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-buffer.c +1 -1
index 79abf70..cd5bfe3 100644
@@ -175,7 +175,7 @@ __poll_t iio_buffer_poll(struct file *filp,
 	struct iio_dev *indio_dev = filp->private_data;
 	struct iio_buffer *rb = indio_dev->buffer;
 
-	if (!indio_dev->info)
+	if (!indio_dev->info || rb == NULL)
 		return 0;
 
 	poll_wait(filp, &rb->pollq, wait);
Signature · 1 line
2.1.4
maintainer Applied
#1 lore raw
Quoted 6 lines · On Thu, 15 Feb 2018 15:02:53 +0100 Stefan Windfeldt-Prytz…

If no iio buffer has been set up and poll is called return 0. Without this check there will be a null pointer dereference when calling poll on a iio driver without an iio buffer.

Applied to the fixes-togreg-post-rc1 branch of iio.git.

Thanks,

Jonathan

Quoted 20 lines

---
Changes in v3:
- Added consequences of missing the check

drivers/iio/industrialio-buffer.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-buffer.c +1 -1
index 79abf70..cd5bfe3 100644
@@ -175,7 +175,7 @@ __poll_t iio_buffer_poll(struct file *filp,
 	struct iio_dev *indio_dev = filp->private_data;
 	struct iio_buffer *rb = indio_dev->buffer;
 
-	if (!indio_dev->info)
+	if (!indio_dev->info || rb == NULL)
 		return 0;
 
 	poll_wait(filp, &rb->pollq, wait);