浏览代码

iio: fix a leak due to improper use of anon_inode_getfd()

it can fail and in that case ->release() will *not* be called...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Al Viro 13 年之前
父节点
当前提交
b464133679
共有 1 个文件被更改,包括 9 次插入1 次删除
  1. 9 1
      drivers/staging/iio/industrialio-core.c

+ 9 - 1
drivers/staging/iio/industrialio-core.c

@@ -242,6 +242,8 @@ static const struct file_operations iio_event_chrdev_fileops = {
 
 
 static int iio_event_getfd(struct iio_dev *indio_dev)
 static int iio_event_getfd(struct iio_dev *indio_dev)
 {
 {
+	int fd;
+
 	if (indio_dev->event_interface == NULL)
 	if (indio_dev->event_interface == NULL)
 		return -ENODEV;
 		return -ENODEV;
 
 
@@ -252,9 +254,15 @@ static int iio_event_getfd(struct iio_dev *indio_dev)
 		return -EBUSY;
 		return -EBUSY;
 	}
 	}
 	mutex_unlock(&indio_dev->event_interface->event_list_lock);
 	mutex_unlock(&indio_dev->event_interface->event_list_lock);
-	return anon_inode_getfd("iio:event",
+	fd = anon_inode_getfd("iio:event",
 				&iio_event_chrdev_fileops,
 				&iio_event_chrdev_fileops,
 				indio_dev->event_interface, O_RDONLY);
 				indio_dev->event_interface, O_RDONLY);
+	if (fd < 0) {
+		mutex_lock(&indio_dev->event_interface->event_list_lock);
+		clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
+		mutex_unlock(&indio_dev->event_interface->event_list_lock);
+	}
+	return fd;
 }
 }
 
 
 static int __init iio_init(void)
 static int __init iio_init(void)