Commit 30eb82f0 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio: Prevent reading from buffer chrdev when device has no buffer.

Silly bug introduced during the chrdev merge series.
Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ad31d250
...@@ -33,7 +33,7 @@ int __iio_add_chan_devattr(const char *postfix, ...@@ -33,7 +33,7 @@ int __iio_add_chan_devattr(const char *postfix,
#ifdef CONFIG_IIO_BUFFER #ifdef CONFIG_IIO_BUFFER
struct poll_table_struct; 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); void iio_chrdev_buffer_release(struct iio_dev *indio_dev);
unsigned int iio_buffer_poll(struct file *filp, 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, ...@@ -47,8 +47,11 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
#else #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) static inline void iio_chrdev_buffer_release(struct iio_dev *indio_dev)
{} {}
......
...@@ -63,11 +63,14 @@ unsigned int iio_buffer_poll(struct file *filp, ...@@ -63,11 +63,14 @@ unsigned int iio_buffer_poll(struct file *filp,
return 0; 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; 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); rb->access->mark_in_use(rb);
return 0;
} }
void iio_chrdev_buffer_release(struct iio_dev *indio_dev) void iio_chrdev_buffer_release(struct iio_dev *indio_dev)
...@@ -77,7 +80,6 @@ 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); clear_bit(IIO_BUSY_BIT_POS, &rb->flags);
if (rb->access->unmark_in_use) if (rb->access->unmark_in_use)
rb->access->unmark_in_use(rb); rb->access->unmark_in_use(rb);
} }
void iio_buffer_init(struct iio_buffer *buffer, struct iio_dev *dev_info) void iio_buffer_init(struct iio_buffer *buffer, struct iio_dev *dev_info)
......
...@@ -1065,8 +1065,8 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp) ...@@ -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 *dev_info = container_of(inode->i_cdev,
struct iio_dev, chrdev); struct iio_dev, chrdev);
filp->private_data = dev_info; filp->private_data = dev_info;
iio_chrdev_buffer_open(dev_info);
return 0; return iio_chrdev_buffer_open(dev_info);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment