staging: comedi: ni_65xx: remove the need for the subdevice private data
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 14 Jul 2014 19:06:56 +0000 (12:06 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 16 Jul 2014 20:22:49 +0000 (13:22 -0700)
There is only one member in the subdevice private data, an unsigned value
that is the 'base_port' that the subdevice uses to access the port registers.

Just cast the appropriate value into s->private instead of allocating the
private data for each subdevice. The casts are a bit of a nusance but it
removes the unnecessary allocations.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_65xx.c

index 4b3f504ee495ca72d26c09c3186d65349f1c273e..7e562f1cffc80cbf18d264bb6b703384ce3b9a8c 100644 (file)
@@ -274,25 +274,16 @@ struct ni_65xx_private {
        unsigned short output_bits[NI_65XX_MAX_NUM_PORTS];
 };
 
-struct ni_65xx_subdevice_private {
-       unsigned base_port;
-};
-
-static inline struct ni_65xx_subdevice_private *sprivate(struct comedi_subdevice
-                                                        *subdev)
-{
-       return subdev->private;
-}
-
 static int ni_65xx_dio_insn_config(struct comedi_device *dev,
                                   struct comedi_subdevice *s,
                                   struct comedi_insn *insn,
                                   unsigned int *data)
 {
        struct ni_65xx_private *devpriv = dev->private;
+       unsigned long base_port = (unsigned long)s->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int chan_mask = 1 << (chan % ni_65xx_channels_per_port);
-       unsigned port = sprivate(s)->base_port + ni_65xx_port_by_channel(chan);
+       unsigned port = base_port + ni_65xx_port_by_channel(chan);
        unsigned int interval;
        unsigned int val;
 
@@ -357,6 +348,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
                                 struct comedi_insn *insn, unsigned int *data)
 {
        const struct ni_65xx_board *board = comedi_board(dev);
+       unsigned long base_port = (unsigned long)s->private;
        struct ni_65xx_private *devpriv = dev->private;
        int base_bitfield_channel;
        unsigned read_bits = 0;
@@ -366,7 +358,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
        base_bitfield_channel = CR_CHAN(insn->chanspec);
        for (port_offset = ni_65xx_port_by_channel(base_bitfield_channel);
             port_offset <= last_port_offset; port_offset++) {
-               unsigned port = sprivate(s)->base_port + port_offset;
+               unsigned port = base_port + port_offset;
                int base_port_channel = port_offset * ni_65xx_channels_per_port;
                unsigned port_mask, port_data, port_read_bits;
                int bitshift = base_port_channel - base_bitfield_channel;
@@ -563,7 +555,6 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        const struct ni_65xx_board *board = NULL;
        struct ni_65xx_private *devpriv;
-       struct ni_65xx_subdevice_private *spriv;
        struct comedi_subdevice *s;
        unsigned i;
        int ret;
@@ -609,10 +600,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
                s->maxdata = 1;
                s->insn_config = ni_65xx_dio_insn_config;
                s->insn_bits = ni_65xx_dio_insn_bits;
-               spriv = comedi_alloc_spriv(s, sizeof(*spriv));
-               if (!spriv)
-                       return -ENOMEM;
-               spriv->base_port = 0;
+
+               /* the input ports always start at port 0 */
+               s->private = (void *)0;
        } else {
                s->type = COMEDI_SUBD_UNUSED;
        }
@@ -626,10 +616,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
                s->range_table = &range_digital;
                s->maxdata = 1;
                s->insn_bits = ni_65xx_dio_insn_bits;
-               spriv = comedi_alloc_spriv(s, sizeof(*spriv));
-               if (!spriv)
-                       return -ENOMEM;
-               spriv->base_port = board->num_di_ports;
+
+               /* the output ports always start after the input ports */
+               s->private = (void *)(unsigned long)board->num_di_ports;
        } else {
                s->type = COMEDI_SUBD_UNUSED;
        }
@@ -644,10 +633,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
                s->maxdata = 1;
                s->insn_config = ni_65xx_dio_insn_config;
                s->insn_bits = ni_65xx_dio_insn_bits;
-               spriv = comedi_alloc_spriv(s, sizeof(*spriv));
-               if (!spriv)
-                       return -ENOMEM;
-               spriv->base_port = 0;
+
+               /* the input/output ports always start at port 0 */
+               s->private = (void *)0;
+
                /* configure all ports for input */
                for (i = 0; i < board->num_dio_ports; ++i) {
                        writeb(NI_65XX_IO_SEL_INPUT,
This page took 0.027496 seconds and 5 git commands to generate.