Commit b46413367961c2e8bd827e067a231be982aaeee2
1 parent
c332c10c01
Exists in
master
and in
6 other branches
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>
Showing 1 changed file with 9 additions and 1 deletions Side-by-side Diff
drivers/staging/iio/industrialio-core.c
... | ... | @@ -242,6 +242,8 @@ |
242 | 242 | |
243 | 243 | static int iio_event_getfd(struct iio_dev *indio_dev) |
244 | 244 | { |
245 | + int fd; | |
246 | + | |
245 | 247 | if (indio_dev->event_interface == NULL) |
246 | 248 | return -ENODEV; |
247 | 249 | |
248 | 250 | |
... | ... | @@ -252,9 +254,15 @@ |
252 | 254 | return -EBUSY; |
253 | 255 | } |
254 | 256 | mutex_unlock(&indio_dev->event_interface->event_list_lock); |
255 | - return anon_inode_getfd("iio:event", | |
257 | + fd = anon_inode_getfd("iio:event", | |
256 | 258 | &iio_event_chrdev_fileops, |
257 | 259 | indio_dev->event_interface, O_RDONLY); |
260 | + if (fd < 0) { | |
261 | + mutex_lock(&indio_dev->event_interface->event_list_lock); | |
262 | + clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags); | |
263 | + mutex_unlock(&indio_dev->event_interface->event_list_lock); | |
264 | + } | |
265 | + return fd; | |
258 | 266 | } |
259 | 267 | |
260 | 268 | static int __init iio_init(void) |