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>
Showing
Please register or sign in to comment