staging: comedi: kcomedilib: increment reference while device in use
authorIan Abbott <abbotti@mev.co.uk>
Fri, 8 Nov 2013 15:03:38 +0000 (15:03 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Nov 2013 00:16:44 +0000 (16:16 -0800)
commit799a66ba36cb51330c53c024dffc6ddb68545c9c
tree5063dbb4e154d60745dc7a4a37712b62b21b0333
parentbe535c9a058b73600666d5431cfb442f39989a33
staging: comedi: kcomedilib: increment reference while device in use

Low-level comedi drivers that use the "kcomedilib" module (currently only
the "comedi_bond" driver) call `comedi_open()` to "open" another comedi
device (not as a file) and `comedi_close()` to "close" it.  (Note: these
are the functions exported by the "kcomedilib" module, not the
identically named, statically linked functions in the core "comedi"
module.)

In `comedi_open()`, call `comedi_dev_get_from_minor()` instead of
`comedi_dev_from_minor()` to get the pointer to the `struct
comedi_device` being "opened".  This increments its reference count to
prevent it being freed.  Call `comedi_dev_put()` if `comedi_open()`
returns `NULL`, and also call it from `comedi_close()`.  This decrements
the reference count.

Note that although we now protect against the `struct comedi_device`
being freed, we do not yet protect against it being "detached" while it
is being used.  This will be addressed by a later patch.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/kcomedilib/kcomedilib_main.c