Commit 24fb134d authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: refactor comedi_free_board_minor()

Split out the part of `comedi_free_board_minor()` that clears the
`comedi_file_info_table[]` element into new function
`comedi_clear_minor()`.  Split out the remainder of the original
function into new function `comedi_free_board_file_info()`.

Also re-use a call to `comedi_clear_minor()` in
`comedi_free_subdevice_minor()` instead of doing the same thing inline.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Reviewed-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a649a675
...@@ -2315,16 +2315,19 @@ int comedi_alloc_board_minor(struct device *hardware_device) ...@@ -2315,16 +2315,19 @@ int comedi_alloc_board_minor(struct device *hardware_device)
return i; return i;
} }
void comedi_free_board_minor(unsigned minor) static struct comedi_file_info *comedi_clear_minor(unsigned minor)
{ {
struct comedi_file_info *info; struct comedi_file_info *info;
BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
spin_lock(&comedi_file_info_table_lock); spin_lock(&comedi_file_info_table_lock);
info = comedi_file_info_table[minor]; info = comedi_file_info_table[minor];
comedi_file_info_table[minor] = NULL; comedi_file_info_table[minor] = NULL;
spin_unlock(&comedi_file_info_table_lock); spin_unlock(&comedi_file_info_table_lock);
return info;
}
static void comedi_free_board_file_info(struct comedi_file_info *info)
{
if (info) { if (info) {
struct comedi_device *dev = info->device; struct comedi_device *dev = info->device;
if (dev) { if (dev) {
...@@ -2339,6 +2342,12 @@ void comedi_free_board_minor(unsigned minor) ...@@ -2339,6 +2342,12 @@ void comedi_free_board_minor(unsigned minor)
} }
} }
void comedi_free_board_minor(unsigned minor)
{
BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
comedi_free_board_file_info(comedi_clear_minor(minor));
}
int comedi_find_board_minor(struct device *hardware_device) int comedi_find_board_minor(struct device *hardware_device)
{ {
int minor; int minor;
...@@ -2407,11 +2416,7 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s) ...@@ -2407,11 +2416,7 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s)
BUG_ON(s->minor >= COMEDI_NUM_MINORS); BUG_ON(s->minor >= COMEDI_NUM_MINORS);
BUG_ON(s->minor < COMEDI_FIRST_SUBDEVICE_MINOR); BUG_ON(s->minor < COMEDI_FIRST_SUBDEVICE_MINOR);
spin_lock(&comedi_file_info_table_lock); info = comedi_clear_minor(s->minor);
info = comedi_file_info_table[s->minor];
comedi_file_info_table[s->minor] = NULL;
spin_unlock(&comedi_file_info_table_lock);
if (s->class_dev) { if (s->class_dev) {
device_destroy(comedi_class, MKDEV(COMEDI_MAJOR, s->minor)); device_destroy(comedi_class, MKDEV(COMEDI_MAJOR, s->minor));
s->class_dev = NULL; s->class_dev = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment