staging: comedi: separate board and subdevice minor tables
authorIan Abbott <abbotti@mev.co.uk>
Thu, 4 Apr 2013 13:59:04 +0000 (14:59 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Apr 2013 21:33:19 +0000 (14:33 -0700)
commit5b7dba1bdda5b5864b61d28e32f860510e9a660f
tree22fd025cf46132d9baa5d083f3fd3ac9e7fed3c8
parent8907cf6c5da2bb6d877c8ba59f90aff1b72cd814
staging: comedi: separate board and subdevice minor tables

The comedi core reserves minor device numbers from 0 to
`COMEDI_NUM_BOARD_MINORS - 1` (0 to 0x30 - 1) for the main comedi
"board" devices and reserves minor device numbers from
`COMEDI_NUM_BOARD_MINORS` to `COMEDI_NUM_MINORS - 1` (0x30 to 0x100 - 1)
for comedi subdevices (or at least those that claim to support
asynchronous comedi commands).  There is an array
`comedi_file_info_table[COMEDI_NUM_MINORS]` used to hold pointers to
information for each board minor device number and subdevice minor
device number that has been allocated (with NULL pointers for those not
allocated), along with a protective lock `comedi_file_info_table_lock`.

Since the ranges of board minor device numbers and subdevice minor
device numbers do not overlap, we can use separate tables and separate
locks for the different types of minor device numbers.  This will allow
us to use different pointer types for the elements of each table in the
future without just using a generic `void *`.  (At the moment, the table
elements point to a `struct comedi_file_info` allocated dynamically for
each allocated board minor device or subdevice minor device, but I plan
to get rid of that data structure.)

Replace `comedi_file_info_table[COMEDI_NUM_MINORS]` with two new arrays
of the same type, `comedi_board_minor_table[COMEDI_NUM_BOARD_MINORS]`
for board minors, and
`comedi_subdevice_minor_table[COMEDI_NUM_SUBDEVICE_MINORS]` for
subdevice minors (where `COMEDI_NUM_SUBDEVICE_MINORS` is
`COMEDI_NUM_MINORS - COMEDI_NUM_BOARD_MINORS`).
`comedi_subdevice_minor_table[]` is indexed by the subdevice minor
number minus `COMEDI_NUM_BOARD_MINORS` since `COMEDI_NUM_BOARD_MINORS`
is the first valid subdevice minor number.

Replace `comedi_file_info_table_lock` with
`comedi_board_minor_table_lock` for board minors and
`comedi_subdevice_minor_table_lock` for subdevice minors.

Refactor `comedi_clear_minor()` to call one of two new functions
`comedi_clear_board_minor()` and `comedi_clear_subdevice_minor()`
depending on the minor device number passed as a parameter.  Similarly,
refactor `comedi_file_info_from_minor()` to call one of two new
functions `comedi_file_info_from_board_minor()` and
`comedi_file_info_from_subdevice_minor()` depending on the minor device
number parameter.

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