diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c index 3383a7ce27ff..ea96bc4b818e 100644 --- a/drivers/comedi/comedi_fops.c +++ b/drivers/comedi/comedi_fops.c @@ -785,21 +785,31 @@ void comedi_device_cancel_all(struct comedi_device *dev) static int is_device_busy(struct comedi_device *dev) { struct comedi_subdevice *s; - int i; + int i, is_busy = 0; lockdep_assert_held(&dev->mutex); if (!dev->attached) return 0; + /* prevent new polls */ + down_write(&dev->attach_lock); + for (i = 0; i < dev->n_subdevices; i++) { s = &dev->subdevices[i]; - if (s->busy) - return 1; - if (s->async && comedi_buf_is_mmapped(s)) - return 1; + if (s->busy) { + is_busy = 1; + break; + } + if (!s->async) + continue; + if (comedi_buf_is_mmapped(s) || + waitqueue_active(&s->async->wait_head)) { + is_busy = 1; + break; + } } - - return 0; + up_write(&dev->attach_lock); + return is_busy; } /*