staging: comedi: drivers: let core handle freeing s->private
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 11 Jun 2013 18:32:29 +0000 (11:32 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 17 Jun 2013 21:31:10 +0000 (14:31 -0700)
Introduce a new subdevice runflags, SRF_FREE_SPRIV, and a new helper
function, comedi_set_spriv(), that the drivers can use to set the
comedi_subdevice private data pointer. The helper function will also
set SRF_FREE_SPRIV to allow the comedi core to automatically free the
subdevice private data during the cleanup_device() stage of the detach.

Currently s->private is only allocated by the 8255, addi_watchdog,
amplc_dio200_common, and ni_65xx drivers. All users of those drivers
can then have the comedi_spriv_free() calls removed and in many cases
the (*detach) can then simply be the appropriate comedi core provided
function.

The ni_65xx driver uses a helper function, ni_65xx_alloc_subdevice_private(),
to allocate the private data. Refactor the function to return an errno
or call comedi_set_spriv() instead of returning a pointer to the private
data and requiring the caller to handle it.

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>
36 files changed:
drivers/staging/comedi/comedi_fops.c
drivers/staging/comedi/comedidev.h
drivers/staging/comedi/drivers.c
drivers/staging/comedi/drivers/8255.c
drivers/staging/comedi/drivers/8255_pci.c
drivers/staging/comedi/drivers/addi_apci_1516.c
drivers/staging/comedi/drivers/addi_apci_2032.c
drivers/staging/comedi/drivers/addi_apci_2200.c
drivers/staging/comedi/drivers/addi_watchdog.c
drivers/staging/comedi/drivers/adv_pci_dio.c
drivers/staging/comedi/drivers/aio_aio12_8.c
drivers/staging/comedi/drivers/amplc_dio200_common.c
drivers/staging/comedi/drivers/amplc_pc236.c
drivers/staging/comedi/drivers/amplc_pci230.c
drivers/staging/comedi/drivers/cb_pcidas.c
drivers/staging/comedi/drivers/cb_pcidas64.c
drivers/staging/comedi/drivers/cb_pcidda.c
drivers/staging/comedi/drivers/cb_pcimdda.c
drivers/staging/comedi/drivers/daqboard2000.c
drivers/staging/comedi/drivers/das08.c
drivers/staging/comedi/drivers/das08.h
drivers/staging/comedi/drivers/das08_cs.c
drivers/staging/comedi/drivers/das08_isa.c
drivers/staging/comedi/drivers/das08_pci.c
drivers/staging/comedi/drivers/das16.c
drivers/staging/comedi/drivers/das16m1.c
drivers/staging/comedi/drivers/ni_65xx.c
drivers/staging/comedi/drivers/ni_atmio16d.c
drivers/staging/comedi/drivers/ni_daq_dio24.c
drivers/staging/comedi/drivers/ni_labpc.c
drivers/staging/comedi/drivers/ni_labpc.h
drivers/staging/comedi/drivers/ni_labpc_cs.c
drivers/staging/comedi/drivers/ni_labpc_pci.c
drivers/staging/comedi/drivers/ni_mio_common.c
drivers/staging/comedi/drivers/pcl724.c
drivers/staging/comedi/drivers/pcm3724.c

index c561a0eda92a6c6edddd2d095d3f1f23e39607e0..423f882416d97d2b533d7bc3eda310469c6959fe 100644 (file)
@@ -531,6 +531,21 @@ static bool comedi_is_subdevice_idle(struct comedi_subdevice *s)
        return (runflags & (SRF_ERROR | SRF_RUNNING)) ? false : true;
 }
 
+/**
+ * comedi_set_spriv() - Set the subdevice private data pointer.
+ * @s: comedi_subdevice struct
+ * @data: pointer to the private data
+ *
+ * This also sets the subdevice runflags to allow the core to automatically
+ * free the private data during the detach.
+ */
+void comedi_set_spriv(struct comedi_subdevice *s, void *data)
+{
+       s->private = data;
+       comedi_set_subdevice_runflags(s, ~0, SRF_FREE_SPRIV);
+}
+EXPORT_SYMBOL_GPL(comedi_set_spriv);
+
 /*
    This function restores a subdevice to an idle state.
  */
