]> asedeno.scripts.mit.edu Git - linux.git/commit
staging: comedi: jr3_pci: re-work struct jr3_pci_subdev_private range
authorIan Abbott <abbotti@mev.co.uk>
Fri, 17 Feb 2017 11:09:16 +0000 (11:09 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 6 Mar 2017 08:16:58 +0000 (09:16 +0100)
commit4af8c8195188b5d9ceaea4925a0e7f48a3e3c6c0
tree23bfe8e1116e1088f834dc2ab47b7b1e7dc7d69d
parentde98befe56960dbeea0501d3cefa42c89825e39f
staging: comedi: jr3_pci: re-work struct jr3_pci_subdev_private range

The `range` member of `struct jr3_pci_subdev_private` is an array of a
tag-less `struct` type whose layout is similar to `struct
comedi_lrange`.  Both `struct` types end with a member also called
`range`.  In the case of tag-less `struct` type, it is a single `struct
comedi_krange`.  In the case of `struct comedi_lrange`, it is a flexible
array of `struct comedi_krange`.

Elements of the `range` array member in `struct jr3_pci_subdev_private`
are pointed to by elements of the `range_table_list` array member, which
are of type `const struct comedi_lrange *`.  This requires some dodgy
type casting.

To avoid the dodgy type casting, change the element type of the `range`
member of `struct jr3_pci_subdev_private` to be a new type `union
jr3_pci_single_range`.  This contains a member `l` of type `struct
comedi_lrange`, and an array member `_reserved` that is large enough to
encompass the `struct comedi_lrange` plus a single `struct
comedi_krange`.  It is the same size as the previous type.  Accesses to
`spriv->range[i].length` and `spriv->range[i].range` are replaced with
`spriv->range[i].l.length` and `spriv->range[i].l.range[0]` respectively
(where `spriv` is a `struct jr3_pci_subdev_private *`, and `i` is an
array index).  Type-casted pointers to `spriv->range[i]` are replaced
with pointers to `spriv->range[i].l`, which do not require the type
casts.  Since we defined a new type, we can define local variables of
the corresponding pointer type to shorten some lines of code.  This is
made use of in `jr3_pci_alloc_spriv()`.

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