Fixed possibile failures to decrement module use count on errors
authorFrank Mori Hess <fmhess@speakeasy.net>
Mon, 20 Nov 2006 19:41:51 +0000 (19:41 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Mon, 20 Nov 2006 19:41:51 +0000 (19:41 +0000)
(one was bug I probably introduced recently).

comedi/drivers.c

index 683fd0da646c8e317f3a96edca78f6706ca653b0..b6afb43e1451adec56514b4dc835a0d7a0a55c43 100644 (file)
@@ -61,7 +61,7 @@ int comedi_modprobe(int minor)
        return -EINVAL;
 }
 
-static void cleanup_device_allocations(comedi_device *dev)
+static void cleanup_device(comedi_device *dev)
 {
        int i;
        comedi_subdevice *s;
@@ -93,6 +93,15 @@ static void cleanup_device_allocations(comedi_device *dev)
                kfree(dev->private);
                dev->private = NULL;
        }
+       dev->driver = 0;
+       dev->board_name = NULL;
+       dev->board_ptr = NULL;
+       dev->iobase = 0;
+       dev->irq = 0;
+       dev->read_subdev = NULL;
+       dev->write_subdev = NULL;
+       dev->open = NULL;
+       dev->close = NULL;
 }
 
 int comedi_device_detach(comedi_device *dev)
@@ -111,16 +120,7 @@ int comedi_device_detach(comedi_device *dev)
                printk("BUG: dev->driver=NULL in comedi_device_detach()\n");
        }
 
-       cleanup_device_allocations(dev);
-       dev->driver = 0;
-       dev->board_name = NULL;
-       dev->board_ptr = NULL;
-       dev->iobase = 0;
-       dev->irq = 0;
-       dev->read_subdev = NULL;
-       dev->write_subdev = NULL;
-       dev->open = NULL;
-       dev->close = NULL;
+       cleanup_device(dev);
        return 0;
 }
 
@@ -154,7 +154,9 @@ int comedi_device_attach(comedi_device *dev,comedi_devconfig *it)
                dev->driver=driv;
                ret=driv->attach(dev,it);
                if(ret<0){
-                       comedi_device_detach(dev);
+                       driv->detach(dev);
+                       cleanup_device(dev);
+                       module_put(driv->module);
                        return ret;
                }
                goto attached;
@@ -180,7 +182,8 @@ attached:
        if(ret < 0)
        {
                driv->detach(dev);
-               cleanup_device_allocations(dev);
+               cleanup_device(dev);
+               module_put(driv->module);
                return ret;
        }