index 57deabf77418dc2beac03eb03049f1b226369748..e8dc7af8f5a1bee3dd40463da62c28bdfa04ffb5 100644 (file)
@@ -265,10 +265,12 @@ enum subdevice_runflags {
        /* indicates an COMEDI_CB_ERROR event has occurred since the last
         * command was started */
        SRF_ERROR = 0x00000004,
-       SRF_RUNNING = 0x08000000
+       SRF_RUNNING = 0x08000000,
+       SRF_FREE_SPRIV = 0x80000000,    /* free s->private on detach */
 };
 
 bool comedi_is_subdevice_running(struct comedi_subdevice *s);
+void comedi_set_spriv(struct comedi_subdevice *s, void *data);
 
 int comedi_check_chanlist(struct comedi_subdevice *s,
                          int n,
@@ -356,8 +358,6 @@ void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset,
 
 int comedi_alloc_subdevices(struct comedi_device *, int);
 
-void comedi_spriv_free(struct comedi_device *, int subdev_num);
-
 int comedi_load_firmware(struct comedi_device *, struct device *,
                         const char *name,
                         int (*cb)(struct comedi_device *,
index f3e57fd8b2fbe8a6fed6014626749970b28b0bf7..e25eba5713c153a9fd2e829561eb481b26a8dc47 100644 (file)
@@ -83,18 +83,6 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
 }
 EXPORT_SYMBOL_GPL(comedi_alloc_subdevices);
 
-void comedi_spriv_free(struct comedi_device *dev, int subdev_num)
-{
-       struct comedi_subdevice *s;
-
-       if (dev->subdevices && subdev_num < dev->n_subdevices) {
-               s = &dev->subdevices[subdev_num];
-               kfree(s->private);
-               s->private = NULL;
-       }
-}
-EXPORT_SYMBOL_GPL(comedi_spriv_free);
-
 static void cleanup_device(struct comedi_device *dev)
 {
        int i;
@@ -103,6 +91,8 @@ static void cleanup_device(struct comedi_device *dev)
        if (dev->subdevices) {
                for (i = 0; i < dev->n_subdevices; i++) {
                        s = &dev->subdevices[i];
+                       if (s->runflags & SRF_FREE_SPRIV)
+                               kfree(s->private);
                        comedi_free_subdevice_minor(s);
                        if (s->async) {
                                comedi_buf_alloc(dev, s, 0);
index 1a1c2dae886b6a8ac371a4bef46a87ad0b5baf9f..dca9b40cefdc8a54e941282252bb86cf711f070d 100644 (file)
@@ -288,12 +288,11 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s,
        spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
        if (!spriv)
                return -ENOMEM;
+       comedi_set_spriv(s, spriv);
 
        spriv->iobase   = iobase;
        spriv->io       = io ? io : subdev_8255_io;
 
-       s->private      = spriv;
-
        s->type         = COMEDI_SUBD_DIO;
        s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
        s->n_chan       = 24;
@@ -386,7 +385,6 @@ static void dev_8255_detach(struct comedi_device *dev)
                        spriv = s->private;
                        release_region(spriv->iobase, _8255_SIZE);
                }
-               comedi_spriv_free(dev, i);
        }
 }
 
index 1117b61da3af1292a202b99efe69c3352cb196d4..3d3547c194806fae3e2cb1d84d61d13dc52f1fb1 100644 (file)
@@ -238,10 +238,7 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
 static void pci_8255_detach(struct comedi_device *dev)
 {
        struct pci_8255_private *devpriv = dev->private;
-       int i;
 
-       for (i = 0; i < dev->n_subdevices; i++)
-               comedi_spriv_free(dev, i);
        if (devpriv && devpriv->mmio_base)
                iounmap(devpriv->mmio_base);
        comedi_pci_disable(dev);
index 5bf6bb129cd47c6436c4830eaaf4b28b89b4d2de..b626738bb73c4c3feac97d6b5b64b1754b701398 100644 (file)
@@ -196,7 +196,6 @@ static void apci1516_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                apci1516_reset(dev);
-       comedi_spriv_free(dev, 2);
        comedi_pci_disable(dev);
 }
 
index c0d83d8709f420dbc9063d120290b3191d7f3cae..89ead8eb3c70702c20b3a06631a6b4f17b258d60 100644 (file)
@@ -347,7 +347,6 @@ static void apci2032_detach(struct comedi_device *dev)
                free_irq(dev->irq, dev);
        if (dev->read_subdev)
                kfree(dev->read_subdev->private);
-       comedi_spriv_free(dev, 1);
        comedi_pci_disable(dev);
 }
 
index 060620e184d6960d772f4a44ff41cabc5055fabb..ca1bd92ecb1748e269037a9675b9fc2f04138a6a 100644 (file)
@@ -123,7 +123,6 @@ static void apci2200_detach(struct comedi_device *dev)
 {
        if (dev->iobase)
                apci2200_reset(dev);
-       comedi_spriv_free(dev, 2);
        comedi_pci_disable(dev);
 }
 
index 2c21a16255473b37e205c35b68c85272d902d092..decc97d0e415e05c043270e86474a60f1feb99b7 100644 (file)
@@ -129,11 +129,10 @@ int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase)
        spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
        if (!spriv)
                return -ENOMEM;
+       comedi_set_spriv(s, spriv);
 
        spriv->iobase = iobase;
 
-       s->private      = spriv;
-
        s->type         = COMEDI_SUBD_TIMER;
        s->subdev_flags = SDF_WRITEABLE;
        s->n_chan       = 1;
index f70c67471c13a42aa850db35a9352edf70e69202..8e6ec75bd294faf12863d2f352c1a0007a5b56aa 100644 (file)
@@ -1173,19 +1173,11 @@ static int pci_dio_auto_attach(struct comedi_device *dev,
 static void pci_dio_detach(struct comedi_device *dev)
 {
        struct pci_dio_private *devpriv = dev->private;
-       struct comedi_subdevice *s;
-       int i;
 
        if (devpriv) {
                if (devpriv->valid)
                        pci_dio_reset(dev);
        }
-       for (i = 0; i < dev->n_subdevices; i++) {
-               s = &dev->subdevices[i];
-               if (s->type == COMEDI_SUBD_DIO)
-                       comedi_spriv_free(dev, i);
-               s->private = NULL; /* some private data is static */
-       }
        comedi_pci_disable(dev);
 }
 
index 77c92cb23d474c4a438a4157e013471e33eb52b6..279dfe8951f703d78f56e0cde365f61aad998f04 100644 (file)
@@ -255,17 +255,11 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void aio_aio12_8_detach(struct comedi_device *dev)
-{
-       comedi_spriv_free(dev, 2);
-       comedi_legacy_detach(dev);
-}
-
 static struct comedi_driver aio_aio12_8_driver = {
        .driver_name    = "aio_aio12_8",
        .module         = THIS_MODULE,
        .attach         = aio_aio12_8_attach,
-       .detach         = aio_aio12_8_detach,
+       .detach         = comedi_legacy_detach,
        .board_name     = &board_types[0].name,
        .num_names      = ARRAY_SIZE(board_types),
        .offset         = sizeof(struct aio12_8_boardtype),
index 81d6ee4549cb08db145f46b3e2f6501cc36179a5..00c35a3541e8945d634ddff156ec61c9ad83a95e 100644 (file)
@@ -559,6 +559,7 @@ dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s,
        subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
        if (!subpriv)
                return -ENOMEM;
+       comedi_set_spriv(s, subpriv);
 
        subpriv->ofs = offset;
        subpriv->valid_isns = valid_isns;
@@ -568,7 +569,6 @@ dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s,
                /* Disable interrupt sources. */
                dio200_write8(dev, subpriv->ofs, 0);
 
-       s->private = subpriv;
        s->type = COMEDI_SUBD_DI;
        s->subdev_flags = SDF_READABLE | SDF_CMD_READ;
        if (layout->has_int_sce) {
@@ -886,8 +886,8 @@ dio200_subdev_8254_init(struct comedi_device *dev, struct comedi_subdevice *s,
        subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
        if (!subpriv)
                return -ENOMEM;
+       comedi_set_spriv(s, subpriv);
 
-       s->private = subpriv;
        s->type = COMEDI_SUBD_COUNTER;
        s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
        s->n_chan = 3;
@@ -1022,8 +1022,10 @@ static int dio200_subdev_8255_init(struct comedi_device *dev,
        subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
        if (!subpriv)
                return -ENOMEM;
+       comedi_set_spriv(s, subpriv);
+
        subpriv->ofs = offset;
-       s->private = subpriv;
+
        s->type = COMEDI_SUBD_DIO;
        s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
        s->n_chan = 24;
@@ -1225,28 +1227,11 @@ void amplc_dio200_common_detach(struct comedi_device *dev)
 {
        const struct dio200_board *thisboard = comedi_board(dev);
        struct dio200_private *devpriv = dev->private;
-       const struct dio200_layout *layout;
-       unsigned n;
 
        if (!thisboard || !devpriv)
                return;
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (dev->subdevices) {
-               layout = dio200_board_layout(thisboard);
-               for (n = 0; n < dev->n_subdevices; n++) {
-                       switch (layout->sdtype[n]) {
-                       case sd_8254:
-                       case sd_8255:
-                       case sd_intr:
-                               comedi_spriv_free(dev, n);
-                               break;
-                       case sd_timer:
-                       default:
-                               break;
-                       }
-               }
-       }
 }
 EXPORT_SYMBOL_GPL(amplc_dio200_common_detach);
 
index 179d25e00ace87ee7137c568ca399c2ae7b3973a..4e889b82cbf2a3827010d2d7a37fd046e6c240cf 100644 (file)
@@ -538,7 +538,6 @@ static void pc236_detach(struct comedi_device *dev)
                return;
        if (dev->iobase)
                pc236_intr_disable(dev);
-       comedi_spriv_free(dev, 0);
        if (is_isa_board(thisboard)) {
                comedi_legacy_detach(dev);
        } else if (is_pci_board(thisboard)) {
index 08ff12837e00150601a7de497884bab0b712c4b3..846d6448fa4dd68ee3485b826270b08cb3d03ae5 100644 (file)
@@ -2830,7 +2830,6 @@ static void pci230_detach(struct comedi_device *dev)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
-       comedi_spriv_free(dev, 2);
        if (dev->irq)
                free_irq(dev->irq, dev);
        comedi_pci_disable(dev);
index 172f459b0af2f920055184d7479866ba6700a30a..58bca184bf22d4d85f86550835708e82fed2fc43 100644 (file)
@@ -1602,7 +1602,6 @@ static void cb_pcidas_detach(struct comedi_device *dev)
        }
        if (dev->irq)
                free_irq(dev->irq, dev);
-       comedi_spriv_free(dev, 2);
        comedi_pci_disable(dev);
 }
 
index 11f8101d851a8a11ceffd4d3648f04ce22163ea1..43c0bf58771ad6deac07067144c565260598c849 100644 (file)
@@ -4158,7 +4158,6 @@ static void detach(struct comedi_device *dev)
                                        devpriv->ao_dma_desc_bus_addr);
                }
        }
-       comedi_spriv_free(dev, 4);
        comedi_pci_disable(dev);
 }
 
index b74d4c38b5c3afa588c11197a182566c900d7402..2d3e920e598711a0cb0b2d6a08dc85b8363f97aa 100644 (file)
@@ -393,18 +393,11 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void cb_pcidda_detach(struct comedi_device *dev)
-{
-       comedi_spriv_free(dev, 1);
-       comedi_spriv_free(dev, 2);
-       comedi_pci_disable(dev);
-}
-
 static struct comedi_driver cb_pcidda_driver = {
        .driver_name    = "cb_pcidda",
        .module         = THIS_MODULE,
        .auto_attach    = cb_pcidda_auto_attach,
-       .detach         = cb_pcidda_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int cb_pcidda_pci_probe(struct pci_dev *dev,
index d3a796eef883db0bc6285aed98993ec4a9a3f44a..406cba8cba88e83335e1bff5491133196e0e0cb6 100644 (file)
@@ -192,17 +192,11 @@ static int cb_pcimdda_auto_attach(struct comedi_device *dev,
        return 1;
 }
 
-static void cb_pcimdda_detach(struct comedi_device *dev)
-{
-       comedi_spriv_free(dev, 1);
-       comedi_pci_disable(dev);
-}
-
 static struct comedi_driver cb_pcimdda_driver = {
        .driver_name    = "cb_pcimdda",
        .module         = THIS_MODULE,
        .auto_attach    = cb_pcimdda_auto_attach,
-       .detach         = cb_pcimdda_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int cb_pcimdda_pci_probe(struct pci_dev *dev,
index f5aa3860e3e7e8d40ea7eeda1774df094b834116..44c912b48b6e27a773df0cd93580a8cf835761ae 100644 (file)
@@ -747,7 +747,6 @@ static void daqboard2000_detach(struct comedi_device *dev)
 {
        struct daqboard2000_private *devpriv = dev->private;
 
-       comedi_spriv_free(dev, 2);
        if (dev->irq)
                free_irq(dev->irq, dev);
        if (devpriv) {
index 64807eaa559eba5dd97fbeea7cf6f1b6ecc817d8..2e7e3e202390763ea14083c75ea4dfeb238e2669 100644 (file)
@@ -560,12 +560,6 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
 }
 EXPORT_SYMBOL_GPL(das08_common_attach);
 
-void das08_common_detach(struct comedi_device *dev)
-{
-       comedi_spriv_free(dev, 4);
-}
-EXPORT_SYMBOL_GPL(das08_common_detach);
-
 static int __init das08_init(void)
 {
        return 0;
index c312870ab691219aa529519fd853b15be5d2ff9e..cce1b584200a82acbf1036af85fa91c103b2d3e8 100644 (file)
@@ -47,6 +47,5 @@ struct das08_private_struct {
 };
 
 int das08_common_attach(struct comedi_device *dev, unsigned long iobase);
-void das08_common_detach(struct comedi_device *dev);
 
 #endif /* _DAS08_H */
index 3625b3eafe7c93005acfb85b2ff7ebbd04fc8157..885fb179c9b412648e33d493b0e4b8126db1eec0 100644 (file)
@@ -86,17 +86,11 @@ static int das08_cs_auto_attach(struct comedi_device *dev,
        return das08_common_attach(dev, iobase);
 }
 
-static void das08_cs_detach(struct comedi_device *dev)
-{
-       das08_common_detach(dev);
-       comedi_pcmcia_disable(dev);
-}
-
 static struct comedi_driver driver_das08_cs = {
        .driver_name    = "das08_cs",
        .module         = THIS_MODULE,
        .auto_attach    = das08_cs_auto_attach,
-       .detach         = das08_cs_detach,
+       .detach         = comedi_pcmcia_disable,
 };
 
 static int das08_pcmcia_attach(struct pcmcia_device *link)
index 10e96e94515ca93e9c3575a9c66e5ed5ebdf96f1..21a94389b8b20bb925faeb651b032dc01b746f15 100644 (file)
@@ -189,17 +189,11 @@ static int das08_isa_attach(struct comedi_device *dev,
        return das08_common_attach(dev, dev->iobase);
 }
 
-static void das08_isa_detach(struct comedi_device *dev)
-{
-       das08_common_detach(dev);
-       comedi_legacy_detach(dev);
-}
-
 static struct comedi_driver das08_isa_driver = {
        .driver_name    = "isa-das08",
        .module         = THIS_MODULE,
        .attach         = das08_isa_attach,
-       .detach         = das08_isa_detach,
+       .detach         = comedi_legacy_detach,
        .board_name     = &das08_isa_boards[0].name,
        .num_names      = ARRAY_SIZE(das08_isa_boards),
        .offset         = sizeof(das08_isa_boards[0]),
index 351fbc6027f11bd93e5f977caec9381196457482..9c5d234e063f0a9b513e52cb3e76eea35a6b48ab 100644 (file)
@@ -75,17 +75,11 @@ static int das08_pci_auto_attach(struct comedi_device *dev,
        return das08_common_attach(dev, dev->iobase);
 }
 
-static void das08_pci_detach(struct comedi_device *dev)
-{
-       das08_common_detach(dev);
-       comedi_pci_disable(dev);
-}
-
 static struct comedi_driver das08_pci_comedi_driver = {
        .driver_name    = "pci-das08",
        .module         = THIS_MODULE,
        .auto_attach    = das08_pci_auto_attach,
-       .detach         = das08_pci_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int das08_pci_probe(struct pci_dev *dev,
index dab7647ec2f5776f53312959e18224f9fa12a08e..dbec3ba995487553ee558ceabb7ed47fe356ab94 100644 (file)
@@ -1333,7 +1333,6 @@ static void das16_detach(struct comedi_device *dev)
        struct das16_private_struct *devpriv = dev->private;
 
        das16_reset(dev);
-       comedi_spriv_free(dev, 4);
        if (devpriv) {
                int i;
                for (i = 0; i < 2; i++) {
index e7ae2ffe8c797b24375cd92ce7d62c4544883a13..0b33808c3a7d91b6f1c53257c85114d72e613b2d 100644 (file)
@@ -666,7 +666,6 @@ static void das16m1_detach(struct comedi_device *dev)
 {
        struct das16m1_private_struct *devpriv = dev->private;
 
-       comedi_spriv_free(dev, 3);
        if (devpriv && devpriv->extra_iobase)
                release_region(devpriv->extra_iobase, DAS16M1_SIZE2);
        comedi_legacy_detach(dev);
index 6a89e5c166e3a0031d9b18064b404679c90cbdd4..5907fd262a38171c052ed68a82331312fd0b8742 100644 (file)
@@ -281,13 +281,16 @@ static inline struct ni_65xx_subdevice_private *sprivate(struct comedi_subdevice
        return subdev->private;
 }
 
-static struct ni_65xx_subdevice_private *ni_65xx_alloc_subdevice_private(void)
+static int ni_65xx_alloc_subdevice_private(struct comedi_subdevice *s)
 {
-       struct ni_65xx_subdevice_private *subdev_private =
-           kzalloc(sizeof(struct ni_65xx_subdevice_private), GFP_KERNEL);
-       if (subdev_private == NULL)
-               return NULL;
-       return subdev_private;
+       struct ni_65xx_subdevice_private *spriv;
+
+       spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
+       if (!spriv)
+               return -ENOMEM;
+       comedi_set_spriv(s, spriv);
+
+       return 0;
 }
 
 static int ni_65xx_config_filter(struct comedi_device *dev,
@@ -632,9 +635,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;
-               s->private = ni_65xx_alloc_subdevice_private();
-               if (s->private == NULL)
-                       return -ENOMEM;
+               ret = ni_65xx_alloc_subdevice_private(s);
+               if (ret)
+                       return ret;
                sprivate(s)->base_port = 0;
        } else {
                s->type = COMEDI_SUBD_UNUSED;
@@ -649,9 +652,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;
-               s->private = ni_65xx_alloc_subdevice_private();
-               if (s->private == NULL)
-                       return -ENOMEM;
+               ret = ni_65xx_alloc_subdevice_private(s);
+               if (ret)
+                       return ret;
                sprivate(s)->base_port = board->num_di_ports;
        } else {
                s->type = COMEDI_SUBD_UNUSED;
@@ -667,9 +670,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;
-               s->private = ni_65xx_alloc_subdevice_private();
-               if (s->private == NULL)
-                       return -ENOMEM;
+               ret = ni_65xx_alloc_subdevice_private(s);
+               if (ret)
+                       return ret;
                sprivate(s)->base_port = 0;
                for (i = 0; i < board->num_dio_ports; ++i) {
                        /*  configure all ports for input */
@@ -725,7 +728,6 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
 static void ni_65xx_detach(struct comedi_device *dev)
 {
        struct ni_65xx_private *devpriv = dev->private;
-       int i;
 
        if (devpriv && devpriv->mite && devpriv->mite->daq_io_addr) {
                writeb(0x00,
@@ -734,8 +736,6 @@ static void ni_65xx_detach(struct comedi_device *dev)
        }
        if (dev->irq)
                free_irq(dev->irq, dev);
-       for (i = 0; i < dev->n_subdevices; ++i)
-               comedi_spriv_free(dev, i);
        if (devpriv) {
                if (devpriv->mite) {
                        mite_unsetup(devpriv->mite);
index d280332d32d193edc58aa50971f5169d45a9aab2..da7396f94297fe7620faec494f500a906c3df0cf 100644 (file)
@@ -762,7 +762,6 @@ static int atmio16d_attach(struct comedi_device *dev,
 
 static void atmio16d_detach(struct comedi_device *dev)
 {
-       comedi_spriv_free(dev, 3);
        reset_atmio16d(dev);
        comedi_legacy_detach(dev);
 }
index 6ff1526bd063a97c082fe0b3622a3d0ed42f27bc..d3d4eb9356a7562d2ae07559bb2941693d5e99e2 100644 (file)
@@ -65,17 +65,11 @@ static int dio24_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void dio24_detach(struct comedi_device *dev)
-{
-       comedi_spriv_free(dev, 0);
-       comedi_pcmcia_disable(dev);
-}
-
 static struct comedi_driver driver_dio24 = {
        .driver_name    = "ni_daq_dio24",
        .module         = THIS_MODULE,
        .auto_attach    = dio24_auto_attach,
-       .detach         = dio24_detach,
+       .detach         = comedi_pcmcia_disable,
 };
 
 static int dio24_cs_attach(struct pcmcia_device *link)
index a918b7ffbe22d28d58ecd00d9c8a339398c80eca..f161e70b3a0d343efefd3cae1bc9bba67fcf0d4e 100644 (file)
@@ -1689,12 +1689,6 @@ int labpc_common_attach(struct comedi_device *dev,
 }
 EXPORT_SYMBOL_GPL(labpc_common_attach);
 
-void labpc_common_detach(struct comedi_device *dev)
-{
-       comedi_spriv_free(dev, 2);
-}
-EXPORT_SYMBOL_GPL(labpc_common_detach);
-
 #if IS_ENABLED(CONFIG_COMEDI_NI_LABPC_ISA)
 static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 {
@@ -1747,8 +1741,6 @@ static void labpc_detach(struct comedi_device *dev)
 {
        struct labpc_private *devpriv = dev->private;
 
-       labpc_common_detach(dev);
-
        if (devpriv) {
                kfree(devpriv->dma_buffer);
                if (devpriv->dma_chan)
index aa5c4d8bdf75f0c91012e21cb1ead935a508607d..486589fa6fd82d8dcf34fff1cc223999149a9702 100644 (file)
@@ -86,6 +86,5 @@ struct labpc_private {
 
 int labpc_common_attach(struct comedi_device *dev,
                        unsigned int irq, unsigned long isr_flags);
-void labpc_common_detach(struct comedi_device *dev);
 
 #endif /* _NI_LABPC_H */
index 883581eb3dbe4b4123b86a5da5bc6a698df2eb9b..ce67f4bbb1f5596060f471fb96e93d986dda8883 100644 (file)
@@ -104,17 +104,11 @@ static int labpc_auto_attach(struct comedi_device *dev,
        return labpc_common_attach(dev, link->irq, IRQF_SHARED);
 }
 
-static void labpc_detach(struct comedi_device *dev)
-{
-       labpc_common_detach(dev);
-       comedi_pcmcia_disable(dev);
-}
-
 static struct comedi_driver driver_labpc_cs = {
        .driver_name    = "ni_labpc_cs",
        .module         = THIS_MODULE,
        .auto_attach    = labpc_auto_attach,
-       .detach         = labpc_detach,
+       .detach         = comedi_pcmcia_disable,
 };
 
 static int labpc_cs_attach(struct pcmcia_device *link)
index 1f80711bf3687813e424df600ef1bd6fef4937aa..6c79237b2b5c624dadb7e9fb6c5adbdcdb3ce64d 100644 (file)
@@ -92,8 +92,6 @@ static void labpc_pci_detach(struct comedi_device *dev)
 {
        struct labpc_private *devpriv = dev->private;
 
-       labpc_common_detach(dev);
-
        if (devpriv && devpriv->mite) {
                mite_unsetup(devpriv->mite);
                mite_free(devpriv->mite);
index 1e78198a2253441e8defa9a48365e085c6b5c2c8..3e9f544e67fc2247a2f8a46c16bf4105c3f38f49 100644 (file)
@@ -4072,7 +4072,6 @@ static void mio_common_detach(struct comedi_device *dev)
                        ni_gpct_device_destroy(devpriv->counter_dev);
                }
        }
-       comedi_spriv_free(dev, NI_8255_DIO_SUBDEV);
 }
 
 static void init_ao_67xx(struct comedi_device *dev, struct comedi_subdevice *s)
index 1bcabb8901d167dc6aedd54ea9f83d2165fa3346..cea657c7801dd49aee659eda220ad50df6be07d7 100644 (file)
@@ -136,20 +136,11 @@ static int pcl724_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void pcl724_detach(struct comedi_device *dev)
-{
-       int i;
-
-       for (i = 0; i < dev->n_subdevices; i++)
-               comedi_spriv_free(dev, i);
-       comedi_legacy_detach(dev);
-}
-
 static struct comedi_driver pcl724_driver = {
        .driver_name    = "pcl724",
        .module         = THIS_MODULE,
        .attach         = pcl724_attach,
-       .detach         = pcl724_detach,
+       .detach         = comedi_legacy_detach,
        .board_name     = &boardtypes[0].name,
        .num_names      = ARRAY_SIZE(boardtypes),
        .offset         = sizeof(struct pcl724_board),
index 4ef0df30b07a1b11349378940294f9df49e5d997..5a9cd38e15f266ed9ce27b8682b4973cbdc8aeac 100644 (file)
@@ -250,20 +250,11 @@ static int pcm3724_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void pcm3724_detach(struct comedi_device *dev)
-{
-       int i;
-
-       for (i = 0; i < dev->n_subdevices; i++)
-               comedi_spriv_free(dev, i);
-       comedi_legacy_detach(dev);
-}
-
 static struct comedi_driver pcm3724_driver = {
        .driver_name    = "pcm3724",
        .module         = THIS_MODULE,
        .attach         = pcm3724_attach,
-       .detach         = pcm3724_detach,
+       .detach         = comedi_legacy_detach,
 };
 module_comedi_driver(pcm3724_driver);