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 17d2e20663cbd42801d4a1f197432000edafa5b0..d605fd95cc50d206662a5e15737e2c65399db261 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 e0afe2cee2d6fe4eb2fee623781ab0bb01df4d29..b21ed526a9607054efd79bacd361ff90f8542ede 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 f0d709e0dafc3513e82e09cdad5a292adac4bd07..775263c1471ee14bb271f8abb2d2e6592e53364c 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 fbf05687347f480085b94c533df34447d82c7572..f4170f89948763d23a9d4887b3d5bfbda88430a2 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;