replace deprecated MOD_INC_USE_COUNT/MOD_DEC_USE_COUNT with
authorFrank Mori Hess <fmhess@speakeasy.net>
Mon, 4 Aug 2003 18:32:31 +0000 (18:32 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Mon, 4 Aug 2003 18:32:31 +0000 (18:32 +0000)
try_module_get()/module_put()

comedi/comedi_fops.c
comedi/drivers.c
comedi/kcomedilib/kcomedilib_main.c

index 26e96de938fe46455baea2db0b34fc2905c3b9f3..78792d77cd1fe6e05b1f92c265cb78eb81f2d903 100644 (file)
@@ -1632,10 +1632,11 @@ static int comedi_fop_open(struct inode *inode,struct file *file)
        return -ENODEV;
 
 ok:
-       MOD_INC_USE_COUNT;
+       if(!try_module_get(THIS_MODULE))
+               return -ENOSYS;
 
-       if(dev->attached && dev->driver->module){
-               __MOD_INC_USE_COUNT(dev->driver->module);
+       if(dev->attached){
+               try_module_get( dev->driver->module );
        }
 
        if(dev->attached && dev->use_count==0 && dev->open){
@@ -1668,9 +1669,9 @@ static int comedi_close_v22(struct inode *inode,struct file *file)
                dev->close(dev);
        }
 
-       MOD_DEC_USE_COUNT;
-       if(dev->attached && dev->driver->module){
-               __MOD_DEC_USE_COUNT(dev->driver->module);
+       module_put(THIS_MODULE);
+       if(dev->attached){
+               module_put(dev->driver->module);
        }
 
        dev->use_count--;
index 8464b1c0e05320dc481c5ee2a5e74979dd019f77..a74a236de3ecf2110ab53cc0ec5fecf5326cec47 100644 (file)
@@ -63,9 +63,8 @@ int comedi_device_detach(comedi_device *dev)
        if(!dev->attached)
                return 0;
 
-       /* this is not correct for the kmod case */
-       if(dev->driver->module)
-               __MOD_DEC_USE_COUNT(dev->driver->module);
+       /* this is not correct for the kmod case? */
+       module_put(dev->driver->module);
 
        dev->attached=0;
 
@@ -108,12 +107,22 @@ int comedi_device_attach(comedi_device *dev,comedi_devconfig *it)
        dev->use_count = use_count;
 
        for(driv=comedi_drivers;driv;driv=driv->next){
+               if(!try_module_get( driv->module ))
+               {
+                       printk( "comedi: failed to increment module count, skipping\n" );
+                       continue;
+               }
                if(driv->num_names){
                        dev->board_ptr=comedi_recognize(driv, it->board_name);
-                       if(dev->board_ptr==NULL) continue;
+                       if(dev->board_ptr==NULL){
+                               module_put( driv->module );
+                               continue;
+                       }
                }else{
-                       if(strcmp(driv->driver_name,it->board_name))
+                       if(strcmp(driv->driver_name,it->board_name)){
+                               module_put( driv->module );
                                continue;
+                       }
                }
                //initialize dev->driver here so comedi_error() can be called from attach
                dev->driver=driv;
@@ -122,16 +131,23 @@ int comedi_device_attach(comedi_device *dev,comedi_devconfig *it)
                        driv->detach(dev);
                        if(dev->subdevices)kfree(dev->subdevices);
                        if(dev->private)kfree(dev->private);
-
+                       module_put( driv->module );
                        return ret;
                }
                goto attached;
+               module_put( driv->module );
        }
 
        // recognize has failed if we get here
        // report valid board names before returning error
        for(driv=comedi_drivers;driv;driv=driv->next){
+               if(!try_module_get( driv->module ))
+               {
+                       printk( "comedi: failed to increment module count\n" );
+                       continue;
+               }
                comedi_report_boards(driv);
+               module_put( driv->module );
        }
        return -EIO;
 
@@ -157,9 +173,6 @@ attached:
 
        dev->attached=1;
 
-       if(driv->module)
-               __MOD_INC_USE_COUNT(driv->module);
-
        return 0;
 }
 
index f14e7708d8399185eda6c94f0e41d2a1c4d303ec..f899dc5927d29caf14e679261dc715455fa995f3 100644 (file)
@@ -65,7 +65,8 @@ comedi_t *comedi_open(const char *filename)
        if(!dev->attached)
                return NULL;
 
-       __MOD_INC_USE_COUNT(dev->driver->module);
+       if(!try_module_get(dev->driver->module))
+               return NULL;
 
        return (comedi_t *)dev;
 }
@@ -89,7 +90,7 @@ int comedi_close(comedi_t *d)
 {
        comedi_device *dev = (comedi_device *) d;
 
-       __MOD_DEC_USE_COUNT(dev->driver->module);
+       module_put(dev->driver->module);
 
        return 0;
 }