From 6d77a6e539699e3d8e3ed45aae5595bb0732e212 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 4 Aug 2003 18:32:31 +0000 Subject: [PATCH] replace deprecated MOD_INC_USE_COUNT/MOD_DEC_USE_COUNT with try_module_get()/module_put() --- comedi/comedi_fops.c | 13 ++++++------ comedi/drivers.c | 31 ++++++++++++++++++++--------- comedi/kcomedilib/kcomedilib_main.c | 5 +++-- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 26e96de9..78792d77 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -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--; diff --git a/comedi/drivers.c b/comedi/drivers.c index 8464b1c0..a74a236d 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -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; } diff --git a/comedi/kcomedilib/kcomedilib_main.c b/comedi/kcomedilib/kcomedilib_main.c index f14e7708..f899dc59 100644 --- a/comedi/kcomedilib/kcomedilib_main.c +++ b/comedi/kcomedilib/kcomedilib_main.c @@ -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; } -- 2.26.2