From: Ian Abbott Date: Wed, 2 Jan 2008 17:41:47 +0000 (+0000) Subject: For COMEDI_DEVCONFIG ioctl, if argument is NULL, refuse to unconfigure the X-Git-Tag: v0_7_76~13 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1016290392d3fd24fa9b0dba0f0fd790e83e0004;p=comedi.git For COMEDI_DEVCONFIG ioctl, if argument is NULL, refuse to unconfigure the device if any subdevices are busy or have mmap'ed buffers. The errno is EBUSY in this case. --- diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 5f593d9f..181cd032 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -83,6 +83,8 @@ static int do_cancel(comedi_device * dev, comedi_subdevice * s); static int comedi_fasync(int fd, struct file *file, int on); +static int is_device_busy(comedi_device * dev); + #ifdef HAVE_UNLOCKED_IOCTL static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) @@ -187,6 +189,8 @@ static int do_devconfig_ioctl(comedi_device * dev, comedi_devconfig * arg) return -EPERM; if (arg == NULL) { + if (is_device_busy(dev)) + return -EBUSY; return comedi_device_detach(dev); } @@ -2033,3 +2037,22 @@ unsigned comedi_get_subdevice_runflags(comedi_subdevice * s) comedi_spin_unlock_irqrestore(&s->spin_lock, flags); return runflags; } + +static int is_device_busy(comedi_device * dev) +{ + comedi_subdevice *s; + int i; + + if (!dev->attached) + return 0; + + for (i = 0; i < dev->n_subdevices; i++) { + s = dev->subdevices + i; + if (s->busy) + return 1; + if (s->async && s->async->mmap_count) + return 1; + } + + return 0; +}