staging:iio: Prevent reading from buffer chrdev when device has no buffer.
authorJonathan Cameron <jic23@cam.ac.uk>
Wed, 21 Sep 2011 10:16:02 +0000 (11:16 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 27 Sep 2011 00:31:56 +0000 (17:31 -0700)
Silly bug introduced during the chrdev merge series.

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/iio/iio_core.h
drivers/staging/iio/industrialio-buffer.c
drivers/staging/iio/industrialio-core.c

index dde9e3e4278e3037af58a98b24add64d777a0149..36159e0dbfc38cc7ae762dca9b88a2a3da9f9d6e 100644 (file)
@@ -33,7 +33,7 @@ int __iio_add_chan_devattr(const char *postfix,
 #ifdef CONFIG_IIO_BUFFER
 struct poll_table_struct;
 
-void iio_chrdev_buffer_open(struct iio_dev *indio_dev);
+int iio_chrdev_buffer_open(struct iio_dev *indio_dev);
 void iio_chrdev_buffer_release(struct iio_dev *indio_dev);
 
 unsigned int iio_buffer_poll(struct file *filp,
@@ -47,8 +47,11 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
 
 #else
 
-static inline void iio_chrdev_buffer_open(struct iio_dev *indio_dev)
-{}
+static inline int iio_chrdev_buffer_open(struct iio_dev *indio_dev)
+{
+       return -EINVAL;
+}
+
 static inline void iio_chrdev_buffer_release(struct iio_dev *indio_dev)
 {}
 
index c3f57e7e80810ae1fc37bef5b241343c83a6089a..4ce101af9a9519538a0553247137198bdc946c68 100644 (file)
@@ -63,11 +63,14 @@ unsigned int iio_buffer_poll(struct file *filp,
        return 0;
 }
 
-void iio_chrdev_buffer_open(struct iio_dev *indio_dev)
+int iio_chrdev_buffer_open(struct iio_dev *indio_dev)
 {
        struct iio_buffer *rb = indio_dev->buffer;
-       if (rb && rb->access->mark_in_use)
+       if (!rb)
+               return -EINVAL;
+       if (rb->access->mark_in_use)
                rb->access->mark_in_use(rb);
+       return 0;
 }
 
 void iio_chrdev_buffer_release(struct iio_dev *indio_dev)
@@ -77,7 +80,6 @@ void iio_chrdev_buffer_release(struct iio_dev *indio_dev)
        clear_bit(IIO_BUSY_BIT_POS, &rb->flags);
        if (rb->access->unmark_in_use)
                rb->access->unmark_in_use(rb);
-
 }
 
 void iio_buffer_init(struct iio_buffer *buffer, struct iio_dev *dev_info)
index b11c7f303acdfc60aa2bd9371f5b2f806f3aa84d..647a4052a8cb7293aa1db548ee4cf2a9c9f7a917 100644 (file)
@@ -1065,8 +1065,8 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
        struct iio_dev *dev_info = container_of(inode->i_cdev,
                                                struct iio_dev, chrdev);
        filp->private_data = dev_info;
-       iio_chrdev_buffer_open(dev_info);
-       return 0;
+
+       return iio_chrdev_buffer_open(dev_info);
 }
 
 /**