staging: comedi: remove manually unconfigured dynamic devices
authorIan Abbott <abbotti@mev.co.uk>
Thu, 4 Apr 2013 13:58:54 +0000 (14:58 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Apr 2013 21:33:18 +0000 (14:33 -0700)
commit8ab4ed6ef1c218cac4270cd20a714b83da6907a3
tree874ecaa3480f2af30061ebb82355341fe271296d
parent1f423cfcf56052b462c4bceefb950921c9a0f495
staging: comedi: remove manually unconfigured dynamic devices

If a dynamically allocated (non-legacy, and automatically configured)
comedi device has been successfully unconfigured by use of the
`COMEDI_DEVCONFIG` ioctl, then remove the device afterwards.
(Dynamically identified comedi devices are identified by their minor
device number being `comedi_num_legacy_minors` or greater.)  This is
done in `comedi_unlocked_ioctl()` on return from `do_devconfig_ioctl()`.

Note that there is an unlikely race condition with some other thread
that has just called `comedi_file_info_from_minor()` or
`comedi_dev_from_minor()` and is about to use the device, but that race
condition also exists for automatically removed devices and will be
dealt with properly once reference counting of comedi devices has been
implemented.  We do avoid a race condition between automatic removal and
removal by the `COMEDI_DEVCONFIG` ioctl though.

Also add an extra precaution in `do_devconfig_ioctl()` to avoid
configuring a dynamically allocated device since there is a tight
window avoiding the race condition where this could happen and the
device is about to be removed anyway.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/comedi_fops.c