From: David Schleef Date: Thu, 5 Jul 2001 05:33:16 +0000 (+0000) Subject: Rewrote checking in comedi_fop_open(), fixed spinlock init X-Git-Tag: r0_7_60~98 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bda1469e1138569325fa8768b50cffbca3454639;p=comedi.git Rewrote checking in comedi_fop_open(), fixed spinlock init problem. --- diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 57b5d18c..bf395800 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -1621,25 +1621,40 @@ static int comedi_fop_open(struct inode *inode,struct file *file) { kdev_t minor=MINOR(inode->i_rdev); comedi_device *dev; - static int in_comedi_open=0; char mod[32]; if(minor>=COMEDI_NDEVICES)return -ENODEV; dev=comedi_get_device_by_minor(minor); + + /* This is slightly hacky, but we want module autoloading + * to work for root. + * case: user opens device, attached -> ok + * case: user opens device, unattached, in_request_module=0 -> autoload + * case: user opens device, unattached, in_request_module=1 -> fail + * case: root opens device, attached -> ok + * case: root opens device, unattached, in_request_module=1 -> ok + * (typically called from modprobe) + * case: root opens device, unattached, in_request_module=0 -> autoload + * + * The last could be changed to "-> ok", which would deny root + * autoloading. + */ if(dev->attached) goto ok; - if(in_comedi_open && suser()) + if(!suser() && dev->in_request_module) + return -ENODEV; + if(suser() && dev->in_request_module) goto ok; - in_comedi_open=1; + dev->in_request_module=1; sprintf(mod,"char-major-%i-%i",COMEDI_MAJOR,minor); #ifdef CONFIG_KMOD request_module(mod); #endif - in_comedi_open=0; + dev->in_request_module=0; if(dev->attached || suser()) goto ok; @@ -1775,6 +1790,7 @@ int comedi_init(void) memset(comedi_devices,0,sizeof(comedi_device)*COMEDI_NDEVICES); for(i=0;iminor; use_count = dev->use_count; memset(dev,0,sizeof(comedi_device)); + spin_lock_init(&dev->spinlock); dev->minor=minor; dev->use_count = use_count; diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index 5df9e908..df5fd928 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -162,6 +162,7 @@ struct comedi_device_struct{ int attached; int rt; spinlock_t spinlock; + int in_request_module; int n_subdevices; comedi_subdevice *subdevices;