staging: comedi: amplc_dio200: remove private data
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Fri, 1 Aug 2014 20:06:59 +0000 (13:06 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 16 Aug 2014 19:23:09 +0000 (12:23 -0700)
The private data in this driver only has one member, 'intr_sd', which is
the index to the interrupt subdevice.

This member is initialized during the attach of the driver when the sd_intr
subdevice is detected in the boadinfo 'layout'. The member is then used in
the interrupt handler to get the pointer to the subdevice.

This member is not necessary. The comedi_device 'read_subdev' is also
initialized during the attach. This can be used in the interrupt handler
to get the subdevice pointer.

Refactor the code to not require the private data and remove the struct
and its 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/amplc_dio200.c
drivers/staging/comedi/drivers/amplc_dio200.h
drivers/staging/comedi/drivers/amplc_dio200_common.c
drivers/staging/comedi/drivers/amplc_dio200_pci.c

index 17d2e20..d605fd9 100644 (file)
@@ -265,16 +265,11 @@ static const struct dio200_board dio200_isa_boards[] = {
 static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 {
        const struct dio200_board *thisboard = comedi_board(dev);
-       struct dio200_private *devpriv;
        unsigned int irq;
        int ret;
 
        irq = it->options[1];
 
-       devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
-       if (!devpriv)
-               return -ENOMEM;
-
        ret = comedi_request_region(dev, it->options[0], thisboard->mainsize);
        if (ret)
                return ret;
index e0afe2c..b21ed52 100644 (file)
@@ -59,13 +59,6 @@ struct dio200_board {
        unsigned int mainsize;
 };
 
-/*
- * Comedi device private data.
- */
-struct dio200_private {
-       int intr_sd;
-};
-
 int amplc_dio200_common_attach(struct comedi_device *dev, unsigned int irq,
                               unsigned long req_irq_flags);
 
index f0d709e..775263c 100644 (file)
@@ -574,19 +574,13 @@ dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s,
 static irqreturn_t dio200_interrupt(int irq, void *d)
 {
        struct comedi_device *dev = d;
-       struct dio200_private *devpriv = dev->private;
-       struct comedi_subdevice *s;
+       struct comedi_subdevice *s = dev->read_subdev;
        int handled;
 
        if (!dev->attached)
                return IRQ_NONE;
 
-       if (devpriv->intr_sd >= 0) {
-               s = &dev->subdevices[devpriv->intr_sd];
-               handled = dio200_handle_read_intr(dev, s);
-       } else {
-               handled = 0;
-       }
+       handled = dio200_handle_read_intr(dev, s);
 
        return IRQ_RETVAL(handled);
 }
@@ -1122,15 +1116,11 @@ int amplc_dio200_common_attach(struct comedi_device *dev, unsigned int irq,
                               unsigned long req_irq_flags)
 {
        const struct dio200_board *thisboard = comedi_board(dev);
-       struct dio200_private *devpriv = dev->private;
        const struct dio200_layout *layout = dio200_board_layout(thisboard);
        struct comedi_subdevice *s;
-       int sdx;
        unsigned int n;
        int ret;
 
-       devpriv->intr_sd = -1;
-
        ret = comedi_alloc_subdevices(dev, layout->n_subdevs);
        if (ret)
                return ret;
@@ -1154,14 +1144,14 @@ int amplc_dio200_common_attach(struct comedi_device *dev, unsigned int irq,
                        break;
                case sd_intr:
                        /* 'INTERRUPT' subdevice */
-                       if (irq) {
+                       if (irq && !dev->read_subdev) {
                                ret = dio200_subdev_intr_init(dev, s,
                                                              DIO200_INT_SCE,
                                                              layout->sdinfo[n]
                                                             );
                                if (ret < 0)
                                        return ret;
-                               devpriv->intr_sd = n;
+                               dev->read_subdev = s;
                        } else {
                                s->type = COMEDI_SUBD_UNUSED;
                        }
@@ -1176,10 +1166,8 @@ int amplc_dio200_common_attach(struct comedi_device *dev, unsigned int irq,
                        break;
                }
        }
-       sdx = devpriv->intr_sd;
-       if (sdx >= 0 && sdx < dev->n_subdevices)
-               dev->read_subdev = &dev->subdevices[sdx];
-       if (irq) {
+
+       if (irq && dev->read_subdev) {
                if (request_irq(irq, dio200_interrupt, req_irq_flags,
                                dev->board_name, dev) >= 0) {
                        dev->irq = irq;
index fbf0568..f4170f8 100644 (file)
@@ -359,7 +359,6 @@ static int dio200_pci_auto_attach(struct comedi_device *dev,
 {
        struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
        const struct dio200_board *thisboard = NULL;
-       struct dio200_private *devpriv;
        unsigned int bar;
        int ret;
 
@@ -373,10 +372,6 @@ static int dio200_pci_auto_attach(struct comedi_device *dev,
        dev_info(dev->class_dev, "%s: attach pci %s (%s)\n",
                 dev->driver->driver_name, pci_name(pci_dev), dev->board_name);
 
-       devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
-       if (!devpriv)
-               return -ENOMEM;
-
        ret = comedi_pci_enable(dev);
        if (ret)
                return ret;