BKL mass-conversion to mutex
Subsystems (43)
Arnd Bergmann
maintainercover BKL mass-conversion to mutex
This is one out of five topic branches in my BKL removal series that I would like to get into linux-next as a preparation for merging into 2.6.37.
Based on a discussion with Ingo Molnar, this series converts many drivers that only have a single file using the BKL to use a private mutex instead. All these patches except for the last two have been reviewed before.
This is safe because they all use the BKL only to protect their basic file operations and they take it as the outermost lock. Consequently, we do not run into lock-order problem or recursion.
Using a script that works for all these drivers gives me reasonable confidence in the approach, since it avoids typos and other common mistakes from sloppiness.
Stephen, please add git+ssh://master.kernel.org/pub/scm/linux/kernel/git/arnd/bkl.git trivial
Arnd Bergmann (7):
scsi: autoconvert trivial BKL users to private mutex
mtd: autoconvert trivial BKL users to private mutex
mac: autoconvert trivial BKL users to private mutex
ipmi: autoconvert trivial BKL users to private mutex
drivers: autoconvert trivial BKL users to private mutex
sound: autoconvert trivial BKL users to private mutex
block: autoconvert trivial BKL users to private mutex
block/bsg.c | 3 -- drivers/block/DAC960.c | 11 ++++--- drivers/block/amiflop.c | 19 ++++++------ drivers/block/aoe/aoeblk.c | 9 +++-- drivers/block/aoe/aoechr.c | 9 +++-- drivers/block/ataflop.c | 15 +++++---- drivers/block/brd.c | 7 ++-- drivers/block/cciss.c | 14 ++++---- drivers/block/cpqarray.c | 15 +++++---- drivers/block/drbd/drbd_main.c | 11 ++++--- drivers/block/floppy.c | 16 +++++----- drivers/block/loop.c | 11 ++++--- drivers/block/nbd.c | 7 ++-- drivers/block/paride/pcd.c | 15 +++++---- drivers/block/paride/pd.c | 15 +++++---- drivers/block/paride/pf.c | 17 ++++++----- drivers/block/paride/pg.c | 7 ++-- drivers/block/paride/pt.c | 19 ++++++------ drivers/block/pktcdvd.c | 16 +++++----- drivers/block/swim.c | 15 +++++---- drivers/block/swim3.c | 15 +++++---- drivers/block/ub.c | 15 +++++---- drivers/block/viodasd.c | 11 ++++--- drivers/block/virtio_blk.c | 7 ++-- drivers/block/xd.c | 7 ++-- drivers/block/xen-blkfront.c | 11 ++++--- drivers/block/xsysace.c | 11 ++++--- drivers/block/z2ram.c | 15 +++++---- drivers/cdrom/gdrom.c | 15 +++++---- drivers/cdrom/viocd.c | 15 +++++---- drivers/char/apm-emulation.c | 11 ++++--- drivers/char/applicom.c | 9 +++-- drivers/char/ds1302.c | 15 +++++---- drivers/char/ds1620.c | 8 ++-- drivers/char/dsp56k.c | 27 +++++++++-------- drivers/char/dtlk.c | 8 ++-- drivers/char/generic_nvram.c | 7 ++-- drivers/char/genrtc.c | 13 ++++---- drivers/char/i8k.c | 7 ++-- drivers/char/ip2/ip2main.c | 8 ++-- drivers/char/ipmi/ipmi_devintf.c | 14 ++++---- drivers/char/ipmi/ipmi_watchdog.c | 8 ++-- drivers/char/lp.c | 15 +++++---- drivers/char/mbcs.c | 8 ++-- drivers/char/mmtimer.c | 7 ++-- drivers/char/mwave/mwavedd.c | 44 ++++++++++++++-------------- drivers/char/nvram.c | 11 ++++--- drivers/char/nwflash.c | 12 ++++---- drivers/char/pcmcia/cm4000_cs.c | 11 ++++--- drivers/char/pcmcia/cm4040_cs.c | 7 ++-- drivers/char/ppdev.c | 8 ++-- drivers/char/rio/rio_linux.c | 7 ++-- drivers/char/snsc.c | 9 +++-- drivers/char/toshiba.c | 9 +++-- drivers/char/viotape.c | 11 ++++--- drivers/char/xilinx_hwicap/xilinx_hwicap.c | 6 ++-- drivers/hwmon/fschmd.c | 6 ++-- drivers/hwmon/w83793.c | 6 ++-- drivers/ide/ide-cd.c | 14 ++++---- drivers/ide/ide-disk_ioctl.c | 7 ++-- drivers/ide/ide-floppy_ioctl.c | 7 ++-- drivers/ide/ide-gd.c | 10 +++--- drivers/ide/ide-tape.c | 19 ++++++------ drivers/input/misc/hp_sdc_rtc.c | 7 ++-- drivers/macintosh/adb.c | 10 +++--- drivers/macintosh/smu.c | 6 ++-- drivers/macintosh/via-pmu.c | 11 ++++--- drivers/md/dm.c | 10 +++--- drivers/md/md.c | 13 ++++---- drivers/memstick/core/mspro_block.c | 11 ++++--- drivers/message/fusion/mptctl.c | 15 +++++---- drivers/message/i2o/i2o_block.c | 15 +++++---- drivers/message/i2o/i2o_config.c | 23 +++++++------- drivers/misc/phantom.c | 11 ++++--- drivers/mmc/card/block.c | 10 +++--- drivers/mtd/mtd_blkdevs.c | 14 ++++---- drivers/mtd/mtdchar.c | 15 +++++---- drivers/pci/hotplug/cpqphp_sysfs.c | 13 ++++---- drivers/rtc/rtc-m41t80.c | 13 ++++---- drivers/s390/char/tape_block.c | 13 ++++---- drivers/sbus/char/jsflash.c | 24 ++++++++------- drivers/scsi/3w-9xxx.c | 7 ++-- drivers/scsi/3w-sas.c | 7 ++-- drivers/scsi/3w-xxxx.c | 9 ++--- drivers/scsi/aacraid/linit.c | 15 +++++---- drivers/scsi/ch.c | 8 ++-- drivers/scsi/dpt_i2o.c | 18 ++++++------ drivers/scsi/gdth.c | 11 ++++--- drivers/scsi/megaraid.c | 8 ++-- drivers/scsi/megaraid/megaraid_mm.c | 8 ++-- drivers/scsi/megaraid/megaraid_sas.c | 2 - drivers/scsi/mpt2sas/mpt2sas_ctl.c | 11 ++++--- drivers/scsi/osst.c | 15 +++++---- drivers/scsi/scsi_tgt_if.c | 2 - drivers/scsi/sg.c | 11 ++++--- drivers/scsi/sr.c | 14 ++++---- drivers/scsi/st.c | 12 ++++---- drivers/staging/hv/blkvsc_drv.c | 11 ++++--- drivers/staging/spectra/ffsport.c | 7 ++-- drivers/telephony/ixj.c | 7 ++-- drivers/watchdog/cpwd.c | 15 +++++---- fs/hfsplus/ioctl.c | 11 ++++--- sound/oss/au1550_ac97.c | 30 +++++++++--------- sound/oss/dmasound/dmasound_core.c | 41 +++++++++++++------------ sound/oss/msnd_pinnacle.c | 15 +++++---- sound/oss/sh_dac_audio.c | 13 ++++---- sound/oss/soundcard.c | 41 +++++++++++++------------ sound/oss/swarm_cs4297a.c | 20 ++++++------ sound/oss/vwsnd.c | 30 +++++++++--------- 109 files changed, 718 insertions(+), 657 deletions(-)
Arnd Bergmann
maintainerPATCH 1/7 scsi: autoconvert trivial BKL users to private mutex
All these files use the big kernel lock in a trivial way to serialize their private file operations, typically resulting from an earlier semi-automatic pushdown from VFS.
None of these drivers appears to want to lock against other code, and they all use the BKL as the top-level lock in their file operations, meaning that there is no lock-order inversion problem.
Consequently, we can remove the BKL completely, replacing it with a per-file mutex in every case. Using a scripted approach means we can avoid typos.
file=$1
name=$2
if grep -q lock_kernel ${file} ; then
if grep -q 'include.*linux.mutex.h' ${file} ; then
sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
else
sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
fi
sed -i ${file} \
-e "/^#include.*linux.mutex.h/,$ {
1,/^\(static\|int\|long\)/ {
/^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);} }" \
-e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
-e '/[ ]*cycle_kernel_lock();/d'
else
sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \
-e '/cycle_kernel_lock()/d'fi
--- drivers/message/fusion/mptctl.c | 15 ++++++++------- drivers/message/i2o/i2o_config.c | 23 ++++++++++++----------- drivers/scsi/3w-9xxx.c | 7 +++---- drivers/scsi/3w-sas.c | 7 +++---- drivers/scsi/3w-xxxx.c | 9 ++++----- drivers/scsi/aacraid/linit.c | 15 ++++++++------- drivers/scsi/ch.c | 8 ++++---- drivers/scsi/dpt_i2o.c | 18 +++++++++--------- drivers/scsi/gdth.c | 11 ++++++----- drivers/scsi/megaraid.c | 8 ++++---- drivers/scsi/megaraid/megaraid_mm.c | 8 ++++---- drivers/scsi/megaraid/megaraid_sas.c | 2 -- drivers/scsi/mpt2sas/mpt2sas_ctl.c | 11 ++++++----- drivers/scsi/osst.c | 15 ++++++++------- drivers/scsi/scsi_tgt_if.c | 2 -- drivers/scsi/sg.c | 11 ++++++----- 16 files changed, 85 insertions(+), 85 deletions(-)
drivers/message/fusion/mptctl.c +8 -7
@@ -54,7 +54,7 @@#include <linux/pci.h> #include <linux/delay.h> /* for mdelay */ #include <linux/miscdevice.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/compat.h> #include <asm/io.h>
@@ -83,6 +83,7 @@ MODULE_VERSION(my_VERSION);/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ +static DEFINE_MUTEX (mpctl_mutex);static u8 mptctl_id =MPT_MAX_PROTOCOL_DRIVERS ;static u8 mptctl_taskmgmt_id =MPT_MAX_PROTOCOL_DRIVERS ;
@@ -601,12 +602,12 @@ mptctl_fasync(int fd, struct file *filep, int mode)MPT_ADAPTER *ioc;int ret; -lock_kernel (); +mutex_lock (&mpctl_mutex);list_for_each_entry (ioc, &ioc_list, list) ioc->aen_event_read_flag=0 ; ret =fasync_helper (fd, filep, mode, &async_queue); -unlock_kernel (); +mutex_unlock (&mpctl_mutex);return ret; }
@@ -698,9 +699,9 @@ static long mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { long ret; -lock_kernel (); +mutex_lock (&mpctl_mutex); ret =__mptctl_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&mpctl_mutex);return ret; }
@@ -2926,7 +2927,7 @@ compat_mpt_command(struct file *filp, unsigned int cmd,static long compat_mpctl_ioctl (struct file *f,unsigned int cmd,unsigned long arg) {long ret; -lock_kernel (); +mutex_lock (&mpctl_mutex);switch (cmd) {case MPTIOCINFO :case MPTIOCINFO1 :
@@ -2951,7 +2952,7 @@ static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long a ret = -ENOIOCTLCMD ;break ; } -unlock_kernel (); +mutex_unlock (&mpctl_mutex);return ret; }
drivers/message/i2o/i2o_config.c +12 -11
@@ -31,7 +31,7 @@*/ #include <linux/miscdevice.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/compat.h> #include <linux/slab.h>
@@ -41,6 +41,7 @@#define SG_TABLESIZE 30 +static DEFINE_MUTEX (i2o_cfg_mutex);static long i2o_cfg_ioctl (struct file *,unsigned int ,unsigned long );static spinlock_t i2o_config_lock;
@@ -741,7 +742,7 @@ static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg) {int ret; -lock_kernel (); +mutex_lock (&i2o_cfg_mutex);switch (cmd) {case I2OGETIOPS : ret =i2o_cfg_ioctl (file, cmd, arg);
@@ -753,7 +754,7 @@ static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd, ret = -ENOIOCTLCMD ;break ; } -unlock_kernel (); +mutex_unlock (&i2o_cfg_mutex);return ret; }
@@ -981,7 +982,7 @@ static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) {int ret; -lock_kernel (); +mutex_lock (&i2o_cfg_mutex);switch (cmd) {case I2OGETIOPS : ret =i2o_cfg_getiops (arg);
@@ -1037,7 +1038,7 @@ static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)osm_debug ("unknown ioctl called!\n" ); ret = -EINVAL ; } -unlock_kernel (); +mutex_unlock (&i2o_cfg_mutex);return ret; }
@@ -1051,7 +1052,7 @@ static int cfg_open(struct inode *inode, struct file *file)if (!tmp)return -ENOMEM ; -lock_kernel (); +mutex_lock (&i2o_cfg_mutex); file->private_data = (void *)(i2o_cfg_info_id++); tmp->fp = file; tmp->fasync =NULL ;
@@ -1065,7 +1066,7 @@ static int cfg_open(struct inode *inode, struct file *file)spin_lock_irqsave (&i2o_config_lock, flags); open_files = tmp;spin_unlock_irqrestore (&i2o_config_lock, flags); -unlock_kernel (); +mutex_unlock (&i2o_cfg_mutex);return 0 ; }
@@ -1076,14 +1077,14 @@ static int cfg_fasync(int fd, struct file *fp, int on)struct i2o_cfg_info *p;int ret = -EBADF ; -lock_kernel (); +mutex_lock (&i2o_cfg_mutex);for (p = open_files; p; p = p->next)if (p->q_id == id)break ;if (p) ret =fasync_helper (fd, fp, on, &p->fasync); -unlock_kernel (); +mutex_unlock (&i2o_cfg_mutex);return ret; }
@@ -1093,7 +1094,7 @@ static int cfg_release(struct inode *inode, struct file *file)struct i2o_cfg_info *p, **q;unsigned long flags; -lock_kernel (); +mutex_lock (&i2o_cfg_mutex);spin_lock_irqsave (&i2o_config_lock, flags);for (q = &open_files; (p = *q) !=NULL ; q = &p->next) {if (p->q_id == id) {
@@ -1103,7 +1104,7 @@ static int cfg_release(struct inode *inode, struct file *file) } }spin_unlock_irqrestore (&i2o_config_lock, flags); -unlock_kernel (); +mutex_unlock (&i2o_cfg_mutex);return 0 ; }
drivers/scsi/3w-9xxx.c +3 -4
@@ -92,7 +92,6 @@#include <linux/pci.h> #include <linux/time.h> #include <linux/mutex.h> -#include <linux/smp_lock.h> #include <linux/slab.h> #include <asm/io.h> #include <asm/irq.h>
@@ -105,6 +104,7 @@/* Globals */ #define TW_DRIVER_VERSION "2.26.02.014" +static DEFINE_MUTEX (twa_chrdev_mutex);static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT ];static unsigned int twa_device_extension_count;static int twa_major =-1 ;
@@ -658,7 +658,7 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned longint retval =TW_IOCTL_ERROR_OS_EFAULT ;void __user *argp = (void __user *)arg; -lock_kernel (); +mutex_lock (&twa_chrdev_mutex);/* Only let one of these through at a time */ if (mutex_lock_interruptible (&tw_dev->ioctl_lock)) {
@@ -879,7 +879,7 @@ out3: out2:mutex_unlock (&tw_dev->ioctl_lock); out: -unlock_kernel (); +mutex_unlock (&twa_chrdev_mutex);return retval; }/* End twa_chrdev_ioctl() */
@@ -890,7 +890,6 @@ static int twa_chrdev_open(struct inode *inode, struct file *file)unsigned int minor_number;int retval =TW_IOCTL_ERROR_OS_ENODEV ; -cycle_kernel_lock (); minor_number =iminor (inode);if (minor_number >= twa_device_extension_count) goto out;
drivers/scsi/3w-sas.c +3 -4
@@ -64,7 +64,6 @@#include <linux/pci.h> #include <linux/time.h> #include <linux/mutex.h> -#include <linux/smp_lock.h> #include <linux/slab.h> #include <asm/io.h> #include <asm/irq.h>
@@ -77,6 +76,7 @@/* Globals */ #define TW_DRIVER_VERSION "3.26.02.000" +static DEFINE_MUTEX (twl_chrdev_mutex);static TW_Device_Extension *twl_device_extension_list[TW_MAX_SLOT ];static unsigned int twl_device_extension_count;static int twl_major =-1 ;
@@ -764,7 +764,7 @@ static long twl_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned longint retval = -EFAULT ;void __user *argp = (void __user *)arg; -lock_kernel (); +mutex_lock (&twl_chrdev_mutex);/* Only let one of these through at a time */ if (mutex_lock_interruptible (&tw_dev->ioctl_lock)) {
@@ -861,7 +861,7 @@ out3: out2:mutex_unlock (&tw_dev->ioctl_lock); out: -unlock_kernel (); +mutex_unlock (&twl_chrdev_mutex);return retval; }/* End twl_chrdev_ioctl() */
@@ -876,7 +876,6 @@ static int twl_chrdev_open(struct inode *inode, struct file *file) goto out; } -cycle_kernel_lock (); minor_number =iminor (inode);if (minor_number >= twl_device_extension_count) goto out;
drivers/scsi/3w-xxxx.c +4 -5
@@ -199,7 +199,6 @@#include <linux/module.h> #include <linux/reboot.h> -#include <linux/smp_lock.h> #include <linux/spinlock.h> #include <linux/interrupt.h> #include <linux/moduleparam.h>
@@ -221,6 +220,7 @@/* Globals */ #define TW_DRIVER_VERSION "1.26.02.003" +static DEFINE_MUTEX (tw_mutex);static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT ];static int tw_device_extension_count =0 ;static int twe_major =-1 ;
@@ -900,10 +900,10 @@ static long tw_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long adprintk (KERN_WARNING "3w-xxxx: tw_chrdev_ioctl()\n" ); -lock_kernel (); +mutex_lock (&tw_mutex);/* Only let one of these through at a time */ if (mutex_lock_interruptible (&tw_dev->ioctl_lock)) { -unlock_kernel (); +mutex_unlock (&tw_mutex);return -EINTR ; }
@@ -1034,7 +1034,7 @@ out2:dma_free_coherent (&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof (TW_New_Ioctl) -1 , cpu_addr, dma_handle); out:mutex_unlock (&tw_dev->ioctl_lock); -unlock_kernel (); +mutex_unlock (&tw_mutex);return retval; }/* End tw_chrdev_ioctl() */
@@ -1044,7 +1044,6 @@ static int tw_chrdev_open(struct inode *inode, struct file *file) {unsigned int minor_number; -cycle_kernel_lock ();dprintk (KERN_WARNING "3w-xxxx: tw_ioctl_open()\n" ); minor_number =iminor (inode);
drivers/scsi/aacraid/linit.c +8 -7
@@ -38,7 +38,7 @@#include <linux/moduleparam.h> #include <linux/pci.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/spinlock.h> #include <linux/syscalls.h> #include <linux/delay.h>
@@ -76,6 +76,7 @@ MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, "MODULE_LICENSE ("GPL" );MODULE_VERSION (AAC_DRIVER_FULL_VERSION ); +static DEFINE_MUTEX (aac_mutex);static LIST_HEAD (aac_devices);static int aac_cfg_major =-1 ;char aac_driver_version[] =AAC_DRIVER_FULL_VERSION ;
@@ -678,7 +679,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)unsigned minor_number =iminor (inode);int err = -ENODEV ; -lock_kernel ();/* BKL pushdown: nothing else protects this list */ +mutex_lock (&aac_mutex);/* BKL pushdown: nothing else protects this list */ list_for_each_entry (aac, &aac_devices, entry) {if (aac->id == minor_number) { file->private_data = aac;
@@ -686,7 +687,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)break ; } } -unlock_kernel (); +mutex_unlock (&aac_mutex);return err; }
@@ -711,9 +712,9 @@ static long aac_cfg_ioctl(struct file *file,int ret;if (!capable (CAP_SYS_RAWIO ))return -EPERM ; -lock_kernel (); +mutex_lock (&aac_mutex); ret =aac_do_ioctl (file->private_data, cmd, (void __user *)arg); -unlock_kernel (); +mutex_unlock (&aac_mutex);return ret; }
@@ -722,7 +723,7 @@ static long aac_cfg_ioctl(struct file *file,static long aac_compat_do_ioctl (struct aac_dev *dev,unsigned cmd,unsigned long arg) {long ret; -lock_kernel (); +mutex_lock (&aac_mutex);switch (cmd) {case FSACTL_MINIPORT_REV_CHECK :case FSACTL_SENDFIB :
@@ -756,7 +757,7 @@ static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long ret = -ENOIOCTLCMD ;break ; } -unlock_kernel (); +mutex_unlock (&aac_mutex);return ret; }
drivers/scsi/ch.c +4 -4
@@ -22,7 +22,6 @@#include <linux/chio.h> /* here are all the ioctls */ #include <linux/mutex.h> #include <linux/idr.h> -#include <linux/smp_lock.h> #include <linux/slab.h> #include <scsi/scsi.h>
@@ -44,6 +43,7 @@ MODULE_LICENSE("GPL");MODULE_ALIAS_CHARDEV_MAJOR (SCSI_CHANGER_MAJOR );MODULE_ALIAS_SCSI_DEVICE (TYPE_MEDIUM_CHANGER ); +static DEFINE_MUTEX (ch_mutex);static int init =1 ;module_param (init, int,0444 ); MODULE_PARM_DESC(init, \
@@ -581,19 +581,19 @@ ch_open(struct inode *inode, struct file *file)scsi_changer *ch;int minor =iminor (inode); -lock_kernel (); +mutex_lock (&ch_mutex);spin_lock (&ch_index_lock); ch =idr_find (&ch_index_idr, minor);if (NULL == ch ||scsi_device_get (ch->device)) {spin_unlock (&ch_index_lock); -unlock_kernel (); +mutex_unlock (&ch_mutex);return -ENXIO ; }spin_unlock (&ch_index_lock); file->private_data = ch; -unlock_kernel (); +mutex_unlock (&ch_mutex);return 0 ; }
drivers/scsi/dpt_i2o.c +9 -9
@@ -49,7 +49,6 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");#include <linux/kernel.h> /* for printk */ #include <linux/sched.h> #include <linux/reboot.h> -#include <linux/smp_lock.h> #include <linux/spinlock.h> #include <linux/dma-mapping.h>
@@ -76,6 +75,7 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");* Needed for our management apps *============================================================================ */ +static DEFINE_MUTEX (adpt_mutex);static dpt_sig_S DPTI_sig = { {'d' ,'P' ,'t' ,'S' ,'i' ,'G' },SIG_VERSION , #ifdef __i386__
@@ -1732,12 +1732,12 @@ static int adpt_open(struct inode *inode, struct file *file)int minor;adpt_hba * pHba; -lock_kernel (); +mutex_lock (&adpt_mutex);//TODO check for root access // minor =iminor (inode);if (minor >= hba_count) { -unlock_kernel (); +mutex_unlock (&adpt_mutex);return -ENXIO ; }mutex_lock (&adpt_configuration_lock);
@@ -1748,7 +1748,7 @@ static int adpt_open(struct inode *inode, struct file *file) }if (pHba ==NULL ) {mutex_unlock (&adpt_configuration_lock); -unlock_kernel (); +mutex_unlock (&adpt_mutex);return -ENXIO ; }
@@ -1759,7 +1759,7 @@ static int adpt_open(struct inode *inode, struct file *file) pHba->in_use =1 ;mutex_unlock (&adpt_configuration_lock); -unlock_kernel (); +mutex_unlock (&adpt_mutex);return 0 ; }
@@ -2160,9 +2160,9 @@ static long adpt_unlocked_ioctl(struct file *file, uint cmd, ulong arg) inode = file->f_dentry->d_inode; -lock_kernel (); +mutex_lock (&adpt_mutex); ret =adpt_ioctl (inode, file, cmd, arg); -unlock_kernel (); +mutex_unlock (&adpt_mutex);return ret; }
@@ -2176,7 +2176,7 @@ static long compat_adpt_ioctl(struct file *file, inode = file->f_dentry->d_inode; -lock_kernel (); +mutex_lock (&adpt_mutex);switch (cmd) {case DPT_SIGNATURE :
@@ -2194,7 +2194,7 @@ static long compat_adpt_ioctl(struct file *file, ret = -ENOIOCTLCMD ; } -unlock_kernel (); +mutex_unlock (&adpt_mutex);return ret; }
drivers/scsi/gdth.c +6 -5
@@ -120,7 +120,7 @@#include <linux/timer.h> #include <linux/dma-mapping.h> #include <linux/list.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/slab.h> #ifdef GDTH_RTC
@@ -140,6 +140,7 @@#include <scsi/scsi_host.h> #include "gdth.h" +static DEFINE_MUTEX (gdth_mutex);static void gdth_delay (int milliseconds);static void gdth_eval_mapping (u32 size,u32 *cyls,int *heads,int *secs);static irqreturn_t gdth_interrupt (int irq,void *dev_id);
@@ -4042,12 +4043,12 @@ static int gdth_open(struct inode *inode, struct file *filep) {gdth_ha_str *ha; -lock_kernel (); +mutex_lock (&gdth_mutex);list_for_each_entry (ha, &gdth_instances, list) {if (!ha->sdev) ha->sdev =scsi_get_host_dev (ha->shost); } -unlock_kernel (); +mutex_unlock (&gdth_mutex);TRACE (("gdth_open()\n" ));return 0 ;
@@ -4615,9 +4616,9 @@ static long gdth_unlocked_ioctl(struct file *file, unsigned int cmd, {int ret; -lock_kernel (); +mutex_lock (&gdth_mutex); ret =gdth_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&gdth_mutex);return ret; }
drivers/scsi/megaraid.c +4 -4
@@ -46,7 +46,7 @@#include <linux/pci.h> #include <linux/init.h> #include <linux/dma-mapping.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/slab.h> #include <scsi/scsicam.h>
@@ -62,6 +62,7 @@ MODULE_DESCRIPTION ("LSI Logic MegaRAID legacy driver");MODULE_LICENSE ("GPL" );MODULE_VERSION (MEGARAID_MODULE_VERSION ); +static DEFINE_MUTEX (megadev_mutex);static unsigned int max_cmd_per_lun =DEF_CMD_PER_LUN ;module_param (max_cmd_per_lun, uint,0 );MODULE_PARM_DESC (max_cmd_per_lun,"Maximum number of commands which can be issued to a single LUN (default=DEF_CMD_PER_LUN=63)" );
@@ -3282,7 +3283,6 @@ mega_init_scb(adapter_t *adapter)static int megadev_open (struct inode *inode,struct file *filep) { -cycle_kernel_lock ();/* * Only allow superuser to access private ioctl interface */
@@ -3701,9 +3701,9 @@ megadev_unlocked_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) {int ret; -lock_kernel (); +mutex_lock (&megadev_mutex); ret =megadev_ioctl (filep, cmd, arg); -unlock_kernel (); +mutex_unlock (&megadev_mutex);return ret; }
drivers/scsi/megaraid/megaraid_mm.c +4 -4
@@ -16,11 +16,12 @@*/ #include <linux/sched.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include "megaraid_mm.h" // Entry points for char node driver +static DEFINE_MUTEX (mraid_mm_mutex);static int mraid_mm_open (struct inode *,struct file *);static long mraid_mm_unlocked_ioctl (struct file *,uint ,unsigned long );
@@ -98,7 +99,6 @@ mraid_mm_open(struct inode *inode, struct file *filep)*/ if (!capable (CAP_SYS_ADMIN ))return (-EACCES ); -cycle_kernel_lock ();return 0 ; }
@@ -224,9 +224,9 @@ mraid_mm_unlocked_ioctl(struct file *filep, unsigned int cmd,int err;/* inconsistant: mraid_mm_compat_ioctl doesn't take the BKL */ -lock_kernel (); +mutex_lock (&mraid_mm_mutex); err =mraid_mm_ioctl (filep, cmd, arg); -unlock_kernel (); +mutex_unlock (&mraid_mm_mutex);return err; }
drivers/scsi/megaraid/megaraid_sas.c +0 -2
@@ -33,7 +33,6 @@#include <linux/spinlock.h> #include <linux/interrupt.h> #include <linux/delay.h> -#include <linux/smp_lock.h> #include <linux/uio.h> #include <linux/slab.h> #include <asm/uaccess.h>
@@ -3557,7 +3556,6 @@ static void megasas_shutdown(struct pci_dev *pdev)*/ static int megasas_mgmt_open (struct inode *inode,struct file *filep) { -cycle_kernel_lock ();/* * Allow only those users with admin rights */
drivers/scsi/mpt2sas/mpt2sas_ctl.c +6 -5
@@ -51,7 +51,7 @@#include <linux/types.h> #include <linux/pci.h> #include <linux/delay.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/compat.h> #include <linux/poll.h>
@@ -61,6 +61,7 @@#include "mpt2sas_base.h" #include "mpt2sas_ctl.h" +static DEFINE_MUTEX (_ctl_mutex);static struct fasync_struct *async_queue;static DECLARE_WAIT_QUEUE_HEAD (ctl_poll_wait);
@@ -2238,9 +2239,9 @@ _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {long ret; -lock_kernel (); +mutex_lock (&_ctl_mutex); ret =_ctl_ioctl_main (file, cmd, (void __user *)arg); -unlock_kernel (); +mutex_unlock (&_ctl_mutex);return ret; }
@@ -2309,12 +2310,12 @@ _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg) {long ret; -lock_kernel (); +mutex_lock (&_ctl_mutex);if (cmd ==MPT2COMMAND32 ) ret =_ctl_compat_mpt_command (file, cmd, arg);else ret =_ctl_ioctl_main (file, cmd, (void __user *)arg); -unlock_kernel (); +mutex_unlock (&_ctl_mutex);return ret; }#endif
drivers/scsi/osst.c +8 -7
@@ -51,7 +51,7 @@ static const char * osst_version = "0.99.4";#include <linux/moduleparam.h> #include <linux/delay.h> #include <linux/jiffies.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/uaccess.h> #include <asm/dma.h> #include <asm/system.h>
@@ -80,6 +80,7 @@ static const char * osst_version = "0.99.4";#include "osst_options.h" #include "osst_detect.h" +static DEFINE_MUTEX (osst_int_mutex);static int max_dev =0 ;static int write_threshold_kbs =0 ;static int max_sg_segs =0 ;
@@ -4807,9 +4808,9 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp) {int ret; -lock_kernel (); +mutex_lock (&osst_int_mutex); ret =__os_scsi_tape_open (inode, filp); -unlock_kernel (); +mutex_unlock (&osst_int_mutex);return ret; }
@@ -4943,9 +4944,9 @@ static long osst_ioctl(struct file * file,char * name =tape_name (STp);void __user * p = (void __user *)arg; -lock_kernel (); +mutex_lock (&osst_int_mutex);if (mutex_lock_interruptible (&STp->lock)) { -unlock_kernel (); +mutex_unlock (&osst_int_mutex);return -ERESTARTSYS ; }
@@ -5260,14 +5261,14 @@ static long osst_ioctl(struct file * file,mutex_unlock (&STp->lock); retval =scsi_ioctl (STp->device, cmd_in, p); -unlock_kernel (); +mutex_unlock (&osst_int_mutex);return retval; out:if (SRpnt)osst_release_request (SRpnt);mutex_unlock (&STp->lock); -unlock_kernel (); +mutex_unlock (&osst_int_mutex);return retval; }
drivers/scsi/scsi_tgt_if.c +0 -2
@@ -22,7 +22,6 @@#include <linux/miscdevice.h> #include <linux/gfp.h> #include <linux/file.h> -#include <linux/smp_lock.h> #include <net/tcp.h> #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h>
@@ -323,7 +322,6 @@ static int tgt_open(struct inode *inode, struct file *file) { tx_ring.tr_idx = rx_ring.tr_idx =0 ; -cycle_kernel_lock ();return 0 ; }
drivers/scsi/sg.c +6 -5
@@ -49,7 +49,7 @@ static int sg_version_num = 30534; /* 2 digits for each component */#include <linux/blkdev.h> #include <linux/delay.h> #include <linux/blktrace_api.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include "scsi.h" #include <scsi/scsi_dbg.h>
@@ -62,6 +62,7 @@ static int sg_version_num = 30534; /* 2 digits for each component */#ifdef CONFIG_SCSI_PROC_FS #include <linux/proc_fs.h> +static DEFINE_MUTEX (sg_mutex);static char *sg_version_date ="20061027" ;static int sg_proc_init (void );
@@ -229,7 +230,7 @@ sg_open(struct inode *inode, struct file *filp)int res;int retval; -lock_kernel (); +mutex_lock (&sg_mutex);nonseekable_open (inode, filp);SCSI_LOG_TIMEOUT (3 ,printk ("sg_open: dev=%d, flags=0x%x\n" , dev, flags)); sdp =sg_get_dev (dev);
@@ -314,7 +315,7 @@ sdp_put: sg_put:if (sdp)sg_put_dev (sdp); -unlock_kernel (); +mutex_unlock (&sg_mutex);return retval; }
@@ -1092,9 +1093,9 @@ sg_unlocked_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) {int ret; -lock_kernel (); +mutex_lock (&sg_mutex); ret =sg_ioctl (filp, cmd_in, arg); -unlock_kernel (); +mutex_unlock (&sg_mutex);return ret; }
Signature · 1 line
1.7.1
Arnd Bergmann
maintainerPATCH 2/7 mtd: autoconvert trivial BKL users to private mutex
In reply to Arnd BergmannAll these files use the big kernel lock in a trivial way to serialize their private file operations, typically resulting from an earlier semi-automatic pushdown from VFS.
None of these drivers appears to want to lock against other code, and they all use the BKL as the top-level lock in their file operations, meaning that there is no lock-order inversion problem.
Consequently, we can remove the BKL completely, replacing it with a per-file mutex in every case. Using a scripted approach means we can avoid typos.
file=$1
name=$2
if grep -q lock_kernel ${file} ; then
if grep -q 'include.*linux.mutex.h' ${file} ; then
sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
else
sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
fi
sed -i ${file} \
-e "/^#include.*linux.mutex.h/,$ {
1,/^\(static\|int\|long\)/ {
/^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);} }" \
-e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
-e '/[ ]*cycle_kernel_lock();/d'
else
sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \
-e '/cycle_kernel_lock()/d'fi
--- drivers/mtd/mtdchar.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-)
drivers/mtd/mtdchar.c +8 -7
@@ -26,7 +26,7 @@#include <linux/module.h> #include <linux/slab.h> #include <linux/sched.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/backing-dev.h> #include <linux/compat.h> #include <linux/mount.h>
@@ -37,6 +37,7 @@#include <asm/uaccess.h> #define MTD_INODE_FS_MAGIC 0x11307854 +static DEFINE_MUTEX (mtd_mutex);static struct vfsmount *mtd_inode_mnt__read_mostly ;/*
@@ -90,7 +91,7 @@ static int mtd_open(struct inode *inode, struct file *file)if ((file->f_mode &FMODE_WRITE ) && (minor &1 ))return -EACCES ; -lock_kernel (); +mutex_lock (&mtd_mutex); mtd =get_mtd_device (NULL , devnum);if (IS_ERR (mtd)) {
@@ -138,7 +139,7 @@ static int mtd_open(struct inode *inode, struct file *file) file->private_data = mfi; out: -unlock_kernel (); +mutex_unlock (&mtd_mutex);return ret; }/* mtd_open */
@@ -866,9 +867,9 @@ static long mtd_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) {int ret; -lock_kernel (); +mutex_lock (&mtd_mutex); ret =mtd_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&mtd_mutex);return ret; }
@@ -892,7 +893,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd,void __user *argp =compat_ptr (arg);int ret =0 ; -lock_kernel (); +mutex_lock (&mtd_mutex);switch (cmd) {case MEMWRITEOOB32 :
@@ -927,7 +928,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd, ret =mtd_ioctl (file, cmd, (unsigned long )argp); } -unlock_kernel (); +mutex_unlock (&mtd_mutex);return ret; }
Signature · 1 line
1.7.1
Re: [PATCH 2/7] mtd: autoconvert trivial BKL users to private mutex
Quoted 10 lines · Arnd Bergmann
All these files use the big kernel lock in a trivial way to serialize their private file operations, typically resulting from an earlier semi-automatic pushdown from VFS.
None of these drivers appears to want to lock against other code, and they all use the BKL as the top-level lock in their file operations, meaning that there is no lock-order inversion problem.
Quoted 5 lines
Consequently, we can remove the BKL completely, replacing it with a per-file mutex in every case. Using a scripted approach means we can avoid typos.
Looks good, are you going to merge them all yourself or you want this to go via the mtd tree?
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Arnd Bergmann
maintainerRe: [PATCH 2/7] mtd: autoconvert trivial BKL users to private mutex
Quoted 8 lines · Artem Bityutskiy
Quoted 5 lines
Consequently, we can remove the BKL completely,
replacing it with a per-file mutex in every case.
Using a scripted approach means we can avoid
typos.Looks good, are you going to merge them all yourself or you want this to go via the mtd tree?
Either way is fine for me. If it goes into the mtd tree, I'll drop it from my series.
Arnd
Arnd Bergmann
maintainerPATCH 3/7 mac: autoconvert trivial BKL users to private mutex
In reply to Arnd BergmannAll these files use the big kernel lock in a trivial way to serialize their private file operations, typically resulting from an earlier semi-automatic pushdown from VFS.
None of these drivers appears to want to lock against other code, and they all use the BKL as the top-level lock in their file operations, meaning that there is no lock-order inversion problem.
Consequently, we can remove the BKL completely, replacing it with a per-file mutex in every case. Using a scripted approach means we can avoid typos.
file=$1
name=$2
if grep -q lock_kernel ${file} ; then
if grep -q 'include.*linux.mutex.h' ${file} ; then
sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
else
sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
fi
sed -i ${file} \
-e "/^#include.*linux.mutex.h/,$ {
1,/^\(static\|int\|long\)/ {
/^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);} }" \
-e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
-e '/[ ]*cycle_kernel_lock();/d'
else
sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \
-e '/cycle_kernel_lock()/d'fi
--- drivers/macintosh/adb.c | 10 +++++----- drivers/macintosh/smu.c | 6 +++--- drivers/macintosh/via-pmu.c | 11 ++++++----- 3 files changed, 14 insertions(+), 13 deletions(-)
drivers/macintosh/adb.c +5 -5
@@ -24,7 +24,6 @@#include <linux/fs.h> #include <linux/mm.h> #include <linux/sched.h> -#include <linux/smp_lock.h> #include <linux/adb.h> #include <linux/cuda.h> #include <linux/pmu.h>
@@ -55,6 +54,7 @@ extern struct adb_driver adb_iop_driver;extern struct adb_driver via_pmu_driver;extern struct adb_driver macio_adb_driver; +static DEFINE_MUTEX (adb_mutex);static struct adb_driver *adb_driver_list[] = { #ifdef CONFIG_ADB_MACII &via_macii_driver,
@@ -647,7 +647,7 @@ static int adb_open(struct inode *inode, struct file *file)struct adbdev_state *state;int ret =0 ; -lock_kernel (); +mutex_lock (&adb_mutex);if (iminor (inode) >0 || adb_controller ==NULL ) { ret = -ENXIO ; goto out;
@@ -665,7 +665,7 @@ static int adb_open(struct inode *inode, struct file *file) state->inuse =1 ; out: -unlock_kernel (); +mutex_unlock (&adb_mutex);return ret; }
@@ -674,7 +674,7 @@ static int adb_release(struct inode *inode, struct file *file)struct adbdev_state *state = file->private_data;unsigned long flags; -lock_kernel (); +mutex_lock (&adb_mutex);if (state) { file->private_data =NULL ;spin_lock_irqsave (&state->lock, flags);
@@ -687,7 +687,7 @@ static int adb_release(struct inode *inode, struct file *file)spin_unlock_irqrestore (&state->lock, flags); } } -unlock_kernel (); +mutex_unlock (&adb_mutex);return 0 ; }
drivers/macintosh/smu.c +3 -3
@@ -19,7 +19,6 @@* the userland interface */ -#include <linux/smp_lock.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/device.h>
@@ -97,6 +96,7 @@ struct smu_device {* I don't think there will ever be more than one SMU, so * for now, just hard code that */ +static DEFINE_MUTEX (smu_mutex);static struct smu_device *smu;static DEFINE_MUTEX (smu_part_access);static int smu_irq_inited;
@@ -1095,12 +1095,12 @@ static int smu_open(struct inode *inode, struct file *file) pp->mode = smu_file_commands;init_waitqueue_head (&pp->wait); -lock_kernel (); +mutex_lock (&smu_mutex);spin_lock_irqsave (&smu_clist_lock, flags);list_add (&pp->list, &smu_clist);spin_unlock_irqrestore (&smu_clist_lock, flags); file->private_data = pp; -unlock_kernel (); +mutex_unlock (&smu_mutex);return 0 ; }
drivers/macintosh/via-pmu.c +6 -5
@@ -18,7 +18,7 @@* */ #include <stdarg.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h>
@@ -73,6 +73,7 @@/* How many iterations between battery polls */ #define BATTERY_POLLING_COUNT 2 +static DEFINE_MUTEX (pmu_info_proc_mutex);static volatile unsigned char __iomem *via;/* VIA registers - spaced 0x200 bytes apart */
@@ -2078,7 +2079,7 @@ pmu_open(struct inode *inode, struct file *file) pp->rb_get = pp->rb_put =0 ;spin_lock_init (&pp->lock);init_waitqueue_head (&pp->wait); -lock_kernel (); +mutex_lock (&pmu_info_proc_mutex);spin_lock_irqsave (&all_pvt_lock, flags);#if defined(CONFIG_INPUT_ADBHID ) && defined(CONFIG_PMAC_BACKLIGHT ) pp->backlight_locker =0 ;
@@ -2086,7 +2087,7 @@ pmu_open(struct inode *inode, struct file *file)list_add (&pp->list, &all_pmu_pvt);spin_unlock_irqrestore (&all_pvt_lock, flags); file->private_data = pp; -unlock_kernel (); +mutex_unlock (&pmu_info_proc_mutex);return 0 ; }
@@ -2343,9 +2344,9 @@ static long pmu_unlocked_ioctl(struct file *filp, {int ret; -lock_kernel (); +mutex_lock (&pmu_info_proc_mutex); ret =pmu_ioctl (filp, cmd, arg); -unlock_kernel (); +mutex_unlock (&pmu_info_proc_mutex);return ret; }
Signature · 1 line
1.7.1
Arnd Bergmann
maintainerPATCH 4/7 ipmi: autoconvert trivial BKL users to private mutex
In reply to Arnd BergmannAll these files use the big kernel lock in a trivial way to serialize their private file operations, typically resulting from an earlier semi-automatic pushdown from VFS.
None of these drivers appears to want to lock against other code, and they all use the BKL as the top-level lock in their file operations, meaning that there is no lock-order inversion problem.
Consequently, we can remove the BKL completely, replacing it with a per-file mutex in every case. Using a scripted approach means we can avoid typos.
file=$1
name=$2
if grep -q lock_kernel ${file} ; then
if grep -q 'include.*linux.mutex.h' ${file} ; then
sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
else
sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
fi
sed -i ${file} \
-e "/^#include.*linux.mutex.h/,$ {
1,/^\(static\|int\|long\)/ {
/^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);} }" \
-e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
-e '/[ ]*cycle_kernel_lock();/d'
else
sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \
-e '/cycle_kernel_lock()/d'fi
--- drivers/char/ipmi/ipmi_devintf.c | 14 +++++++------- drivers/char/ipmi/ipmi_watchdog.c | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-)
drivers/char/ipmi/ipmi_devintf.c +7 -7
@@ -44,7 +44,6 @@#include <linux/init.h> #include <linux/device.h> #include <linux/compat.h> -#include <linux/smp_lock.h> struct ipmi_file_private {
@@ -59,6 +58,7 @@ struct ipmi_file_privateunsigned int default_retry_time_ms; }; +static DEFINE_MUTEX (ipmi_mutex);static void file_receive_handler (struct ipmi_recv_msg *msg,void *handler_data) {
@@ -102,9 +102,9 @@ static int ipmi_fasync(int fd, struct file *file, int on)struct ipmi_file_private *priv = file->private_data;int result; -lock_kernel ();/* could race against open() otherwise */ +mutex_lock (&ipmi_mutex);/* could race against open() otherwise */ result =fasync_helper (fd, file, on, &priv->fasync_queue); -unlock_kernel (); +mutex_unlock (&ipmi_mutex);return (result); }
@@ -125,7 +125,7 @@ static int ipmi_open(struct inode *inode, struct file *file)if (!priv)return -ENOMEM ; -lock_kernel (); +mutex_lock (&ipmi_mutex); priv->file = file; rv = ipmi_create_user(if_num,
@@ -150,7 +150,7 @@ static int ipmi_open(struct inode *inode, struct file *file) priv->default_retry_time_ms =0 ; out: -unlock_kernel (); +mutex_unlock (&ipmi_mutex);return rv; }
@@ -639,9 +639,9 @@ static long ipmi_unlocked_ioctl(struct file *file, {int ret; -lock_kernel (); +mutex_lock (&ipmi_mutex); ret =ipmi_ioctl (file, cmd, data); -unlock_kernel (); +mutex_unlock (&ipmi_mutex);return ret; }
drivers/char/ipmi/ipmi_watchdog.c +4 -4
@@ -35,7 +35,7 @@#include <linux/moduleparam.h> #include <linux/ipmi.h> #include <linux/ipmi_smi.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/watchdog.h> #include <linux/miscdevice.h> #include <linux/init.h>
@@ -149,6 +149,7 @@#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int)#endif +static DEFINE_MUTEX (ipmi_watchdog_mutex);static int nowayout =WATCHDOG_NOWAYOUT ;static ipmi_user_t watchdog_user;
@@ -748,9 +749,9 @@ static long ipmi_unlocked_ioctl(struct file *file, {int ret; -lock_kernel (); +mutex_lock (&ipmi_watchdog_mutex); ret =ipmi_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&ipmi_watchdog_mutex);return ret; }
@@ -844,7 +845,6 @@ static int ipmi_open(struct inode *ino, struct file *filep)if (test_and_set_bit (0 , &ipmi_wdog_open))return -EBUSY ; -cycle_kernel_lock ();/* * Don't start the timer now, let it start on the
Signature · 1 line
1.7.1
Re: [PATCH 4/7] ipmi: autoconvert trivial BKL users to private mutex
This patch is good with me.
Quoted 148 lines · Arnd Bergmann
All these files use the big kernel lock in a trivial way to serialize their private file operations, typically resulting from an earlier semi-automatic pushdown from VFS.
None of these drivers appears to want to lock against other code, and they all use the BKL as the top-level lock in their file operations, meaning that there is no lock-order inversion problem.
Consequently, we can remove the BKL completely, replacing it with a per-file mutex in every case. Using a scripted approach means we can avoid typos.
file=$1
name=$2
if grep -qlock_kernel${file} ; thenif grep -q 'include.*linux.mutex.h' ${file} ; then sed -i '/include.*<linux\/smp_lock.h>/d' ${file} else sed -i 's/include.*<linux\/smp_lock.h>.*$/include<linux\/mutex.h>/g' ${file} fi sed -i ${file} \ -e "/^#include.*linux.mutex.h/,$ { 1,/^\(static\|int\|long\)/ { /^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);} }" \ -e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \ -e '/[ ]*cycle_kernel_lock();/d' else sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \ -e '/cycle_kernel_lock()/d'fi
Signed-off-by Arnd Bergmann<[email protected]>Cc Corey Minyard<[email protected]>--- drivers/char/ipmi/ipmi_devintf.c | 14 +++++++------- drivers/char/ipmi/ipmi_watchdog.c | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-)drivers/char/ipmi/ipmi_devintf.c +7
-7@@ -44,7 +44,6 @@#include <linux/init.h> #include <linux/device.h> #include <linux/compat.h> -#include <linux/smp_lock.h> struct ipmi_file_private {@@ -59,6 +58,7 @@ struct ipmi_file_privateunsigned int default_retry_time_ms; }; +static DEFINE_MUTEX (ipmi_mutex);static void file_receive_handler (struct ipmi_recv_msg *msg,void *handler_data) {@@ -102,9 +102,9 @@ static int ipmi_fasync(int fd, struct file *file, int on)struct ipmi_file_private *priv = file->private_data;int result; -lock_kernel ();/* could race against open() otherwise */ +mutex_lock (&ipmi_mutex);/* could race against open() otherwise */ result =fasync_helper (fd, file, on,&priv->fasync_queue); -unlock_kernel (); +mutex_unlock (&ipmi_mutex);return (result); }@@ -125,7 +125,7 @@ static int ipmi_open(struct inode *inode, struct file *file)if (!priv)return -ENOMEM ; -lock_kernel (); +mutex_lock (&ipmi_mutex); priv->file = file; rv = ipmi_create_user(if_num,@@ -150,7 +150,7 @@ static int ipmi_open(struct inode *inode, struct file *file) priv->default_retry_time_ms =0 ; out: -unlock_kernel (); +mutex_unlock (&ipmi_mutex);return rv; }@@ -639,9 +639,9 @@ static long ipmi_unlocked_ioctl(struct file *file, {int ret; -lock_kernel (); +mutex_lock (&ipmi_mutex); ret =ipmi_ioctl (file, cmd, data); -unlock_kernel (); +mutex_unlock (&ipmi_mutex);return ret; }drivers/char/ipmi/ipmi_watchdog.c +4
-4@@ -35,7 +35,7 @@#include <linux/moduleparam.h> #include <linux/ipmi.h> #include <linux/ipmi_smi.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/watchdog.h> #include <linux/miscdevice.h> #include <linux/init.h> @@ -149,6 +149,7 @@#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int)#endif +static DEFINE_MUTEX (ipmi_watchdog_mutex);static int nowayout =WATCHDOG_NOWAYOUT ;static ipmi_user_t watchdog_user;@@ -748,9 +749,9 @@ static long ipmi_unlocked_ioctl(struct file *file, {int ret; -lock_kernel (); +mutex_lock (&ipmi_watchdog_mutex); ret =ipmi_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&ipmi_watchdog_mutex);return ret; }@@ -844,7 +845,6 @@ static int ipmi_open(struct inode *ino, struct file *filep)if (test_and_set_bit (0 ,&ipmi_wdog_open))return -EBUSY ; -cycle_kernel_lock ();/* * Don't start the timer now, let it start on the
Arnd Bergmann
maintainerPATCH 5/7 drivers: autoconvert trivial BKL users to private mutex
In reply to Arnd BergmannAll these files use the big kernel lock in a trivial way to serialize their private file operations, typically resulting from an earlier semi-automatic pushdown from VFS.
None of these drivers appears to want to lock against other code, and they all use the BKL as the top-level lock in their file operations, meaning that there is no lock-order inversion problem.
Consequently, we can remove the BKL completely, replacing it with a per-file mutex in every case. Using a scripted approach means we can avoid typos.
These drivers do not seem to be under active maintainance from my brief investigation. Apologies to those maintainers that I have missed.
file=$1
name=$2
if grep -q lock_kernel ${file} ; then
if grep -q 'include.*linux.mutex.h' ${file} ; then
sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
else
sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
fi
sed -i ${file} \
-e "/^#include.*linux.mutex.h/,$ {
1,/^\(static\|int\|long\)/ {
/^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);} }" \
-e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
-e '/[ ]*cycle_kernel_lock();/d'
else
sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \
-e '/cycle_kernel_lock()/d'fi
--- drivers/block/paride/pg.c | 7 ++-- drivers/block/paride/pt.c | 19 ++++++------ drivers/char/apm-emulation.c | 11 ++++--- drivers/char/applicom.c | 9 +++-- drivers/char/ds1302.c | 15 +++++---- drivers/char/ds1620.c | 8 ++-- drivers/char/dsp56k.c | 27 +++++++++-------- drivers/char/dtlk.c | 8 ++-- drivers/char/generic_nvram.c | 7 ++-- drivers/char/genrtc.c | 13 ++++---- drivers/char/i8k.c | 7 ++-- drivers/char/ip2/ip2main.c | 8 ++-- drivers/char/lp.c | 15 +++++---- drivers/char/mbcs.c | 8 ++-- drivers/char/mmtimer.c | 7 ++-- drivers/char/mwave/mwavedd.c | 44 ++++++++++++++-------------- drivers/char/nvram.c | 11 ++++--- drivers/char/nwflash.c | 12 ++++---- drivers/char/pcmcia/cm4000_cs.c | 11 ++++--- drivers/char/pcmcia/cm4040_cs.c | 7 ++-- drivers/char/ppdev.c | 8 ++-- drivers/char/rio/rio_linux.c | 7 ++-- drivers/char/snsc.c | 9 +++-- drivers/char/toshiba.c | 9 +++-- drivers/char/viotape.c | 11 ++++--- drivers/char/xilinx_hwicap/xilinx_hwicap.c | 6 ++-- drivers/hwmon/fschmd.c | 6 ++-- drivers/hwmon/w83793.c | 6 ++-- drivers/input/misc/hp_sdc_rtc.c | 7 ++-- drivers/misc/phantom.c | 11 ++++--- drivers/pci/hotplug/cpqphp_sysfs.c | 13 ++++---- drivers/rtc/rtc-m41t80.c | 13 ++++---- drivers/sbus/char/jsflash.c | 24 ++++++++------- drivers/telephony/ixj.c | 7 ++-- drivers/watchdog/cpwd.c | 15 +++++---- fs/hfsplus/ioctl.c | 11 ++++--- 36 files changed, 222 insertions(+), 195 deletions(-)
drivers/block/paride/pg.c +4 -3
@@ -162,7 +162,7 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};#include <linux/pg.h> #include <linux/device.h> #include <linux/sched.h> /* current, TASK_* */ -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/jiffies.h> #include <asm/uaccess.h>
@@ -193,6 +193,7 @@ module_param_array(drive3, int, NULL, 0);#define ATAPI_IDENTIFY 0x12 +static DEFINE_MUTEX (pg_mutex);static int pg_open (struct inode *inode,struct file *file);static int pg_release (struct inode *inode,struct file *file); static ssize_t pg_read(struct file *filp, char __user *buf,
@@ -518,7 +519,7 @@ static int pg_open(struct inode *inode, struct file *file)struct pg *dev = &devices[unit];int ret =0 ; -lock_kernel (); +mutex_lock (&pg_mutex);if ((unit >=PG_UNITS ) || (!dev->present)) { ret = -ENODEV ; goto out;
@@ -547,7 +548,7 @@ static int pg_open(struct inode *inode, struct file *file) file->private_data = dev; out: -unlock_kernel (); +mutex_unlock (&pg_mutex);return ret; }
drivers/block/paride/pt.c +10 -9
@@ -146,7 +146,7 @@ static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};#include <linux/mtio.h> #include <linux/device.h> #include <linux/sched.h> /* current, TASK_*, schedule_timeout() */ -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/uaccess.h>
@@ -189,6 +189,7 @@ module_param_array(drive3, int, NULL, 0);#define ATAPI_MODE_SENSE 0x1a#define ATAPI_LOG_SENSE 0x4d +static DEFINE_MUTEX (pt_mutex);static int pt_open (struct inode *inode,struct file *file);static long pt_ioctl (struct file *file,unsigned int cmd,unsigned long arg);static int pt_release (struct inode *inode,struct file *file);
@@ -650,9 +651,9 @@ static int pt_open(struct inode *inode, struct file *file)struct pt_unit *tape = pt + unit;int err; -lock_kernel (); +mutex_lock (&pt_mutex);if (unit >=PT_UNITS || (!tape->present)) { -unlock_kernel (); +mutex_unlock (&pt_mutex);return -ENODEV ; }
@@ -681,12 +682,12 @@ static int pt_open(struct inode *inode, struct file *file) } file->private_data = tape; -unlock_kernel (); +mutex_unlock (&pt_mutex);return 0 ; out:atomic_inc (&tape->available); -unlock_kernel (); +mutex_unlock (&pt_mutex);return err; }
@@ -704,15 +705,15 @@ static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)switch (mtop.mt_op) {case MTREW : -lock_kernel (); +mutex_lock (&pt_mutex);pt_rewind (tape); -unlock_kernel (); +mutex_unlock (&pt_mutex);return 0 ;case MTWEOF : -lock_kernel (); +mutex_lock (&pt_mutex);pt_write_fm (tape); -unlock_kernel (); +mutex_unlock (&pt_mutex);return 0 ;default :
drivers/char/apm-emulation.c +6 -5
@@ -13,7 +13,7 @@#include <linux/module.h> #include <linux/poll.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/miscdevice.h>
@@ -126,6 +126,7 @@ struct apm_user {/* * Local variables */ +static DEFINE_MUTEX (apm_mutex);static atomic_t suspend_acks_pending =ATOMIC_INIT (0 );static atomic_t userspace_notification_inhibit =ATOMIC_INIT (0 );static int apm_disabled;
@@ -274,7 +275,7 @@ apm_ioctl(struct file *filp, u_int cmd, u_long arg)if (!as->suser || !as->writer)return -EPERM ; -lock_kernel (); +mutex_lock (&apm_mutex);switch (cmd) {case APM_IOC_SUSPEND :mutex_lock (&state_lock);
@@ -335,7 +336,7 @@ apm_ioctl(struct file *filp, u_int cmd, u_long arg)mutex_unlock (&state_lock);break ; } -unlock_kernel (); +mutex_unlock (&apm_mutex);return err; }
@@ -370,7 +371,7 @@ static int apm_open(struct inode * inode, struct file * filp) {struct apm_user *as; -lock_kernel (); +mutex_lock (&apm_mutex); as =kzalloc (sizeof (*as),GFP_KERNEL );if (as) {/*
@@ -390,7 +391,7 @@ static int apm_open(struct inode * inode, struct file * filp) filp->private_data = as; } -unlock_kernel (); +mutex_unlock (&apm_mutex);return as ?0 : -ENOMEM ; }
drivers/char/applicom.c +5 -4
@@ -26,7 +26,7 @@#include <linux/sched.h> #include <linux/slab.h> #include <linux/errno.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/miscdevice.h> #include <linux/pci.h> #include <linux/wait.h>
@@ -60,6 +60,7 @@#define PCI_DEVICE_ID_APPLICOM_PCI2000PFB 0x0003#endif +static DEFINE_MUTEX (ac_mutex);static char *applicom_pci_devnames[] = {"PCI board" ,"PCI2000IBS / PCI2000CAN" ,
@@ -707,7 +708,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (IS_ERR (adgl))return PTR_ERR (adgl); -lock_kernel (); +mutex_lock (&ac_mutex); IndexCard = adgl->num_card-1 ;if (cmd !=6 && ((IndexCard >=MAX_BOARD ) || !apbs[IndexCard].RamIO)) {
@@ -717,7 +718,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg) warncount--; }kfree (adgl); -unlock_kernel (); +mutex_unlock (&ac_mutex);return -EINVAL ; }
@@ -835,7 +836,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg) } Dummy =readb (apbs[IndexCard].RamIO +VERS );kfree (adgl); -unlock_kernel (); +mutex_unlock (&ac_mutex);return 0 ; }
drivers/char/ds1302.c +8 -7
@@ -20,7 +20,7 @@#include <linux/miscdevice.h> #include <linux/delay.h> #include <linux/bcd.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/uaccess.h> #include <linux/io.h>
@@ -32,6 +32,7 @@#define RTC_MAJOR_NR 121/* local major, change later */ +static DEFINE_MUTEX (rtc_mutex);static const char ds1302_name[] ="ds1302" ;/* Send 8 bits. */
@@ -164,9 +165,9 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)struct rtc_time rtc_tm;memset (&rtc_tm,0 ,sizeof (struct rtc_time )); -lock_kernel (); +mutex_lock (&rtc_mutex);get_rtc_time (&rtc_tm); -unlock_kernel (); +mutex_unlock (&rtc_mutex);if (copy_to_user ((struct rtc_time *)arg, &rtc_tm,sizeof (struct rtc_time )))return -EFAULT ;return 0 ;
@@ -218,7 +219,7 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) mon =bin2bcd (mon); yrs =bin2bcd (yrs); -lock_kernel (); +mutex_lock (&rtc_mutex);local_irq_save (flags);CMOS_WRITE (yrs,RTC_YEAR );CMOS_WRITE (mon,RTC_MONTH );
@@ -227,7 +228,7 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)CMOS_WRITE (min,RTC_MINUTES );CMOS_WRITE (sec,RTC_SECONDS );local_irq_restore (flags); -unlock_kernel (); +mutex_unlock (&rtc_mutex);/* Notice that at this point, the RTC is updated but * the kernel is still running with the old time.
@@ -247,10 +248,10 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (copy_from_user (&tcs_val, (int *)arg,sizeof (int )))return -EFAULT ; -lock_kernel (); +mutex_lock (&rtc_mutex); tcs_val =RTC_TCR_PATTERN | (tcs_val &0x0F );ds1302_writereg (RTC_TRICKLECHARGER , tcs_val); -unlock_kernel (); +mutex_unlock (&rtc_mutex);return 0 ; }default :
drivers/char/ds1620.c +4 -4
@@ -8,7 +8,7 @@#include <linux/proc_fs.h> #include <linux/capability.h> #include <linux/init.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <mach/hardware.h> #include <asm/mach-types.h>
@@ -34,6 +34,7 @@#define CFG_CPU 2#define CFG_1SHOT 1 +static DEFINE_MUTEX (ds1620_mutex);static const char *fan_state[] = {"off" ,"on" ,"on (hardwired)" };/*
@@ -210,7 +211,6 @@ static void ds1620_read_state(struct therm *therm)static int ds1620_open (struct inode *inode,struct file *file) { -cycle_kernel_lock ();return nonseekable_open (inode, file); }
@@ -321,9 +321,9 @@ ds1620_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {int ret; -lock_kernel (); +mutex_lock (&ds1620_mutex); ret =ds1620_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&ds1620_mutex);return ret; }
drivers/char/dsp56k.c +14 -13
@@ -32,7 +32,7 @@#include <linux/mm.h> #include <linux/init.h> #include <linux/device.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/firmware.h> #include <linux/platform_device.h> #include <linux/uaccess.h> /* For put_user and get_user */
@@ -94,6 +94,7 @@ } \ } +static DEFINE_MUTEX (dsp56k_mutex); static struct dsp56k_device { unsigned long in_use; long maxio, timeout;
@@ -330,9 +331,9 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,if (len >DSP56K_MAX_BINARY_LENGTH ) {return -EINVAL ; } -lock_kernel (); +mutex_lock (&dsp56k_mutex); r =dsp56k_upload (bin, len); -unlock_kernel (); +mutex_unlock (&dsp56k_mutex);if (r <0 ) {return r; }
@@ -342,16 +343,16 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,case DSP56K_SET_TX_WSIZE :if (arg >4 || arg <1 )return -EINVAL ; -lock_kernel (); +mutex_lock (&dsp56k_mutex); dsp56k.tx_wsize = (int ) arg; -unlock_kernel (); +mutex_unlock (&dsp56k_mutex);break ;case DSP56K_SET_RX_WSIZE :if (arg >4 || arg <1 )return -EINVAL ; -lock_kernel (); +mutex_lock (&dsp56k_mutex); dsp56k.rx_wsize = (int ) arg; -unlock_kernel (); +mutex_unlock (&dsp56k_mutex);break ;case DSP56K_HOST_FLAGS : {
@@ -363,7 +364,7 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,if (get_user (out, &hf->out) <0 )return -EFAULT ; -lock_kernel (); +mutex_lock (&dsp56k_mutex);if ((dir &0x1 ) && (out &0x1 )) dsp56k_host_interface.icr |=DSP56K_ICR_HF0 ;else if (dir &0x1 )
@@ -378,16 +379,16 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,if (dsp56k_host_interface.icr &DSP56K_ICR_HF1 ) status |=0x2 ;if (dsp56k_host_interface.isr &DSP56K_ISR_HF2 ) status |=0x4 ;if (dsp56k_host_interface.isr &DSP56K_ISR_HF3 ) status |=0x8 ; -unlock_kernel (); +mutex_unlock (&dsp56k_mutex);return put_user (status, &hf->status); }case DSP56K_HOST_CMD :if (arg >31 || arg <0 )return -EINVAL ; -lock_kernel (); +mutex_lock (&dsp56k_mutex); dsp56k_host_interface.cvr = (u_char)((arg &DSP56K_CVR_HV_MASK ) |DSP56K_CVR_HC ); -unlock_kernel (); +mutex_unlock (&dsp56k_mutex);break ;default :return -EINVAL ;
@@ -427,7 +428,7 @@ static int dsp56k_open(struct inode *inode, struct file *file)int dev =iminor (inode) &0x0f ;int ret =0 ; -lock_kernel (); +mutex_lock (&dsp56k_mutex);switch (dev) {case DSP56K_DEV_56001 :
@@ -454,7 +455,7 @@ static int dsp56k_open(struct inode *inode, struct file *file) ret = -ENODEV ; } out: -unlock_kernel (); +mutex_unlock (&dsp56k_mutex);return ret; }
drivers/char/dtlk.c +4 -4
@@ -57,7 +57,7 @@#include <linux/ioport.h> /* for request_region */ #include <linux/delay.h> /* for loops_per_jiffy */ #include <linux/sched.h> -#include <linux/smp_lock.h> /* cycle_kernel_lock() */ +#include <linux/mutex.h> #include <asm/io.h> /* for inb_p, outb_p, inb, outb, etc. */ #include <asm/uaccess.h> /* for get_user, etc. */ #include <linux/wait.h> /* for wait_queue */
@@ -73,6 +73,7 @@#define TRACE_RET ((void) 0)#endif /* TRACING */ +static DEFINE_MUTEX (dtlk_mutex);static void dtlk_timer_tick (unsigned long data);static int dtlk_major;
@@ -275,9 +276,9 @@ static long dtlk_ioctl(struct file *file,switch (cmd) {case DTLK_INTERROGATE : -lock_kernel (); +mutex_lock (&dtlk_mutex); sp =dtlk_interrogate (); -unlock_kernel (); +mutex_unlock (&dtlk_mutex);if (copy_to_user (argp, sp,sizeof (struct dtlk_settings )))return -EINVAL ;return 0 ;
@@ -296,7 +297,6 @@ static int dtlk_open(struct inode *inode, struct file *file) {TRACE_TEXT ("(dtlk_open" ); -cycle_kernel_lock ();nonseekable_open (inode, file);switch (iminor (inode)) {case DTLK_MINOR :
drivers/char/generic_nvram.c +4 -3
@@ -19,7 +19,7 @@#include <linux/miscdevice.h> #include <linux/fcntl.h> #include <linux/init.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/uaccess.h> #include <asm/nvram.h> #ifdef CONFIG_PPC_PMAC
@@ -28,6 +28,7 @@#define NVRAM_SIZE 8192 +static DEFINE_MUTEX (nvram_mutex);static ssize_t nvram_len;static loff_t nvram_llseek (struct file *file,loff_t offset,int origin)
@@ -120,9 +121,9 @@ static long nvram_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned l {int ret; -lock_kernel (); +mutex_lock (&nvram_mutex); ret =nvram_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&nvram_mutex);return ret; }
drivers/char/genrtc.c +7 -6
@@ -52,7 +52,7 @@#include <linux/init.h> #include <linux/poll.h> #include <linux/proc_fs.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/workqueue.h> #include <asm/uaccess.h>
@@ -66,6 +66,7 @@* ioctls. */ +static DEFINE_MUTEX (gen_rtc_mutex);static DECLARE_WAIT_QUEUE_HEAD (gen_rtc_wait);/*
@@ -337,9 +338,9 @@ static long gen_rtc_unlocked_ioctl(struct file *file, unsigned int cmd, {int ret; -lock_kernel (); +mutex_lock (&gen_rtc_mutex); ret =gen_rtc_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&gen_rtc_mutex);return ret; }
@@ -352,16 +353,16 @@ static long gen_rtc_unlocked_ioctl(struct file *file, unsigned int cmd,static int gen_rtc_open (struct inode *inode,struct file *file) { -lock_kernel (); +mutex_lock (&gen_rtc_mutex);if (gen_rtc_status &RTC_IS_OPEN ) { -unlock_kernel (); +mutex_unlock (&gen_rtc_mutex);return -EBUSY ; } gen_rtc_status |=RTC_IS_OPEN ; gen_rtc_irq_data =0 ; irq_active =0 ; -unlock_kernel (); +mutex_unlock (&gen_rtc_mutex);return 0 ; }
drivers/char/i8k.c +4 -3
@@ -23,7 +23,7 @@#include <linux/seq_file.h> #include <linux/dmi.h> #include <linux/capability.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/uaccess.h> #include <asm/io.h>
@@ -56,6 +56,7 @@#define I8K_TEMPERATURE_BUG 1 +static DEFINE_MUTEX (i8k_mutex);static char bios_version[4 ];MODULE_AUTHOR ("Massimo Dal Zotto ([email protected])" );
@@ -399,9 +400,9 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) {long ret; -lock_kernel (); +mutex_lock (&i8k_mutex); ret =i8k_ioctl_unlocked (fp, cmd, arg); -unlock_kernel (); +mutex_unlock (&i8k_mutex);return ret; }
drivers/char/ip2/ip2main.c +4 -4
@@ -98,7 +98,7 @@#include <linux/major.h> #include <linux/wait.h> #include <linux/device.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/firmware.h> #include <linux/platform_device.h>
@@ -138,6 +138,7 @@#include <linux/proc_fs.h> #include <linux/seq_file.h> +static DEFINE_MUTEX (ip2_mutex);static const struct file_operations ip2mem_proc_fops;static const struct file_operations ip2_proc_fops;
@@ -2897,7 +2898,7 @@ ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg )printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n" , cmd, arg );#endif -lock_kernel (); +mutex_lock (&ip2_mutex);switch ( iplminor ) {case 0 :// IPL device
@@ -2961,7 +2962,7 @@ ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg ) rc = -ENODEV ;break ; } -unlock_kernel (); +mutex_unlock (&ip2_mutex);return rc; }
@@ -2982,7 +2983,6 @@ ip2_ipl_open( struct inode *pInode, struct file *pFile )#ifdef IP2DEBUG_IPL printk (KERN_DEBUG "IP2IPL: open\n" );#endif -cycle_kernel_lock ();return 0 ; }
drivers/char/lp.c +8 -7
@@ -126,7 +126,7 @@#include <linux/device.h> #include <linux/wait.h> #include <linux/jiffies.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/compat.h> #include <linux/parport.h>
@@ -140,6 +140,7 @@/* if you have more than 8 printers, remember to increase LP_NO */ #define LP_NO 8 +static DEFINE_MUTEX (lp_mutex);static struct lp_struct lp_table[LP_NO ];static unsigned int lp_count =0 ;
@@ -493,7 +494,7 @@ static int lp_open(struct inode * inode, struct file * file)unsigned int minor =iminor (inode);int ret =0 ; -lock_kernel (); +mutex_lock (&lp_mutex);if (minor >=LP_NO ) { ret = -ENXIO ; goto out;
@@ -554,7 +555,7 @@ static int lp_open(struct inode * inode, struct file * file)lp_release_parport (&lp_table[minor]); lp_table[minor].current_mode =IEEE1284_MODE_COMPAT ; out: -unlock_kernel (); +mutex_unlock (&lp_mutex);return ret; }
@@ -680,7 +681,7 @@ static long lp_ioctl(struct file *file, unsigned int cmd,int ret; minor =iminor (file->f_path.dentry->d_inode); -lock_kernel (); +mutex_lock (&lp_mutex);switch (cmd) {case LPSETTIMEOUT : if (copy_from_user(&par_timeout, (void __user *)arg,
@@ -694,7 +695,7 @@ static long lp_ioctl(struct file *file, unsigned int cmd, ret =lp_do_ioctl (minor, cmd, arg, (void __user *)arg);break ; } -unlock_kernel (); +mutex_unlock (&lp_mutex);return ret; }
@@ -709,7 +710,7 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd,int ret; minor =iminor (file->f_path.dentry->d_inode); -lock_kernel (); +mutex_lock (&lp_mutex);switch (cmd) {case LPSETTIMEOUT : tc =compat_ptr (arg);
@@ -730,7 +731,7 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd, ret =lp_do_ioctl (minor, cmd, arg,compat_ptr (arg));break ; } -unlock_kernel (); +mutex_unlock (&lp_mutex);return ret; }
drivers/char/mbcs.c +4 -4
@@ -25,7 +25,6 @@#include <linux/mm.h> #include <linux/uio.h> #include <linux/mutex.h> -#include <linux/smp_lock.h> #include <linux/slab.h> #include <asm/io.h> #include <asm/uaccess.h>
@@ -42,6 +41,7 @@#else #define DBG(fmt...)#endif +static DEFINE_MUTEX (mbcs_mutex);static int mbcs_major;static LIST_HEAD (soft_list);
@@ -385,19 +385,19 @@ static int mbcs_open(struct inode *ip, struct file *fp)struct mbcs_soft *soft;int minor; -lock_kernel (); +mutex_lock (&mbcs_mutex); minor =iminor (ip);/* Nothing protects access to this list... */ list_for_each_entry (soft, &soft_list, list) {if (soft->nasid == minor) { fp->private_data = soft->cxdev; -unlock_kernel (); +mutex_unlock (&mbcs_mutex);return 0 ; } } -unlock_kernel (); +mutex_unlock (&mbcs_mutex);return -ENODEV ; }
drivers/char/mmtimer.c +4 -3
@@ -32,7 +32,7 @@#include <linux/interrupt.h> #include <linux/time.h> #include <linux/math64.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/slab.h> #include <asm/uaccess.h>
@@ -59,6 +59,7 @@ extern unsigned long sn_rtc_cycles_per_second;#define rtc_time () (*RTC_COUNTER_ADDR) +static DEFINE_MUTEX (mmtimer_mutex);static long mmtimer_ioctl (struct file *file,unsigned int cmd,unsigned long arg);static int mmtimer_mmap (struct file *file,struct vm_area_struct *vma);
@@ -371,7 +372,7 @@ static long mmtimer_ioctl(struct file *file, unsigned int cmd, {int ret =0 ; -lock_kernel (); +mutex_lock (&mmtimer_mutex);switch (cmd) {case MMTIMER_GETOFFSET :/* offset of the counter */
@@ -414,7 +415,7 @@ static long mmtimer_ioctl(struct file *file, unsigned int cmd, ret = -ENOTTY ;break ; } -unlock_kernel (); +mutex_unlock (&mmtimer_mutex);return ret; }
drivers/char/mwave/mwavedd.c +22 -22
157 lines not on this page · raw message
drivers/char/nvram.c +6 -5
@@ -109,10 +109,11 @@#include <linux/spinlock.h> #include <linux/io.h> #include <linux/uaccess.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/system.h> +static DEFINE_MUTEX (nvram_mutex);static DEFINE_SPINLOCK (nvram_state_lock);static int nvram_open_cnt;/* #times opened */ static int nvram_open_mode;/* special open modes */
@@ -308,7 +309,7 @@ static long nvram_ioctl(struct file *file, unsigned int cmd,if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -lock_kernel (); +mutex_lock (&nvram_mutex);spin_lock_irq (&rtc_lock);for (i =0 ; i <NVRAM_BYTES ; ++i)
@@ -316,7 +317,7 @@ static long nvram_ioctl(struct file *file, unsigned int cmd,__nvram_set_checksum ();spin_unlock_irq (&rtc_lock); -unlock_kernel (); +mutex_unlock (&nvram_mutex);return 0 ;case NVRAM_SETCKS :
@@ -325,11 +326,11 @@ static long nvram_ioctl(struct file *file, unsigned int cmd,if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -lock_kernel (); +mutex_lock (&nvram_mutex);spin_lock_irq (&rtc_lock);__nvram_set_checksum ();spin_unlock_irq (&rtc_lock); -unlock_kernel (); +mutex_unlock (&nvram_mutex);return 0 ;default :
drivers/char/nwflash.c +6 -6
@@ -25,7 +25,6 @@#include <linux/spinlock.h> #include <linux/rwsem.h> #include <linux/init.h> -#include <linux/smp_lock.h> #include <linux/mutex.h> #include <linux/jiffies.h>
@@ -41,6 +40,7 @@#define NWFLASH_VERSION "6.4" +static DEFINE_MUTEX (flash_mutex);static void kick_open (void );static int get_flash_id (void );static int erase_block (int nBlock);
@@ -96,7 +96,7 @@ static int get_flash_id(void)static long flash_ioctl (struct file *filep,unsigned int cmd,unsigned long arg) { -lock_kernel (); +mutex_lock (&flash_mutex);switch (cmd) {case CMD_WRITE_DISABLE : gbWriteBase64Enable =0 ;
@@ -114,10 +114,10 @@ static long flash_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)default : gbWriteBase64Enable =0 ; gbWriteEnable =0 ; -unlock_kernel (); +mutex_unlock (&flash_mutex);return -EINVAL ; } -unlock_kernel (); +mutex_unlock (&flash_mutex);return 0 ; }
@@ -282,7 +282,7 @@ static loff_t flash_llseek(struct file *file, loff_t offset, int orig) {loff_t ret; -lock_kernel (); +mutex_lock (&flash_mutex);if (flashdebug)printk (KERN_DEBUG "flash_llseek: offset=0x%X, orig=0x%X.\n" , (unsigned int ) offset, orig);
@@ -317,7 +317,7 @@ static loff_t flash_llseek(struct file *file, loff_t offset, int orig)default : ret = -EINVAL ; } -unlock_kernel (); +mutex_unlock (&flash_mutex);return ret; }
drivers/char/pcmcia/cm4000_cs.c +6 -5
@@ -30,7 +30,7 @@#include <linux/fs.h> #include <linux/delay.h> #include <linux/bitrev.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/uaccess.h> #include <linux/io.h>
@@ -55,6 +55,7 @@ __func__ , ## args); \ } while (0) +static DEFINE_MUTEX (cmm_mutex);static char *version ="cm4000_cs.c v2.4.0gm6 - All bugs added by Harald Welte" ;#define T_1SEC (HZ)
@@ -1418,7 +1419,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) iminor(inode), ioctl_names[_IOC_NR(cmd)]);#endif -lock_kernel (); +mutex_lock (&cmm_mutex); rc = -ENODEV ; link = dev_table[iminor (inode)];if (!pcmcia_dev_present (link)) {
@@ -1626,7 +1627,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) rc = -ENOTTY ; } out: -unlock_kernel (); +mutex_unlock (&cmm_mutex);return rc; }
@@ -1640,7 +1641,7 @@ static int cmm_open(struct inode *inode, struct file *filp)if (minor >=CM4000_MAX_DEV )return -ENODEV ; -lock_kernel (); +mutex_lock (&cmm_mutex); link = dev_table[minor];if (link ==NULL || !pcmcia_dev_present (link)) { ret = -ENODEV ;
@@ -1685,7 +1686,7 @@ static int cmm_open(struct inode *inode, struct file *filp)DEBUGP (2 , dev,"<- cmm_open\n" ); ret =nonseekable_open (inode, filp); out: -unlock_kernel (); +mutex_unlock (&cmm_mutex);return ret; }
drivers/char/pcmcia/cm4040_cs.c +4 -3
@@ -24,7 +24,7 @@#include <linux/fs.h> #include <linux/delay.h> #include <linux/poll.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/wait.h> #include <asm/uaccess.h> #include <asm/io.h>
@@ -49,6 +49,7 @@ __func__ , ## args); \ } while (0) +static DEFINE_MUTEX (cm4040_mutex);static char *version ="OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte" ;
@@ -444,7 +445,7 @@ static int cm4040_open(struct inode *inode, struct file *filp)if (minor >=CM_MAX_DEV )return -ENODEV ; -lock_kernel (); +mutex_lock (&cm4040_mutex); link = dev_table[minor];if (link ==NULL || !pcmcia_dev_present (link)) { ret = -ENODEV ;
@@ -473,7 +474,7 @@ static int cm4040_open(struct inode *inode, struct file *filp)DEBUGP (2 , dev,"<- cm4040_open (successfully)\n" ); ret =nonseekable_open (inode, filp); out: -unlock_kernel (); +mutex_unlock (&cm4040_mutex);return ret; }
drivers/char/ppdev.c +4 -4
@@ -67,7 +67,7 @@#include <linux/slab.h> #include <linux/major.h> #include <linux/ppdev.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/uaccess.h> #define PP_VERSION "ppdev: user-space parallel port driver"
@@ -97,6 +97,7 @@ struct pp_struct {/* ROUND_UP macro from fs/select.c */ #define ROUND_UP (x,y) (((x)+(y)-1)/(y)) +static DEFINE_MUTEX (pp_do_mutex);static inline void pp_enable_irq (struct pp_struct *pp) {struct parport *port = pp->pdev->port;
@@ -630,9 +631,9 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)static long pp_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {long ret; -lock_kernel (); +mutex_lock (&pp_do_mutex); ret =pp_do_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&pp_do_mutex);return ret; }
@@ -641,7 +642,6 @@ static int pp_open (struct inode * inode, struct file * file)unsigned int minor =iminor (inode);struct pp_struct *pp; -cycle_kernel_lock ();if (minor >=PARPORT_MAX )return -ENXIO ;
drivers/char/rio/rio_linux.c +4 -3
@@ -44,7 +44,7 @@#include <linux/delay.h> #include <linux/pci.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/miscdevice.h> #include <linux/init.h>
@@ -122,6 +122,7 @@ more than 512 ports.... *//* These constants are derived from SCO Source */ +static DEFINE_MUTEX (rio_fw_mutex);static struct Conf RIOConf = {/* locator */ "RIO Config here" ,
@@ -566,9 +567,9 @@ static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)func_enter ();/* The "dev" argument isn't used. */ -lock_kernel (); +mutex_lock (&rio_fw_mutex); rc =riocontrol (p,0 , cmd, arg,capable (CAP_SYS_ADMIN )); -unlock_kernel (); +mutex_unlock (&rio_fw_mutex);func_exit ();return rc;
drivers/char/snsc.c +5 -4
@@ -21,7 +21,7 @@#include <linux/poll.h> #include <linux/module.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/sn/io.h> #include <asm/sn/sn_sal.h> #include <asm/sn/module.h>
@@ -34,6 +34,7 @@#define SCDRV_BUFSZ 2048#define SCDRV_TIMEOUT 1000 +static DEFINE_MUTEX (scdrv_mutex);static irqreturn_t scdrv_interrupt (int irq,void *subch_data) {
@@ -105,7 +106,7 @@ scdrv_open(struct inode *inode, struct file *file) file->private_data = sd;/* hook this subchannel up to the system controller interrupt */ -lock_kernel (); +mutex_lock (&scdrv_mutex); rv =request_irq (SGI_UART_VECTOR , scdrv_interrupt,IRQF_SHARED |IRQF_DISABLED ,SYSCTL_BASENAME , sd);
@@ -113,10 +114,10 @@ scdrv_open(struct inode *inode, struct file *file)ia64_sn_irtr_close (sd->sd_nasid, sd->sd_subch);kfree (sd);printk ("%s: irq request failed (%d)\n" , __func__, rv); -unlock_kernel (); +mutex_unlock (&scdrv_mutex);return -EBUSY ; } -unlock_kernel (); +mutex_unlock (&scdrv_mutex);return 0 ; }
drivers/char/toshiba.c +5 -4
@@ -68,7 +68,7 @@#include <linux/stat.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/toshiba.h> #define TOSH_MINOR_DEV 181
@@ -78,6 +78,7 @@ MODULE_AUTHOR("Jonathan Buzzard <[email protected]>");MODULE_DESCRIPTION ("Toshiba laptop SMM driver" );MODULE_SUPPORTED_DEVICE ("toshiba" ); +static DEFINE_MUTEX (tosh_mutex);static int tosh_fn;module_param_named (fn, tosh_fn, int,0 );MODULE_PARM_DESC (fn,"User specified Fn key detection port" );
@@ -274,16 +275,16 @@ static long tosh_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)return -EINVAL ;/* do we need to emulate the fan ? */ -lock_kernel (); +mutex_lock (&tosh_mutex);if (tosh_fan==1 ) {if (((ax==0xf300 ) || (ax==0xf400 )) && (bx==0x0004 )) { err =tosh_emulate_fan (®s); -unlock_kernel (); +mutex_unlock (&tosh_mutex);break ; } } err =tosh_smm (®s); -unlock_kernel (); +mutex_unlock (&tosh_mutex);break ;default :return -EINVAL ;
drivers/char/viotape.c +6 -5
@@ -46,7 +46,7 @@#include <linux/completion.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/slab.h> #include <asm/uaccess.h>
@@ -64,6 +64,7 @@#define VIOTAPE_KERN_WARN KERN_WARNING "viotape: "#define VIOTAPE_KERN_INFO KERN_INFO "viotape: " +static DEFINE_MUTEX (proc_viotape_mutex);static int viotape_numdev;/*
@@ -684,9 +685,9 @@ static long viotap_unlocked_ioctl(struct file *file, {long rc; -lock_kernel (); +mutex_lock (&proc_viotape_mutex); rc =viotap_ioctl (file->f_path.dentry->d_inode, file, cmd, arg); -unlock_kernel (); +mutex_unlock (&proc_viotape_mutex);return rc; }
@@ -700,7 +701,7 @@ static int viotap_open(struct inode *inode, struct file *file)if (op ==NULL )return -ENOMEM ; -lock_kernel (); +mutex_lock (&proc_viotape_mutex);get_dev_info (file->f_path.dentry->d_inode, &devi);/* Note: We currently only support one mode! */
@@ -731,7 +732,7 @@ static int viotap_open(struct inode *inode, struct file *file) free_op:free_op_struct (op); -unlock_kernel (); +mutex_unlock (&proc_viotape_mutex);return ret; }
drivers/char/xilinx_hwicap/xilinx_hwicap.c +3 -3
@@ -81,7 +81,6 @@#include <linux/poll.h> #include <linux/proc_fs.h> #include <linux/mutex.h> -#include <linux/smp_lock.h> #include <linux/sysctl.h> #include <linux/fs.h> #include <linux/cdev.h>
@@ -112,6 +111,7 @@#define HWICAP_DEVICES 1/* An array, which is set to true when the device is registered. */ +static DEFINE_MUTEX (hwicap_mutex);static bool probed_devices[HWICAP_DEVICES ];static struct mutex icap_sem;
@@ -502,7 +502,7 @@ static int hwicap_open(struct inode *inode, struct file *file)struct hwicap_drvdata *drvdata;int status; -lock_kernel (); +mutex_lock (&hwicap_mutex); drvdata = container_of(inode->i_cdev, struct hwicap_drvdata, cdev); status =mutex_lock_interruptible (&drvdata->sem);
@@ -528,7 +528,7 @@ static int hwicap_open(struct inode *inode, struct file *file) error:mutex_unlock (&drvdata->sem); out: -unlock_kernel (); +mutex_unlock (&hwicap_mutex);return status; }
drivers/hwmon/fschmd.c +3 -3
@@ -38,7 +38,6 @@#include <linux/i2c.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> -#include <linux/smp_lock.h> #include <linux/err.h> #include <linux/mutex.h> #include <linux/sysfs.h>
@@ -50,6 +49,7 @@#include <linux/kref.h> /* Addresses to scan */ +static DEFINE_MUTEX (watchdog_mutex);static const unsigned short normal_i2c[] = {0x73 ,I2C_CLIENT_END };/* Insmod parameters */
@@ -858,7 +858,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long arint i, ret =0 ;struct fschmd_data *data = filp->private_data; -lock_kernel (); +mutex_lock (&watchdog_mutex);switch (cmd) {case WDIOC_GETSUPPORT : ident.firmware_version = data->revision;
@@ -915,7 +915,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long ardefault : ret = -ENOTTY ; } -unlock_kernel (); +mutex_unlock (&watchdog_mutex);return ret; }
drivers/hwmon/w83793.c +3 -3
@@ -35,7 +35,6 @@#include <linux/slab.h> #include <linux/i2c.h> #include <linux/hwmon.h> -#include <linux/smp_lock.h> #include <linux/hwmon-vid.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h>
@@ -52,6 +51,7 @@#define WATCHDOG_TIMEOUT 2/* 2 minute default timeout */ /* Addresses to scan */ +static DEFINE_MUTEX (watchdog_mutex);static const unsigned short normal_i2c[] = {0x2c ,0x2d ,0x2e ,0x2f ,I2C_CLIENT_END };
@@ -1333,7 +1333,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,int val, ret =0 ;struct w83793_data *data = filp->private_data; -lock_kernel (); +mutex_lock (&watchdog_mutex);switch (cmd) {case WDIOC_GETSUPPORT :if (!nowayout)
@@ -1387,7 +1387,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,default : ret = -ENOTTY ; } -unlock_kernel (); +mutex_unlock (&watchdog_mutex);return ret; }
drivers/input/misc/hp_sdc_rtc.c +4 -3
@@ -43,7 +43,7 @@#include <linux/proc_fs.h> #include <linux/poll.h> #include <linux/rtc.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/semaphore.h> MODULE_AUTHOR ("Brian S. Julin <[email protected]>" );
@@ -52,6 +52,7 @@ MODULE_LICENSE("Dual BSD/GPL");#define RTC_VERSION "1.10d" +static DEFINE_MUTEX (hp_sdc_rtc_mutex);static unsigned long epoch =2000 ;static struct semaphore i8042tregs;
@@ -665,9 +666,9 @@ static long hp_sdc_rtc_unlocked_ioctl(struct file *file, {int ret; -lock_kernel (); +mutex_lock (&hp_sdc_rtc_mutex); ret =hp_sdc_rtc_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&hp_sdc_rtc_mutex);return ret; }
drivers/misc/phantom.c +6 -5
@@ -24,7 +24,7 @@#include <linux/slab.h> #include <linux/phantom.h> #include <linux/sched.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/atomic.h> #include <asm/io.h>
@@ -38,6 +38,7 @@#define PHB_RUNNING 1#define PHB_NOT_OH 2 +static DEFINE_MUTEX (phantom_mutex);static struct class *phantom_class;static int phantom_major;
@@ -215,17 +216,17 @@ static int phantom_open(struct inode *inode, struct file *file)struct phantom_device *dev =container_of (inode->i_cdev, struct phantom_device, cdev); -lock_kernel (); +mutex_lock (&phantom_mutex);nonseekable_open (inode, file);if (mutex_lock_interruptible (&dev->open_lock)) { -unlock_kernel (); +mutex_unlock (&phantom_mutex);return -ERESTARTSYS ; }if (dev->opened) {mutex_unlock (&dev->open_lock); -unlock_kernel (); +mutex_unlock (&phantom_mutex);return -EINVAL ; }
@@ -236,7 +237,7 @@ static int phantom_open(struct inode *inode, struct file *file)atomic_set (&dev->counter,0 ); dev->opened++;mutex_unlock (&dev->open_lock); -unlock_kernel (); +mutex_unlock (&phantom_mutex);return 0 ; }
drivers/pci/hotplug/cpqphp_sysfs.c +7 -6
@@ -34,10 +34,11 @@#include <linux/workqueue.h> #include <linux/pci.h> #include <linux/pci_hotplug.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/debugfs.h> #include "cpqphp.h" +static DEFINE_MUTEX (cpqphp_mutex);static int show_ctrl (struct controller *ctrl,char *buf) {char *out = buf;
@@ -147,7 +148,7 @@ static int open(struct inode *inode, struct file *file)struct ctrl_dbg *dbg;int retval = -ENOMEM ; -lock_kernel (); +mutex_lock (&cpqphp_mutex); dbg =kmalloc (sizeof (*dbg),GFP_KERNEL );if (!dbg) goto exit;
@@ -160,7 +161,7 @@ static int open(struct inode *inode, struct file *file) file->private_data = dbg; retval =0 ; exit: -unlock_kernel (); +mutex_unlock (&cpqphp_mutex);return retval; }
@@ -169,7 +170,7 @@ static loff_t lseek(struct file *file, loff_t off, int whence)struct ctrl_dbg *dbg;loff_t new =-1 ; -lock_kernel (); +mutex_lock (&cpqphp_mutex); dbg = file->private_data;switch (whence) {
@@ -181,10 +182,10 @@ static loff_t lseek(struct file *file, loff_t off, int whence)break ; }if (new <0 || new > dbg->size) { -unlock_kernel (); +mutex_unlock (&cpqphp_mutex);return -EINVAL ; } -unlock_kernel (); +mutex_unlock (&cpqphp_mutex);return (file->f_pos = new); }
drivers/rtc/rtc-m41t80.c +7 -6
@@ -20,7 +20,7 @@#include <linux/module.h> #include <linux/rtc.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/string.h> #ifdef CONFIG_RTC_DRV_M41T80_WDT #include <linux/fs.h>
@@ -68,6 +68,7 @@#define DRV_VERSION "0.05" +static DEFINE_MUTEX (m41t80_rtc_mutex);static const struct i2c_device_id m41t80_id[] = { {"m41t62" ,M41T80_FEATURE_SQ |M41T80_FEATURE_SQ_ALT }, {"m41t65" ,M41T80_FEATURE_HT |M41T80_FEATURE_WD },
@@ -677,9 +678,9 @@ static long wdt_unlocked_ioctl(struct file *file, unsigned int cmd, {int ret; -lock_kernel (); +mutex_lock (&m41t80_rtc_mutex); ret =wdt_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&m41t80_rtc_mutex);return ret; }
@@ -693,16 +694,16 @@ static long wdt_unlocked_ioctl(struct file *file, unsigned int cmd,static int wdt_open (struct inode *inode,struct file *file) {if (MINOR (inode->i_rdev) ==WATCHDOG_MINOR ) { -lock_kernel (); +mutex_lock (&m41t80_rtc_mutex);if (test_and_set_bit (0 , &wdt_is_open)) { -unlock_kernel (); +mutex_unlock (&m41t80_rtc_mutex);return -EBUSY ; }/* * Activate */ wdt_is_open =1 ; -unlock_kernel (); +mutex_unlock (&m41t80_rtc_mutex);return nonseekable_open (inode, file); }return -ENODEV ;
drivers/sbus/char/jsflash.c +13 -11
@@ -27,7 +27,7 @@*/ #include <linux/module.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/miscdevice.h>
@@ -68,6 +68,8 @@#define JSF_PART_BITS 2/* 2 bits of minors to cover JSF_NPART */ #define JSF_PART_MASK 0x3/* 2 bits mask */ +static DEFINE_MUTEX (jsf_mutex); +/* * Access functions. * We could ioremap(), but it's easier this way.
@@ -225,7 +227,7 @@ static loff_t jsf_lseek(struct file * file, loff_t offset, int orig) {loff_t ret; -lock_kernel (); +mutex_lock (&jsf_mutex);switch (orig) {case 0 : file->f_pos = offset;
@@ -238,7 +240,7 @@ static loff_t jsf_lseek(struct file * file, loff_t offset, int orig)default : ret = -EINVAL ; } -unlock_kernel (); +mutex_unlock (&jsf_mutex);return ret; }
@@ -384,18 +386,18 @@ static int jsf_ioctl_program(void __user *arg)static long jsf_ioctl (struct file *f,unsigned int cmd,unsigned long arg) { -lock_kernel (); +mutex_lock (&jsf_mutex);int error = -ENOTTY ;void __user *argp = (void __user *)arg;if (!capable (CAP_SYS_ADMIN )) { -unlock_kernel (); +mutex_unlock (&jsf_mutex);return -EPERM ; }switch (cmd) {case JSFLASH_IDENT :if (copy_to_user (argp, &jsf0.id,JSFIDSZ )) { -unlock_kernel (); +mutex_unlock (&jsf_mutex);return -EFAULT ; }break ;
@@ -407,7 +409,7 @@ static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg)break ; } -unlock_kernel (); +mutex_unlock (&jsf_mutex);return error; }
@@ -418,17 +420,17 @@ static int jsf_mmap(struct file * file, struct vm_area_struct * vma)static int jsf_open (struct inode * inode,struct file * filp) { -lock_kernel (); +mutex_lock (&jsf_mutex);if (jsf0.base ==0 ) { -unlock_kernel (); +mutex_unlock (&jsf_mutex);return -ENXIO ; }if (test_and_set_bit (0 , (void *)&jsf0.busy) !=0 ) { -unlock_kernel (); +mutex_unlock (&jsf_mutex);return -EBUSY ; } -unlock_kernel (); +mutex_unlock (&jsf_mutex);return 0 ;/* XXX What security? */ }
drivers/telephony/ixj.c +4 -3
@@ -257,7 +257,7 @@#include <linux/fs.h> /* everything... */ #include <linux/errno.h> /* error codes */ #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/mm.h> #include <linux/ioport.h> #include <linux/interrupt.h>
@@ -277,6 +277,7 @@#define TYPE (inode) (iminor(inode) >> 4)#define NUM (inode) (iminor(inode) & 0xf) +static DEFINE_MUTEX (ixj_mutex);static int ixjdebug;static int hertz =HZ ;static int samplerate =100 ;
@@ -6655,9 +6656,9 @@ static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arstatic long ixj_ioctl (struct file *file_p,unsigned int cmd,unsigned long arg) {long ret; -lock_kernel (); +mutex_lock (&ixj_mutex); ret =do_ixj_ioctl (file_p, cmd, arg); -unlock_kernel (); +mutex_unlock (&ixj_mutex);return ret; }
drivers/watchdog/cpwd.c +8 -7
@@ -25,7 +25,7 @@#include <linux/ioport.h> #include <linux/timer.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/io.h> #include <linux/of.h> #include <linux/of_device.h>
@@ -89,6 +89,7 @@ struct cpwd { } devs[WD_NUMDEVS ]; }; +static DEFINE_MUTEX (cpwd_mutex);static struct cpwd *cpwd_device;/* Sun uses Altera PLD EPF8820ATC144-4
@@ -368,7 +369,7 @@ static int cpwd_open(struct inode *inode, struct file *f) {struct cpwd *p = cpwd_device; -lock_kernel (); +mutex_lock (&cpwd_mutex);switch (iminor (inode)) {case WD0_MINOR :case WD1_MINOR :
@@ -376,7 +377,7 @@ static int cpwd_open(struct inode *inode, struct file *f)break ;default : -unlock_kernel (); +mutex_unlock (&cpwd_mutex);return -ENODEV ; }
@@ -386,13 +387,13 @@ static int cpwd_open(struct inode *inode, struct file *f) IRQF_SHARED, DRIVER_NAME, p)) { printk(KERN_ERR PFX "Cannot register IRQ %d\n", p->irq); -unlock_kernel (); +mutex_unlock (&cpwd_mutex);return -EBUSY ; } p->initialized = true; } -unlock_kernel (); +mutex_unlock (&cpwd_mutex);return nonseekable_open (inode, f); }
@@ -482,9 +483,9 @@ static long cpwd_compat_ioctl(struct file *file, unsigned int cmd,case WIOCSTART :case WIOCSTOP :case WIOCGSTAT : -lock_kernel (); +mutex_lock (&cpwd_mutex); rval =cpwd_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&cpwd_mutex);break ;/* everything else is handled by the generic compat layer */
fs/hfsplus/ioctl.c +6 -5
@@ -17,16 +17,17 @@#include <linux/mount.h> #include <linux/sched.h> #include <linux/xattr.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/uaccess.h> #include "hfsplus_fs.h" +static DEFINE_MUTEX (hfsplus_mutex);long hfsplus_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {struct inode *inode = filp->f_path.dentry->d_inode;unsigned int flags; -lock_kernel (); +mutex_lock (&hfsplus_mutex);switch (cmd) {case HFSPLUS_IOC_EXT2_GETFLAGS : flags =0 ;
@@ -41,7 +42,7 @@ long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)int err =0 ; err =mnt_want_write (filp->f_path.mnt);if (err) { -unlock_kernel (); +mutex_unlock (&hfsplus_mutex);return err; }
@@ -89,11 +90,11 @@ long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)mark_inode_dirty (inode); setflags_out:mnt_drop_write (filp->f_path.mnt); -unlock_kernel (); +mutex_unlock (&hfsplus_mutex);return err; }default : -unlock_kernel (); +mutex_unlock (&hfsplus_mutex);return -ENOTTY ; } }
Signature · 1 line
1.7.1
Arnd Bergmann
maintainerPATCH 6/7 sound: autoconvert trivial BKL users to private mutex
In reply to Arnd BergmannThe usage of the BKL in the OSS sound drivers is trivial, and each of them only locks against itself, so it can be turned into per-driver mutexes.
This is the script that was used for the conversion:
file=$1
name=$2
if grep -q lock_kernel ${file} ; then
if grep -q 'include.*linux.mutex.h' ${file} ; then
sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
else
sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
fi
sed -i ${file} \
-e "/^#include.*linux.mutex.h/,$ {
1,/^\(static\|int\|long\)/ {
/^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);} }" \
-e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
-e '/[ ]*cycle_kernel_lock();/d'
else
sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \
-e '/cycle_kernel_lock()/d'fi
--- sound/oss/au1550_ac97.c | 30 +++++++++++++------------- sound/oss/dmasound/dmasound_core.c | 41 ++++++++++++++++++----------------- sound/oss/msnd_pinnacle.c | 15 +++++++------ sound/oss/sh_dac_audio.c | 13 ++++++----- sound/oss/soundcard.c | 41 ++++++++++++++++++----------------- sound/oss/swarm_cs4297a.c | 20 ++++++++-------- sound/oss/vwsnd.c | 30 +++++++++++++------------- 7 files changed, 97 insertions(+), 93 deletions(-)
sound/oss/au1550_ac97.c +15 -15
@@ -43,7 +43,6 @@#include <linux/sound.h> #include <linux/slab.h> #include <linux/soundcard.h> -#include <linux/smp_lock.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/kernel.h>
@@ -77,6 +76,7 @@/* Boot options * 0 = no VRA, 1 = use VRA if codec supports it */ +static DEFINE_MUTEX (au1550_ac97_mutex);static int vra =1 ;module_param (vra, bool,0 );MODULE_PARM_DESC (vra,"if 1 use VRA if codec supports it" );
@@ -798,9 +798,9 @@ au1550_llseek(struct file *file, loff_t offset, int origin)static int au1550_open_mixdev (struct inode *inode,struct file *file) { -lock_kernel (); +mutex_lock (&au1550_ac97_mutex); file->private_data = &au1550_state; -unlock_kernel (); +mutex_unlock (&au1550_ac97_mutex);return 0 ; }
@@ -824,9 +824,9 @@ au1550_ioctl_mixdev(struct file *file, unsigned int cmd, unsigned long arg)struct ac97_codec *codec = s->codec;int ret; -lock_kernel (); +mutex_lock (&au1550_ac97_mutex); ret =mixdev_ioctl (codec, cmd, arg); -unlock_kernel (); +mutex_unlock (&au1550_ac97_mutex);return ret; }
@@ -1255,7 +1255,7 @@ au1550_mmap(struct file *file, struct vm_area_struct *vma)unsigned long size;int ret =0 ; -lock_kernel (); +mutex_lock (&au1550_ac97_mutex);mutex_lock (&s->sem);if (vma->vm_flags &VM_WRITE ) db = &s->dma_dac;
@@ -1283,7 +1283,7 @@ au1550_mmap(struct file *file, struct vm_area_struct *vma) db->mapped =1 ; out:mutex_unlock (&s->sem); -unlock_kernel (); +mutex_unlock (&au1550_ac97_mutex);return ret; }
@@ -1781,9 +1781,9 @@ au1550_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {int ret; -lock_kernel (); +mutex_lock (&au1550_ac97_mutex); ret =au1550_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&au1550_ac97_mutex);return ret; }
@@ -1804,7 +1804,7 @@ au1550_open(struct inode *inode, struct file *file)#endif file->private_data = s; -lock_kernel (); +mutex_lock (&au1550_ac97_mutex);/* wait for device to become free */ mutex_lock (&s->open_mutex);while (s->open_mode & file->f_mode) {
@@ -1861,7 +1861,7 @@ au1550_open(struct inode *inode, struct file *file) out:mutex_unlock (&s->open_mutex); out2: -unlock_kernel (); +mutex_unlock (&au1550_ac97_mutex);return ret; }
@@ -1870,12 +1870,12 @@ au1550_release(struct inode *inode, struct file *file) {struct au1550_state *s = (struct au1550_state *)file->private_data; -lock_kernel (); +mutex_lock (&au1550_ac97_mutex);if (file->f_mode &FMODE_WRITE ) { -unlock_kernel (); +mutex_unlock (&au1550_ac97_mutex);drain_dac (s, file->f_flags &O_NONBLOCK ); -lock_kernel (); +mutex_lock (&au1550_ac97_mutex); }mutex_lock (&s->open_mutex);
@@ -1892,7 +1892,7 @@ au1550_release(struct inode *inode, struct file *file) s->open_mode &= ((~file->f_mode) & (FMODE_READ |FMODE_WRITE ));mutex_unlock (&s->open_mutex);wake_up (&s->open_wait); -unlock_kernel (); +mutex_unlock (&au1550_ac97_mutex);return 0 ; }
sound/oss/dmasound/dmasound_core.c +21 -20
131 lines not on this page · raw message
sound/oss/msnd_pinnacle.c +8 -7
@@ -39,7 +39,7 @@#include <linux/delay.h> #include <linux/init.h> #include <linux/interrupt.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/gfp.h> #include <asm/irq.h> #include <asm/io.h>
@@ -79,6 +79,7 @@ dev.rec_sample_rate / \ dev.rec_channels) +static DEFINE_MUTEX (msnd_pinnacle_mutex);static multisound_dev_t dev;#ifndef HAVE_DSPCODEH
@@ -651,12 +652,12 @@ static long dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ret = -EINVAL ; -lock_kernel (); +mutex_lock (&msnd_pinnacle_mutex);if (minor == dev.dsp_minor) ret =dsp_ioctl (file, cmd, arg);else if (minor == dev.mixer_minor) ret =mixer_ioctl (cmd, arg); -unlock_kernel (); +mutex_unlock (&msnd_pinnacle_mutex);return ret; }
@@ -761,7 +762,7 @@ static int dev_open(struct inode *inode, struct file *file)int minor =iminor (inode);int err =0 ; -lock_kernel (); +mutex_lock (&msnd_pinnacle_mutex);if (minor == dev.dsp_minor) { if ((file->f_mode & FMODE_WRITE && test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) ||
@@ -791,7 +792,7 @@ static int dev_open(struct inode *inode, struct file *file) }else err = -EINVAL ; out: -unlock_kernel (); +mutex_unlock (&msnd_pinnacle_mutex);return err; }
@@ -800,14 +801,14 @@ static int dev_release(struct inode *inode, struct file *file)int minor =iminor (inode);int err =0 ; -lock_kernel (); +mutex_lock (&msnd_pinnacle_mutex);if (minor == dev.dsp_minor) err =dsp_release (file);else if (minor == dev.mixer_minor) {/* nothing */ }else err = -EINVAL ; -unlock_kernel (); +mutex_unlock (&msnd_pinnacle_mutex);return err; }
sound/oss/sh_dac_audio.c +7 -6
@@ -16,7 +16,7 @@#include <linux/slab.h> #include <linux/fs.h> #include <linux/sound.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/soundcard.h> #include <linux/interrupt.h> #include <linux/hrtimer.h>
@@ -34,6 +34,7 @@#define BUFFER_SIZE 48000 +static DEFINE_MUTEX (sh_dac_audio_mutex);static int rate;static int empty;static char *data_buffer, *buffer_begin, *buffer_end;
@@ -163,9 +164,9 @@ static long dac_audio_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) {int ret; -lock_kernel (); +mutex_lock (&sh_dac_audio_mutex); ret =dac_audio_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&sh_dac_audio_mutex);return ret; }
@@ -229,16 +230,16 @@ static int dac_audio_open(struct inode *inode, struct file *file)if (file->f_mode &FMODE_READ )return -ENODEV ; -lock_kernel (); +mutex_lock (&sh_dac_audio_mutex);if (in_use) { -unlock_kernel (); +mutex_unlock (&sh_dac_audio_mutex);return -EBUSY ; } in_use =1 ;dac_audio_start (); -unlock_kernel (); +mutex_unlock (&sh_dac_audio_mutex);return 0 ; }
sound/oss/soundcard.c +21 -20
160 lines not on this page · raw message
sound/oss/swarm_cs4297a.c +10 -10
@@ -68,7 +68,6 @@#include <linux/delay.h> #include <linux/sound.h> #include <linux/slab.h> -#include <linux/smp_lock.h> #include <linux/soundcard.h> #include <linux/ac97_codec.h> #include <linux/pci.h>
@@ -94,6 +93,7 @@struct cs4297a_state ; +static DEFINE_MUTEX (swarm_cs4297a_mutex);static void stop_dac (struct cs4297a_state *s);static void stop_adc (struct cs4297a_state *s);static void start_dac (struct cs4297a_state *s);
@@ -1535,7 +1535,7 @@ static int cs4297a_open_mixdev(struct inode *inode, struct file *file)CS_DBGOUT (CS_FUNCTION |CS_OPEN ,4 ,printk (KERN_INFO "cs4297a: cs4297a_open_mixdev()+\n" )); -lock_kernel (); +mutex_lock (&swarm_cs4297a_mutex);list_for_each (entry, &cs4297a_devs) { s = list_entry(entry, struct cs4297a_state, list);
@@ -1547,7 +1547,7 @@ static int cs4297a_open_mixdev(struct inode *inode, struct file *file)CS_DBGOUT (CS_FUNCTION |CS_OPEN |CS_ERROR ,2 ,printk (KERN_INFO "cs4297a: cs4297a_open_mixdev()- -ENODEV\n" )); -unlock_kernel (); +mutex_unlock (&swarm_cs4297a_mutex);return -ENODEV ; }VALIDATE_STATE (s);
@@ -1555,7 +1555,7 @@ static int cs4297a_open_mixdev(struct inode *inode, struct file *file)CS_DBGOUT (CS_FUNCTION |CS_OPEN ,4 ,printk (KERN_INFO "cs4297a: cs4297a_open_mixdev()- 0\n" )); -unlock_kernel (); +mutex_unlock (&swarm_cs4297a_mutex);return nonseekable_open (inode, file); }
@@ -1575,10 +1575,10 @@ static int cs4297a_ioctl_mixdev(struct file *file, unsigned int cmd, unsigned long arg) { int ret; -lock_kernel (); +mutex_lock (&swarm_cs4297a_mutex); ret =mixer_ioctl ((struct cs4297a_state *) file->private_data, cmd, arg); -unlock_kernel (); +mutex_unlock (&swarm_cs4297a_mutex);return ret; }
@@ -2350,9 +2350,9 @@ static long cs4297a_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) {int ret; -lock_kernel (); +mutex_lock (&swarm_cs4297a_mutex); ret =cs4297a_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&swarm_cs4297a_mutex);return ret; }
@@ -2509,9 +2509,9 @@ static int cs4297a_open(struct inode *inode, struct file *file) {int ret; -lock_kernel (); +mutex_lock (&swarm_cs4297a_mutex); ret =cs4297a_open (inode, file); -unlock_kernel (); +mutex_unlock (&swarm_cs4297a_mutex);return ret; }
sound/oss/vwsnd.c +15 -15
@@ -145,7 +145,6 @@#include <linux/init.h> #include <linux/spinlock.h> -#include <linux/smp_lock.h> #include <linux/wait.h> #include <linux/interrupt.h> #include <linux/mutex.h>
@@ -160,6 +159,7 @@#ifdef VWSND_DEBUG +static DEFINE_MUTEX (vwsnd_mutex);static int shut_up =1 ;/*
@@ -2891,11 +2891,11 @@ static long vwsnd_audio_ioctl(struct file *file,vwsnd_dev_t *devc = (vwsnd_dev_t *) file->private_data;int ret; -lock_kernel (); +mutex_lock (&vwsnd_mutex);mutex_lock (&devc->io_mutex); ret =vwsnd_audio_do_ioctl (file, cmd, arg);mutex_unlock (&devc->io_mutex); -unlock_kernel (); +mutex_unlock (&vwsnd_mutex);return ret; }
@@ -2922,7 +2922,7 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file)DBGE ("(inode=0x%p, file=0x%p)\n" , inode, file); -lock_kernel (); +mutex_lock (&vwsnd_mutex);INC_USE_COUNT ;for (devc = vwsnd_dev_list; devc; devc = devc->next_dev)if ((devc->audio_minor & ~0x0F ) == (minor & ~0x0F ))
@@ -2930,7 +2930,7 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file)if (devc ==NULL ) {DEC_USE_COUNT ; -unlock_kernel (); +mutex_unlock (&vwsnd_mutex);return -ENODEV ; }
@@ -2939,13 +2939,13 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file)mutex_unlock (&devc->open_mutex);if (file->f_flags &O_NONBLOCK ) {DEC_USE_COUNT ; -unlock_kernel (); +mutex_unlock (&vwsnd_mutex);return -EBUSY ; }interruptible_sleep_on (&devc->open_wait);if (signal_pending (current)) {DEC_USE_COUNT ; -unlock_kernel (); +mutex_unlock (&vwsnd_mutex);return -ERESTARTSYS ; }mutex_lock (&devc->open_mutex);
@@ -2998,7 +2998,7 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file) file->private_data = devc;DBGRV (); -unlock_kernel (); +mutex_unlock (&vwsnd_mutex);return 0 ; }
@@ -3012,7 +3012,7 @@ static int vwsnd_audio_release(struct inode *inode, struct file *file)vwsnd_port_t *wport =NULL , *rport =NULL ;int err =0 ; -lock_kernel (); +mutex_lock (&vwsnd_mutex);mutex_lock (&devc->io_mutex); {DBGEV ("(inode=0x%p, file=0x%p)\n" , inode, file);
@@ -3040,7 +3040,7 @@ static int vwsnd_audio_release(struct inode *inode, struct file *file)wake_up (&devc->open_wait);DEC_USE_COUNT ;DBGR (); -unlock_kernel (); +mutex_unlock (&vwsnd_mutex);return err; }
@@ -3068,18 +3068,18 @@ static int vwsnd_mixer_open(struct inode *inode, struct file *file)DBGEV ("(inode=0x%p, file=0x%p)\n" , inode, file);INC_USE_COUNT ; -lock_kernel (); +mutex_lock (&vwsnd_mutex);for (devc = vwsnd_dev_list; devc; devc = devc->next_dev)if (devc->mixer_minor ==iminor (inode))break ;if (devc ==NULL ) {DEC_USE_COUNT ; -unlock_kernel (); +mutex_unlock (&vwsnd_mutex);return -ENODEV ; } file->private_data = devc; -unlock_kernel (); +mutex_unlock (&vwsnd_mutex);return 0 ; }
@@ -3223,7 +3223,7 @@ static long vwsnd_mixer_ioctl(struct file *file,DBGEV ("(devc=0x%p, cmd=0x%x, arg=0x%lx)\n" , devc, cmd, arg); -lock_kernel (); +mutex_lock (&vwsnd_mutex);mutex_lock (&devc->mix_mutex); {if ((cmd & ~nrmask) ==MIXER_READ (0 ))
@@ -3234,7 +3234,7 @@ static long vwsnd_mixer_ioctl(struct file *file, retval = -EINVAL ; }mutex_unlock (&devc->mix_mutex); -unlock_kernel (); +mutex_unlock (&vwsnd_mutex);return retval; }
Signature · 1 line
1.7.1
Re: [PATCH 6/7] sound: autoconvert trivial BKL users to private mutex
At Tue, 14 Sep 2010 21:53:41 +0200,
Quoted 26 lines · Arnd Bergmann
The usage of the BKL in the OSS sound drivers is trivial, and each of them only locks against itself, so it can be turned into per-driver mutexes.
This is the script that was used for the conversion:
file=$1
name=$2
if grep -qlock_kernel${file} ; thenif grep -q 'include.*linux.mutex.h' ${file} ; then sed -i '/include.*<linux\/smp_lock.h>/d' ${file} else sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file} fi sed -i ${file} \ -e "/^#include.*linux.mutex.h/,$ { 1,/^\(static\|int\|long\)/ { /^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);} }" \ -e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \ -e '/[ ]*cycle_kernel_lock();/d' else sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \ -e '/cycle_kernel_lock()/d'
Quoted 4 lines
fi
Signed-off-by Arnd Bergmann <[email protected]>Cc Takashi Iwai <[email protected]>
Through a quick look over the patch and the actual driver codes, I found no obvious problems, so I applied it now to sound git tree.
thanks,
Takashi
Arnd Bergmann
maintainerRe: [PATCH 6/7] sound: autoconvert trivial BKL users to private mutex
Quoted 5 lines · On Tuesday 14 September 2010 23:16:43 Takashi Iwai wrote:
Quoted 2 lines
Signed-off-by Arnd Bergmann <[email protected]>Cc Takashi Iwai <[email protected]>Through a quick look over the patch and the actual driver codes, I found no obvious problems, so I applied it now to sound git tree.
Ok, dropped from my tree.
Arnd
Arnd Bergmann
maintainerPATCH 7/7 block: autoconvert trivial BKL users to private mutex
In reply to Arnd BergmannThe block device drivers have all gained new lock_kernel calls from a recent pushdown, and some of the drivers were already using the BKL before.
This turns the BKL into a set of per-driver mutexes. Still need to check whether this is safe to do.
file=$1
name=$2
if grep -q lock_kernel ${file} ; then
if grep -q 'include.*linux.mutex.h' ${file} ; then
sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
else
sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
fi
sed -i ${file} \
-e "/^#include.*linux.mutex.h/,$ {
1,/^\(static\|int\|long\)/ {
/^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);} }" \
-e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
-e '/[ ]*cycle_kernel_lock();/d'
else
sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \
-e '/cycle_kernel_lock()/d'fi
--- block/bsg.c | 3 --- drivers/block/DAC960.c | 11 ++++++----- drivers/block/amiflop.c | 19 ++++++++++--------- drivers/block/aoe/aoeblk.c | 9 +++++---- drivers/block/aoe/aoechr.c | 9 +++++---- drivers/block/ataflop.c | 15 ++++++++------- drivers/block/brd.c | 7 ++++--- drivers/block/cciss.c | 14 +++++++------- drivers/block/cpqarray.c | 15 ++++++++------- drivers/block/drbd/drbd_main.c | 11 ++++++----- drivers/block/floppy.c | 16 ++++++++-------- drivers/block/loop.c | 11 ++++++----- drivers/block/nbd.c | 7 ++++--- drivers/block/paride/pcd.c | 15 ++++++++------- drivers/block/paride/pd.c | 15 ++++++++------- drivers/block/paride/pf.c | 17 +++++++++-------- drivers/block/pktcdvd.c | 16 ++++++++-------- drivers/block/swim.c | 15 ++++++++------- drivers/block/swim3.c | 15 ++++++++------- drivers/block/ub.c | 15 ++++++++------- drivers/block/viodasd.c | 11 ++++++----- drivers/block/virtio_blk.c | 7 ++++--- drivers/block/xd.c | 7 ++++--- drivers/block/xen-blkfront.c | 11 ++++++----- drivers/block/xsysace.c | 11 ++++++----- drivers/block/z2ram.c | 15 ++++++++------- drivers/cdrom/gdrom.c | 15 ++++++++------- drivers/cdrom/viocd.c | 15 ++++++++------- drivers/ide/ide-cd.c | 14 +++++++------- drivers/ide/ide-disk_ioctl.c | 7 ++++--- drivers/ide/ide-floppy_ioctl.c | 7 ++++--- drivers/ide/ide-gd.c | 10 +++++----- drivers/ide/ide-tape.c | 19 +++++++++---------- drivers/md/dm.c | 10 +++++----- drivers/md/md.c | 13 +++++++------ drivers/memstick/core/mspro_block.c | 11 ++++++----- drivers/message/i2o/i2o_block.c | 15 ++++++++------- drivers/mmc/card/block.c | 10 +++++----- drivers/mtd/mtd_blkdevs.c | 14 +++++++------- drivers/s390/char/tape_block.c | 13 +++++++------ drivers/scsi/sr.c | 14 +++++++------- drivers/scsi/st.c | 12 ++++++------ drivers/staging/hv/blkvsc_drv.c | 11 ++++++----- drivers/staging/spectra/ffsport.c | 7 ++++--- 44 files changed, 281 insertions(+), 253 deletions(-)
block/bsg.c +0 -3
@@ -20,7 +20,6 @@#include <linux/uio.h> #include <linux/idr.h> #include <linux/bsg.h> -#include <linux/smp_lock.h> #include <linux/slab.h> #include <scsi/scsi.h>
@@ -843,9 +842,7 @@ static int bsg_open(struct inode *inode, struct file *file) {struct bsg_device *bd; -lock_kernel (); bd =bsg_get_device (inode, file); -unlock_kernel ();if (IS_ERR (bd))return PTR_ERR (bd);
drivers/block/DAC960.c +6 -5
@@ -36,7 +36,7 @@#include <linux/ioport.h> #include <linux/mm.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/reboot.h>
@@ -54,6 +54,7 @@#define DAC960_GAM_MINOR 252 +static DEFINE_MUTEX (DAC960_mutex);static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];static int DAC960_ControllerCount;static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
@@ -81,7 +82,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)int drive_nr = (long )disk->private_data;int ret = -ENXIO ; -lock_kernel (); +mutex_lock (&DAC960_mutex);if (p->FirmwareType == DAC960_V1_Controller) {if (p->V1.LogicalDriveInformation[drive_nr]. LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
@@ -99,7 +100,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode) goto out; ret =0 ; out: -unlock_kernel (); +mutex_unlock (&DAC960_mutex);return ret; }
@@ -6625,7 +6626,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,long ErrorCode =0 ;if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -lock_kernel (); +mutex_lock (&DAC960_mutex);switch (Request) {case DAC960_IOCTL_GET_CONTROLLER_COUNT :
@@ -7056,7 +7057,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,default : ErrorCode = -ENOTTY ; } -unlock_kernel (); +mutex_unlock (&DAC960_mutex);return ErrorCode; }
drivers/block/amiflop.c +10 -9
@@ -60,7 +60,7 @@#include <linux/hdreg.h> #include <linux/delay.h> #include <linux/init.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/amifdreg.h> #include <linux/amifd.h> #include <linux/buffer_head.h>
@@ -109,6 +109,7 @@#define FD_HD_3 0x55555555/* high-density 3.5" (1760K) drive */ #define FD_DD_5 0xaaaaaaaa/* double-density 5.25" (440K) drive */ +static DEFINE_MUTEX (amiflop_mutex);static unsigned long int fd_def_df0 =FD_DD_3 ;/* default for df0 if it doesn't identify */ module_param (fd_def_df0, ulong,0 );
@@ -1506,9 +1507,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, {int ret; -lock_kernel (); +mutex_lock (&amiflop_mutex); ret =fd_locked_ioctl (bdev, mode, cmd, param); -unlock_kernel (); +mutex_unlock (&amiflop_mutex);return ret; }
@@ -1555,11 +1556,11 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)int old_dev;unsigned long flags; -lock_kernel (); +mutex_lock (&amiflop_mutex); old_dev = fd_device[drive];if (fd_ref[drive] && old_dev != system) { -unlock_kernel (); +mutex_unlock (&amiflop_mutex);return -EBUSY ; }
@@ -1575,7 +1576,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)rel_fdc ();if (wrprot) { -unlock_kernel (); +mutex_unlock (&amiflop_mutex);return -EROFS ; } }
@@ -1594,7 +1595,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)printk (KERN_INFO "fd%d: accessing %s-disk with %s-layout\n" ,drive, unit[drive].type->name, data_types[system].name); -unlock_kernel (); +mutex_unlock (&amiflop_mutex);return 0 ; }
@@ -1603,7 +1604,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)struct amiga_floppy_struct *p = disk->private_data;int drive = p - unit; -lock_kernel (); +mutex_lock (&amiflop_mutex);if (unit[drive].dirty ==1 ) {del_timer (flush_track_timer + drive);non_int_flush_track (drive);
@@ -1617,7 +1618,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)/* the mod_use counter is handled this way */ floppy_off (drive |0x40000000 );#endif -unlock_kernel (); +mutex_unlock (&amiflop_mutex);return 0 ; }
drivers/block/aoe/aoeblk.c +5 -4
@@ -12,9 +12,10 @@#include <linux/slab.h> #include <linux/genhd.h> #include <linux/netdevice.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include "aoe.h" +static DEFINE_MUTEX (aoeblk_mutex);static struct kmem_cache *buf_pool_cache; static ssize_t aoedisk_show_state(struct device *dev,
@@ -125,16 +126,16 @@ aoeblk_open(struct block_device *bdev, fmode_t mode)struct aoedev *d = bdev->bd_disk->private_data;ulong flags; -lock_kernel (); +mutex_lock (&aoeblk_mutex);spin_lock_irqsave (&d->lock, flags);if (d->flags &DEVFL_UP ) { d->nopen++;spin_unlock_irqrestore (&d->lock, flags); -unlock_kernel (); +mutex_unlock (&aoeblk_mutex);return 0 ; }spin_unlock_irqrestore (&d->lock, flags); -unlock_kernel (); +mutex_unlock (&aoeblk_mutex);return -ENODEV ; }
drivers/block/aoe/aoechr.c +5 -4
@@ -9,7 +9,7 @@#include <linux/completion.h> #include <linux/delay.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/skbuff.h> #include "aoe.h"
@@ -37,6 +37,7 @@ struct ErrMsg {char *msg; }; +static DEFINE_MUTEX (aoechr_mutex);static struct ErrMsg emsgs[NMSG ];static int emsgs_head_idx, emsgs_tail_idx;static struct completion emsgs_comp;
@@ -183,16 +184,16 @@ aoechr_open(struct inode *inode, struct file *filp) {int n, i; -lock_kernel (); +mutex_lock (&aoechr_mutex); n =iminor (inode); filp->private_data = (void *) (unsigned long ) n;for (i =0 ; i <ARRAY_SIZE (chardevs); ++i)if (chardevs[i].minor == n) { -unlock_kernel (); +mutex_unlock (&aoechr_mutex);return 0 ; } -unlock_kernel (); +mutex_unlock (&aoechr_mutex);return -EINVAL ; }
drivers/block/ataflop.c +8 -7
@@ -67,7 +67,7 @@#include <linux/delay.h> #include <linux/init.h> #include <linux/blkdev.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/atafd.h> #include <asm/atafdreg.h>
@@ -79,6 +79,7 @@#undef DEBUG +static DEFINE_MUTEX (ataflop_mutex);static struct request_queue *floppy_queue;static struct request *fd_request;
@@ -1671,9 +1672,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, {int ret; -lock_kernel (); +mutex_lock (&ataflop_mutex); ret =fd_locked_ioctl (bdev, mode, cmd, arg); -unlock_kernel (); +mutex_unlock (&ataflop_mutex);return ret; }
@@ -1854,9 +1855,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&ataflop_mutex); ret =floppy_open (bdev, mode); -unlock_kernel (); +mutex_unlock (&ataflop_mutex);return ret; }
@@ -1864,14 +1865,14 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)static int floppy_release (struct gendisk *disk,fmode_t mode) {struct atari_floppy_struct *p = disk->private_data; -lock_kernel (); +mutex_lock (&ataflop_mutex);if (p->ref <0 ) p->ref =0 ;else if (!p->ref--) {printk (KERN_ERR "floppy_release with fd_ref == 0" ); p->ref =0 ; } -unlock_kernel (); +mutex_unlock (&ataflop_mutex);return 0 ; }
drivers/block/brd.c +4 -3
@@ -15,7 +15,7 @@#include <linux/blkdev.h> #include <linux/bio.h> #include <linux/highmem.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/radix-tree.h> #include <linux/buffer_head.h> /* invalidate_bh_lrus() */ #include <linux/slab.h>
@@ -55,6 +55,7 @@ struct brd_device {/* * Look up and return a brd's page for a given sector. */ +static DEFINE_MUTEX (brd_mutex);static struct page *brd_lookup_page (struct brd_device *brd,sector_t sector) {pgoff_t idx;
@@ -402,7 +403,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,* ram device BLKFLSBUF has special semantics, we want to actually * release and destroy the ramdisk data. */ -lock_kernel (); +mutex_lock (&brd_mutex);mutex_lock (&bdev->bd_mutex); error = -EBUSY ;if (bdev->bd_openers <=1 ) {
@@ -419,7 +420,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode, error =0 ; }mutex_unlock (&bdev->bd_mutex); -unlock_kernel (); +mutex_unlock (&brd_mutex);return error; }
drivers/block/cciss.c +7 -7
@@ -26,7 +26,6 @@#include <linux/pci.h> #include <linux/kernel.h> #include <linux/slab.h> -#include <linux/smp_lock.h> #include <linux/delay.h> #include <linux/major.h> #include <linux/fs.h>
@@ -66,6 +65,7 @@ MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");MODULE_VERSION ("3.6.26" );MODULE_LICENSE ("GPL" ); +static DEFINE_MUTEX (cciss_mutex);static int cciss_allow_hpsa;module_param (cciss_allow_hpsa, int,S_IRUGO |S_IWUSR ); MODULE_PARM_DESC(cciss_allow_hpsa,
@@ -1057,9 +1057,9 @@ static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&cciss_mutex); ret =cciss_open (bdev, mode); -unlock_kernel (); +mutex_unlock (&cciss_mutex);return ret; }
@@ -1072,13 +1072,13 @@ static int cciss_release(struct gendisk *disk, fmode_t mode)ctlr_info_t *h;drive_info_struct *drv; -lock_kernel (); +mutex_lock (&cciss_mutex); h =get_host (disk); drv =get_drv (disk);dev_dbg (&h->pdev->dev,"cciss_release %s\n" , disk->disk_name); drv->usage_count--; h->usage_count--; -unlock_kernel (); +mutex_unlock (&cciss_mutex);return 0 ; }
@@ -1086,9 +1086,9 @@ static int do_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, unsigned long arg) { int ret; -lock_kernel (); +mutex_lock (&cciss_mutex); ret =cciss_ioctl (bdev, mode, cmd, arg); -unlock_kernel (); +mutex_unlock (&cciss_mutex);return ret; }
drivers/block/cpqarray.c +8 -7
@@ -35,7 +35,7 @@#include <linux/seq_file.h> #include <linux/init.h> #include <linux/hdreg.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/spinlock.h> #include <linux/blkdev.h> #include <linux/genhd.h>
@@ -68,6 +68,7 @@ MODULE_LICENSE("GPL");#define CPQARRAY_DMA_MASK 0xFFFFFFFF/* 32 bit DMA */ +static DEFINE_MUTEX (cpqarray_mutex);static int nr_ctlr;static ctlr_info_t *hba[MAX_CTLR ];
@@ -845,9 +846,9 @@ static int ida_unlocked_open(struct block_device *bdev, fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&cpqarray_mutex); ret =ida_open (bdev, mode); -unlock_kernel (); +mutex_unlock (&cpqarray_mutex);return ret; }
@@ -859,10 +860,10 @@ static int ida_release(struct gendisk *disk, fmode_t mode) {ctlr_info_t *host; -lock_kernel (); +mutex_lock (&cpqarray_mutex); host =get_host (disk); host->usage_count--; -unlock_kernel (); +mutex_unlock (&cpqarray_mutex);return 0 ; }
@@ -1217,9 +1218,9 @@ static int ida_ioctl(struct block_device *bdev, fmode_t mode, {int ret; -lock_kernel (); +mutex_lock (&cpqarray_mutex); ret =ida_locked_ioctl (bdev, mode, cmd, param); -unlock_kernel (); +mutex_unlock (&cpqarray_mutex);return ret; }
drivers/block/drbd/drbd_main.c +6 -5
@@ -32,7 +32,7 @@#include <asm/types.h> #include <net/sock.h> #include <linux/ctype.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/fs.h> #include <linux/file.h> #include <linux/proc_fs.h>
@@ -64,6 +64,7 @@ struct after_state_chg_work {struct completion *done; }; +static DEFINE_MUTEX (drbd_main_mutex);int drbdd_init (struct drbd_thread *);int drbd_worker (struct drbd_thread *);int drbd_asender (struct drbd_thread *);
@@ -2536,7 +2537,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)unsigned long flags;int rv =0 ; -lock_kernel (); +mutex_lock (&drbd_main_mutex);spin_lock_irqsave (&mdev->req_lock, flags);/* to have a stable mdev->state.role * and no race with updating open_cnt */
@@ -2551,7 +2552,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)if (!rv) mdev->open_cnt++;spin_unlock_irqrestore (&mdev->req_lock, flags); -unlock_kernel (); +mutex_unlock (&drbd_main_mutex);return rv; }
@@ -2559,9 +2560,9 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)static int drbd_release (struct gendisk *gd,fmode_t mode) {struct drbd_conf *mdev = gd->private_data; -lock_kernel (); +mutex_lock (&drbd_main_mutex); mdev->open_cnt--; -unlock_kernel (); +mutex_unlock (&drbd_main_mutex);return 0 ; }
drivers/block/floppy.c +8 -8
@@ -178,7 +178,6 @@ static int print_unex = 1;#include <linux/slab.h> #include <linux/mm.h> #include <linux/bio.h> -#include <linux/smp_lock.h> #include <linux/string.h> #include <linux/jiffies.h> #include <linux/fcntl.h>
@@ -199,6 +198,7 @@ static int print_unex = 1;* It's been recommended that take about 1/4 of the default speed * in some more extreme cases. */ +static DEFINE_MUTEX (floppy_mutex);static int slow_floppy;#include <asm/dma.h>
@@ -3553,9 +3553,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, {int ret; -lock_kernel (); +mutex_lock (&floppy_mutex); ret =fd_locked_ioctl (bdev, mode, cmd, param); -unlock_kernel (); +mutex_unlock (&floppy_mutex);return ret; }
@@ -3616,7 +3616,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode) {int drive = (long )disk->private_data; -lock_kernel (); +mutex_lock (&floppy_mutex);mutex_lock (&open_lock);if (UDRS ->fd_ref <0 )UDRS ->fd_ref =0 ;
@@ -3627,7 +3627,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)if (!UDRS ->fd_ref) opened_bdev[drive] =NULL ;mutex_unlock (&open_lock); -unlock_kernel (); +mutex_unlock (&floppy_mutex);return 0 ; }
@@ -3645,7 +3645,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)int res = -EBUSY ;char *tmp; -lock_kernel (); +mutex_lock (&floppy_mutex);mutex_lock (&open_lock); old_dev =UDRS ->fd_device;if (opened_bdev[drive] && opened_bdev[drive] != bdev)
@@ -3722,7 +3722,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) goto out; }mutex_unlock (&open_lock); -unlock_kernel (); +mutex_unlock (&floppy_mutex);return 0 ; out:if (UDRS ->fd_ref <0 )
@@ -3733,7 +3733,7 @@ out: opened_bdev[drive] =NULL ; out2:mutex_unlock (&open_lock); -unlock_kernel (); +mutex_unlock (&floppy_mutex);return res; }
drivers/block/loop.c +6 -5
@@ -67,7 +67,7 @@#include <linux/compat.h> #include <linux/suspend.h> #include <linux/freezer.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/writeback.h> #include <linux/buffer_head.h> /* for invalidate_bdev() */ #include <linux/completion.h>
@@ -77,6 +77,7 @@#include <asm/uaccess.h> +static DEFINE_MUTEX (loop_mutex);static LIST_HEAD (loop_devices);static DEFINE_MUTEX (loop_devices_mutex);
@@ -1409,11 +1410,11 @@ static int lo_open(struct block_device *bdev, fmode_t mode) {struct loop_device *lo = bdev->bd_disk->private_data; -lock_kernel (); +mutex_lock (&loop_mutex);mutex_lock (&lo->lo_ctl_mutex); lo->lo_refcnt++;mutex_unlock (&lo->lo_ctl_mutex); -unlock_kernel (); +mutex_unlock (&loop_mutex);return 0 ; }
@@ -1423,7 +1424,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)struct loop_device *lo = disk->private_data;int err; -lock_kernel (); +mutex_lock (&loop_mutex);mutex_lock (&lo->lo_ctl_mutex);if (--lo->lo_refcnt)
@@ -1448,7 +1449,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode) out:mutex_unlock (&lo->lo_ctl_mutex); out_unlocked: -lock_kernel (); +mutex_unlock (&loop_mutex);return 0 ; }
drivers/block/nbd.c +4 -3
@@ -24,7 +24,7 @@#include <linux/errno.h> #include <linux/file.h> #include <linux/ioctl.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/compiler.h> #include <linux/err.h> #include <linux/kernel.h>
@@ -53,6 +53,7 @@#define DBG_BLKDEV 0x0100#define DBG_RX 0x0200#define DBG_TX 0x0400 +static DEFINE_MUTEX (nbd_mutex);static unsigned int debugflags;#endif /* NDEBUG */
@@ -717,11 +718,11 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,dprintk (DBG_IOCTL ,"%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n" , lo->disk->disk_name,ioctl_cmd_to_ascii (cmd), cmd, arg); -lock_kernel (); +mutex_lock (&nbd_mutex);mutex_lock (&lo->tx_lock); error =__nbd_ioctl (bdev, lo, cmd, arg);mutex_unlock (&lo->tx_lock); -unlock_kernel (); +mutex_unlock (&nbd_mutex);return error; }
drivers/block/paride/pcd.c +8 -7
@@ -138,9 +138,10 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};#include <linux/cdrom.h> #include <linux/spinlock.h> #include <linux/blkdev.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/uaccess.h> +static DEFINE_MUTEX (pcd_mutex);static DEFINE_SPINLOCK (pcd_lock);module_param (verbose, bool,0644 );
@@ -227,9 +228,9 @@ static int pcd_block_open(struct block_device *bdev, fmode_t mode)struct pcd_unit *cd = bdev->bd_disk->private_data;int ret; -lock_kernel (); +mutex_lock (&pcd_mutex); ret =cdrom_open (&cd->info, bdev, mode); -unlock_kernel (); +mutex_unlock (&pcd_mutex);return ret; }
@@ -237,9 +238,9 @@ static int pcd_block_open(struct block_device *bdev, fmode_t mode)static int pcd_block_release (struct gendisk *disk,fmode_t mode) {struct pcd_unit *cd = disk->private_data; -lock_kernel (); +mutex_lock (&pcd_mutex);cdrom_release (&cd->info, mode); -unlock_kernel (); +mutex_unlock (&pcd_mutex);return 0 ; }
@@ -249,9 +250,9 @@ static int pcd_block_ioctl(struct block_device *bdev, fmode_t mode,struct pcd_unit *cd = bdev->bd_disk->private_data;int ret; -lock_kernel (); +mutex_lock (&pcd_mutex); ret =cdrom_ioctl (&cd->info, bdev, mode, cmd, arg); -unlock_kernel (); +mutex_unlock (&pcd_mutex);return ret; }
drivers/block/paride/pd.c +8 -7
@@ -153,10 +153,11 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_GEO, D_SBY, D_DLY, D_SLV};#include <linux/blkdev.h> #include <linux/blkpg.h> #include <linux/kernel.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/uaccess.h> #include <linux/workqueue.h> +static DEFINE_MUTEX (pd_mutex);static DEFINE_SPINLOCK (pd_lock);module_param (verbose, bool,0 );
@@ -736,14 +737,14 @@ static int pd_open(struct block_device *bdev, fmode_t mode) {struct pd_unit *disk = bdev->bd_disk->private_data; -lock_kernel (); +mutex_lock (&pd_mutex); disk->access++;if (disk->removable) {pd_special_command (disk, pd_media_check);pd_special_command (disk, pd_door_lock); } -unlock_kernel (); +mutex_unlock (&pd_mutex);return 0 ; }
@@ -771,10 +772,10 @@ static int pd_ioctl(struct block_device *bdev, fmode_t mode,switch (cmd) {case CDROMEJECT : -lock_kernel (); +mutex_lock (&pd_mutex);if (disk->access ==1 )pd_special_command (disk, pd_eject); -unlock_kernel (); +mutex_unlock (&pd_mutex);return 0 ;default :return -EINVAL ;
@@ -785,10 +786,10 @@ static int pd_release(struct gendisk *p, fmode_t mode) {struct pd_unit *disk = p->private_data; -lock_kernel (); +mutex_lock (&pd_mutex);if (!--disk->access && disk->removable)pd_special_command (disk, pd_door_unlock); -unlock_kernel (); +mutex_unlock (&pd_mutex);return 0 ; }
drivers/block/paride/pf.c +9 -8
@@ -152,9 +152,10 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_LUN, D_DLY};#include <linux/spinlock.h> #include <linux/blkdev.h> #include <linux/blkpg.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/uaccess.h> +static DEFINE_MUTEX (pf_mutex);static DEFINE_SPINLOCK (pf_spin_lock);module_param (verbose, bool,0644 );
@@ -302,7 +303,7 @@ static int pf_open(struct block_device *bdev, fmode_t mode)struct pf_unit *pf = bdev->bd_disk->private_data;int ret; -lock_kernel (); +mutex_lock (&pf_mutex);pf_identify (pf); ret = -ENODEV ;
@@ -318,7 +319,7 @@ static int pf_open(struct block_device *bdev, fmode_t mode)if (pf->removable)pf_lock (pf,1 ); out: -unlock_kernel (); +mutex_unlock (&pf_mutex);return ret; }
@@ -349,9 +350,9 @@ static int pf_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, uif (pf->access !=1 )return -EBUSY ; -lock_kernel (); +mutex_lock (&pf_mutex);pf_eject (pf); -unlock_kernel (); +mutex_unlock (&pf_mutex);return 0 ; }
@@ -360,9 +361,9 @@ static int pf_release(struct gendisk *disk, fmode_t mode) {struct pf_unit *pf = disk->private_data; -lock_kernel (); +mutex_lock (&pf_mutex);if (pf->access <=0 ) { -unlock_kernel (); +mutex_unlock (&pf_mutex);return -EINVAL ; }
@@ -371,7 +372,7 @@ static int pf_release(struct gendisk *disk, fmode_t mode)if (!pf->access && pf->removable)pf_lock (pf,0 ); -unlock_kernel (); +mutex_unlock (&pf_mutex);return 0 ; }
drivers/block/pktcdvd.c +8 -8
@@ -57,7 +57,6 @@#include <linux/seq_file.h> #include <linux/miscdevice.h> #include <linux/freezer.h> -#include <linux/smp_lock.h> #include <linux/mutex.h> #include <linux/slab.h> #include <scsi/scsi_cmnd.h>
@@ -86,6 +85,7 @@#define ZONE (sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1)) +static DEFINE_MUTEX (pktcdvd_mutex);static struct pktcdvd_device *pkt_devs[MAX_WRITERS ];static struct proc_dir_entry *pkt_proc;static int pktdev_major;
@@ -2383,7 +2383,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode)VPRINTK (DRIVER_NAME ": entering open\n" ); -lock_kernel (); +mutex_lock (&pktcdvd_mutex);mutex_lock (&ctl_mutex); pd =pkt_find_dev_from_minor (MINOR (bdev->bd_dev));if (!pd) {
@@ -2411,7 +2411,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode) }mutex_unlock (&ctl_mutex); -unlock_kernel (); +mutex_unlock (&pktcdvd_mutex);return 0 ; out_dec:
@@ -2419,7 +2419,7 @@ out_dec: out:VPRINTK (DRIVER_NAME ": failed open (%d)\n" , ret);mutex_unlock (&ctl_mutex); -unlock_kernel (); +mutex_unlock (&pktcdvd_mutex);return ret; }
@@ -2428,7 +2428,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)struct pktcdvd_device *pd = disk->private_data;int ret =0 ; -lock_kernel (); +mutex_lock (&pktcdvd_mutex);mutex_lock (&ctl_mutex); pd->refcnt--;BUG_ON (pd->refcnt <0 );
@@ -2437,7 +2437,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)pkt_release_dev (pd, flush); }mutex_unlock (&ctl_mutex); -unlock_kernel (); +mutex_unlock (&pktcdvd_mutex);return ret; }
@@ -2773,7 +2773,7 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,VPRINTK ("pkt_ioctl: cmd %x, dev %d:%d\n" , cmd,MAJOR (bdev->bd_dev),MINOR (bdev->bd_dev)); -lock_kernel (); +mutex_lock (&pktcdvd_mutex);switch (cmd) {case CDROMEJECT :/*
@@ -2798,7 +2798,7 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,VPRINTK (DRIVER_NAME ": Unknown ioctl for %s (%x)\n" , pd->name, cmd); ret = -ENOTTY ; } -unlock_kernel (); +mutex_unlock (&pktcdvd_mutex);return ret; }
drivers/block/swim.c +8 -7
@@ -20,7 +20,7 @@#include <linux/fd.h> #include <linux/slab.h> #include <linux/blkdev.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/hdreg.h> #include <linux/kernel.h> #include <linux/delay.h>
@@ -222,6 +222,7 @@ extern int swim_read_sector_header(struct swim __iomem *base,extern int swim_read_sector_data (struct swim __iomem *base,unsigned char *data); +static DEFINE_MUTEX (swim_mutex);static inline void set_swim_mode (struct swim __iomem *base,int enable) {struct iwm __iomem *iwm_base;
@@ -666,9 +667,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&swim_mutex); ret =floppy_open (bdev, mode); -unlock_kernel (); +mutex_unlock (&swim_mutex);return ret; }
@@ -678,7 +679,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)struct floppy_state *fs = disk->private_data;struct swim __iomem *base = fs->swd->base; -lock_kernel (); +mutex_lock (&swim_mutex);if (fs->ref_count <0 ) fs->ref_count =0 ;else if (fs->ref_count >0 )
@@ -686,7 +687,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)if (fs->ref_count ==0 )swim_motor (base,OFF ); -unlock_kernel (); +mutex_unlock (&swim_mutex);return 0 ; }
@@ -704,9 +705,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,case FDEJECT :if (fs->ref_count !=1 )return -EBUSY ; -lock_kernel (); +mutex_lock (&swim_mutex); err =floppy_eject (fs); -unlock_kernel (); +mutex_unlock (&swim_mutex);return err;case FDGETPRM :
drivers/block/swim3.c +8 -7
@@ -25,7 +25,7 @@#include <linux/ioctl.h> #include <linux/blkdev.h> #include <linux/interrupt.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/module.h> #include <linux/spinlock.h> #include <asm/io.h>
@@ -36,6 +36,7 @@#include <asm/machdep.h> #include <asm/pmac_feature.h> +static DEFINE_MUTEX (swim3_mutex);static struct request_queue *swim3_queue;static struct gendisk *disks[2 ];static struct request *fd_req;
@@ -873,9 +874,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode, {int ret; -lock_kernel (); +mutex_lock (&swim3_mutex); ret =floppy_locked_ioctl (bdev, mode, cmd, param); -unlock_kernel (); +mutex_unlock (&swim3_mutex);return ret; }
@@ -953,9 +954,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&swim3_mutex); ret =floppy_open (bdev, mode); -unlock_kernel (); +mutex_unlock (&swim3_mutex);return ret; }
@@ -964,13 +965,13 @@ static int floppy_release(struct gendisk *disk, fmode_t mode) {struct floppy_state *fs = disk->private_data;struct swim3 __iomem *sw = fs->swim3; -lock_kernel (); +mutex_lock (&swim3_mutex);if (fs->ref_count >0 && --fs->ref_count ==0 ) {swim3_action (fs,MOTOR_OFF );out_8 (&sw->control_bic,0xff );swim3_select (fs,RELAX ); } -unlock_kernel (); +mutex_unlock (&swim3_mutex);return 0 ; }
drivers/block/ub.c +8 -7
@@ -28,7 +28,7 @@#include <linux/timer.h> #include <linux/scatterlist.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <scsi/scsi.h> #define DRV_NAME "ub"
@@ -248,6 +248,7 @@ struct ub_completion {spinlock_t lock; }; +static DEFINE_MUTEX (ub_mutex);static inline void ub_init_completion (struct ub_completion *x) { x->done =0 ;
@@ -1715,9 +1716,9 @@ static int ub_bd_unlocked_open(struct block_device *bdev, fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&ub_mutex); ret =ub_bd_open (bdev, mode); -unlock_kernel (); +mutex_unlock (&ub_mutex);return ret; }
@@ -1730,9 +1731,9 @@ static int ub_bd_release(struct gendisk *disk, fmode_t mode)struct ub_lun *lun = disk->private_data;struct ub_dev *sc = lun->udev; -lock_kernel (); +mutex_lock (&ub_mutex);ub_put (sc); -unlock_kernel (); +mutex_unlock (&ub_mutex);return 0 ; }
@@ -1747,9 +1748,9 @@ static int ub_bd_ioctl(struct block_device *bdev, fmode_t mode,void __user *usermem = (void __user *) arg;int ret; -lock_kernel (); +mutex_lock (&ub_mutex); ret =scsi_cmd_ioctl (disk->queue, disk, mode, cmd, usermem); -unlock_kernel (); +mutex_unlock (&ub_mutex);return ret; }
drivers/block/viodasd.c +6 -5
@@ -41,7 +41,7 @@#include <linux/errno.h> #include <linux/init.h> #include <linux/string.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/dma-mapping.h> #include <linux/completion.h> #include <linux/device.h>
@@ -73,6 +73,7 @@ enum { MAX_DISK_NAME = FIELD_SIZEOF(struct gendisk, disk_name) }; +static DEFINE_MUTEX (viodasd_mutex);static DEFINE_SPINLOCK (viodasd_spinlock);#define VIOMAXREQ 16
@@ -180,9 +181,9 @@ static int viodasd_unlocked_open(struct block_device *bdev, fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&viodasd_mutex); ret =viodasd_open (bdev, mode); -unlock_kernel (); +mutex_unlock (&viodasd_mutex);return ret; }
@@ -196,7 +197,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)struct viodasd_device *d = disk->private_data;HvLpEvent_Rc hvrc; -lock_kernel (); +mutex_lock (&viodasd_mutex);/* Send the event to OS/400. We DON'T expect a response */ hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, HvLpEvent_Type_VirtualIo,
@@ -210,7 +211,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)if (hvrc !=0 )pr_warning ("HV close call failed %d\n" , (int )hvrc); -unlock_kernel (); +mutex_unlock (&viodasd_mutex);return 0 ; }
drivers/block/virtio_blk.c +4 -3
@@ -2,7 +2,7 @@#include <linux/spinlock.h> #include <linux/slab.h> #include <linux/blkdev.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/hdreg.h> #include <linux/virtio.h> #include <linux/virtio_blk.h>
@@ -10,6 +10,7 @@#define PART_BITS 4 +static DEFINE_MUTEX (virtio_blk_mutex);static int major, index;struct virtio_blk
@@ -239,9 +240,9 @@ static int virtblk_ioctl(struct block_device *bdev, fmode_t mode, {int ret; -lock_kernel (); +mutex_lock (&virtio_blk_mutex); ret =virtblk_locked_ioctl (bdev, mode, cmd, param); -unlock_kernel (); +mutex_unlock (&virtio_blk_mutex);return ret; }
drivers/block/xd.c +4 -3
@@ -46,7 +46,7 @@#include <linux/init.h> #include <linux/wait.h> #include <linux/blkdev.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/blkpg.h> #include <linux/delay.h> #include <linux/io.h>
@@ -58,6 +58,7 @@#include "xd.h" +static DEFINE_MUTEX (xd_mutex);static void __init do_xd_setup (int *integers);#ifdef MODULE static int xd[5 ] = {-1 ,-1 ,-1 ,-1 , };
@@ -381,9 +382,9 @@ static int xd_ioctl(struct block_device *bdev, fmode_t mode, {int ret; -lock_kernel (); +mutex_lock (&xd_mutex); ret =xd_locked_ioctl (bdev, mode, cmd, param); -unlock_kernel (); +mutex_unlock (&xd_mutex);return ret; }
drivers/block/xen-blkfront.c +6 -5
@@ -41,7 +41,7 @@#include <linux/cdrom.h> #include <linux/module.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/scatterlist.h> #include <xen/xen.h>
@@ -69,6 +69,7 @@ struct blk_shadow {unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST ]; }; +static DEFINE_MUTEX (blkfront_mutex);static const struct block_device_operations xlvbd_block_fops;#define BLK_RING_SIZE __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE)
@@ -1201,7 +1202,7 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)struct blkfront_info *info;int err =0 ; -lock_kernel (); +mutex_lock (&blkfront_mutex); info = disk->private_data;if (!info) {
@@ -1219,7 +1220,7 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)mutex_unlock (&info->mutex); out: -unlock_kernel (); +mutex_unlock (&blkfront_mutex);return err; }
@@ -1229,7 +1230,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)struct block_device *bdev;struct xenbus_device *xbdev; -lock_kernel (); +mutex_lock (&blkfront_mutex); bdev =bdget_disk (disk,0 );bdput (bdev);
@@ -1263,7 +1264,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode) } out: -unlock_kernel (); +mutex_unlock (&blkfront_mutex);return 0 ; }
drivers/block/xsysace.c +6 -5
@@ -89,7 +89,7 @@#include <linux/delay.h> #include <linux/slab.h> #include <linux/blkdev.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/ata.h> #include <linux/hdreg.h> #include <linux/platform_device.h>
@@ -214,6 +214,7 @@ struct ace_device {u16 cf_id[ATA_ID_WORDS ]; }; +static DEFINE_MUTEX (xsysace_mutex);static int ace_major;/* ---------------------------------------------------------------------
@@ -903,13 +904,13 @@ static int ace_open(struct block_device *bdev, fmode_t mode)dev_dbg (ace->dev,"ace_open() users=%i\n" , ace->users +1 ); -lock_kernel (); +mutex_lock (&xsysace_mutex);spin_lock_irqsave (&ace->lock, flags); ace->users++;spin_unlock_irqrestore (&ace->lock, flags);check_disk_change (bdev); -unlock_kernel (); +mutex_unlock (&xsysace_mutex);return 0 ; }
@@ -922,7 +923,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)dev_dbg (ace->dev,"ace_release() users=%i\n" , ace->users -1 ); -lock_kernel (); +mutex_lock (&xsysace_mutex);spin_lock_irqsave (&ace->lock, flags); ace->users--;if (ace->users ==0 ) {
@@ -930,7 +931,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)ace_out (ace,ACE_CTRL , val & ~ACE_CTRL_LOCKREQ ); }spin_unlock_irqrestore (&ace->lock, flags); -unlock_kernel (); +mutex_unlock (&xsysace_mutex);return 0 ; }
drivers/block/z2ram.c +8 -7
@@ -33,7 +33,7 @@#include <linux/module.h> #include <linux/blkdev.h> #include <linux/bitops.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/slab.h> #include <asm/setup.h>
@@ -57,6 +57,7 @@ extern struct mem_info m68k_memory[NUM_MEMINFO];#define Z2RAM_CHUNK1024 ( Z2RAM_CHUNKSIZE >> 10 ) +static DEFINE_MUTEX (z2ram_mutex);static u_long *z2ram_map =NULL ;static u_long z2ram_size =0 ;static int z2_count =0 ;
@@ -154,7 +155,7 @@ static int z2_open(struct block_device *bdev, fmode_t mode) device =MINOR (bdev->bd_dev); -lock_kernel (); +mutex_lock (&z2ram_mutex);if ( current_device !=-1 && current_device != device ) { rc = -EBUSY ;
@@ -296,25 +297,25 @@ static int z2_open(struct block_device *bdev, fmode_t mode)set_capacity (z2ram_gendisk, z2ram_size >>9 ); } -unlock_kernel (); +mutex_unlock (&z2ram_mutex);return 0 ; err_out_kfree:kfree (z2ram_map); err_out: -unlock_kernel (); +mutex_unlock (&z2ram_mutex);return rc; }static int z2_release (struct gendisk *disk,fmode_t mode) { -lock_kernel (); +mutex_lock (&z2ram_mutex);if ( current_device ==-1 ) { -unlock_kernel (); +mutex_unlock (&z2ram_mutex);return 0 ; } -unlock_kernel (); +mutex_unlock (&z2ram_mutex);/* * FIXME: unmap memory */
drivers/cdrom/gdrom.c +8 -7
@@ -34,7 +34,7 @@#include <linux/blkdev.h> #include <linux/interrupt.h> #include <linux/device.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/wait.h> #include <linux/workqueue.h> #include <linux/platform_device.h>
@@ -81,6 +81,7 @@#define GDROM_DEFAULT_TIMEOUT (HZ * 7) +static DEFINE_MUTEX (gdrom_mutex); static const struct { int sense_key; const char * const text;
@@ -494,17 +495,17 @@ static struct cdrom_device_ops gdrom_ops = {static int gdrom_bdops_open (struct block_device *bdev,fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&gdrom_mutex); ret =cdrom_open (gd.cd_info, bdev, mode); -unlock_kernel (); +mutex_unlock (&gdrom_mutex);return ret; }static int gdrom_bdops_release (struct gendisk *disk,fmode_t mode) { -lock_kernel (); +mutex_lock (&gdrom_mutex);cdrom_release (gd.cd_info, mode); -unlock_kernel (); +mutex_unlock (&gdrom_mutex);return 0 ; }
@@ -518,9 +519,9 @@ static int gdrom_bdops_ioctl(struct block_device *bdev, fmode_t mode, {int ret; -lock_kernel (); +mutex_lock (&gdrom_mutex); ret =cdrom_ioctl (gd.cd_info, bdev, mode, cmd, arg); -unlock_kernel (); +mutex_unlock (&gdrom_mutex);return ret; }
drivers/cdrom/viocd.c +8 -7
@@ -42,7 +42,7 @@#include <linux/module.h> #include <linux/completion.h> #include <linux/proc_fs.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/seq_file.h> #include <linux/scatterlist.h>
@@ -61,6 +61,7 @@*/ #define VIOCD_MAX_CD HVMAXARCHITECTEDVIRTUALCDROMS +static DEFINE_MUTEX (viocd_mutex);static const struct vio_error_entry viocd_err_table[] = { {0x0201 ,EINVAL ,"Invalid Range" }, {0x0202 ,EINVAL ,"Invalid Token" },
@@ -156,9 +157,9 @@ static int viocd_blk_open(struct block_device *bdev, fmode_t mode)struct disk_info *di = bdev->bd_disk->private_data;int ret; -lock_kernel (); +mutex_lock (&viocd_mutex); ret =cdrom_open (&di->viocd_info, bdev, mode); -unlock_kernel (); +mutex_unlock (&viocd_mutex);return ret; }
@@ -166,9 +167,9 @@ static int viocd_blk_open(struct block_device *bdev, fmode_t mode)static int viocd_blk_release (struct gendisk *disk,fmode_t mode) {struct disk_info *di = disk->private_data; -lock_kernel (); +mutex_lock (&viocd_mutex);cdrom_release (&di->viocd_info, mode); -unlock_kernel (); +mutex_unlock (&viocd_mutex);return 0 ; }
@@ -178,9 +179,9 @@ static int viocd_blk_ioctl(struct block_device *bdev, fmode_t mode,struct disk_info *di = bdev->bd_disk->private_data;int ret; -lock_kernel (); +mutex_lock (&viocd_mutex); ret =cdrom_ioctl (&di->viocd_info, bdev, mode, cmd, arg); -unlock_kernel (); +mutex_unlock (&viocd_mutex);return ret; }
drivers/ide/ide-cd.c +7 -7
@@ -31,7 +31,6 @@#include <linux/delay.h> #include <linux/timer.h> #include <linux/seq_file.h> -#include <linux/smp_lock.h> #include <linux/slab.h> #include <linux/interrupt.h> #include <linux/errno.h>
@@ -52,6 +51,7 @@#include "ide-cd.h" +static DEFINE_MUTEX (ide_cd_mutex);static DEFINE_MUTEX (idecd_ref_mutex);static void ide_cd_release (struct device *);
@@ -1602,7 +1602,7 @@ static int idecd_open(struct block_device *bdev, fmode_t mode)struct cdrom_info *info;int rc = -ENXIO ; -lock_kernel (); +mutex_lock (&ide_cd_mutex); info =ide_cd_get (bdev->bd_disk);if (!info) goto out;
@@ -1611,7 +1611,7 @@ static int idecd_open(struct block_device *bdev, fmode_t mode)if (rc <0 )ide_cd_put (info); out: -unlock_kernel (); +mutex_unlock (&ide_cd_mutex);return rc; }
@@ -1619,11 +1619,11 @@ static int idecd_release(struct gendisk *disk, fmode_t mode) {struct cdrom_info *info =ide_drv_g (disk, cdrom_info); -lock_kernel (); +mutex_lock (&ide_cd_mutex);cdrom_release (&info->devinfo, mode);ide_cd_put (info); -unlock_kernel (); +mutex_unlock (&ide_cd_mutex);return 0 ; }
@@ -1694,9 +1694,9 @@ static int idecd_ioctl(struct block_device *bdev, fmode_t mode, {int ret; -lock_kernel (); +mutex_lock (&ide_cd_mutex); ret =idecd_locked_ioctl (bdev, mode, cmd, arg); -unlock_kernel (); +mutex_unlock (&ide_cd_mutex);return ret; }
drivers/ide/ide-disk_ioctl.c +4 -3
@@ -1,10 +1,11 @@#include <linux/kernel.h> #include <linux/ide.h> #include <linux/hdreg.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include "ide-disk.h" +static DEFINE_MUTEX (ide_disk_ioctl_mutex);static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = { {HDIO_GET_ADDRESS ,HDIO_SET_ADDRESS , &ide_devset_address }, {HDIO_GET_MULTCOUNT ,HDIO_SET_MULTCOUNT , &ide_devset_multcount },
@@ -19,13 +20,13 @@ int ide_disk_ioctl(ide_drive_t *drive, struct block_device *bdev, fmode_t mode, {int err; -lock_kernel (); +mutex_lock (&ide_disk_ioctl_mutex); err =ide_setting_ioctl (drive, bdev, cmd, arg, ide_disk_ioctl_settings);if (err != -EOPNOTSUPP ) goto out; err =generic_ide_ioctl (drive, bdev, cmd, arg); out: -unlock_kernel (); +mutex_unlock (&ide_disk_ioctl_mutex);return err; }
drivers/ide/ide-floppy_ioctl.c +4 -3
@@ -5,7 +5,7 @@#include <linux/kernel.h> #include <linux/ide.h> #include <linux/cdrom.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <asm/unaligned.h>
@@ -32,6 +32,7 @@* On exit we set nformats to the number of records we've actually initialized. */ +static DEFINE_MUTEX (ide_floppy_ioctl_mutex);static int ide_floppy_get_format_capacities (ide_drive_t *drive,struct ide_atapi_pc *pc,int __user *arg)
@@ -276,7 +277,7 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,void __user *argp = (void __user *)arg;int err; -lock_kernel (); +mutex_lock (&ide_floppy_ioctl_mutex);if (cmd ==CDROMEJECT || cmd ==CDROM_LOCKDOOR ) { err =ide_floppy_lockdoor (drive, &pc, arg, cmd); goto out;
@@ -298,6 +299,6 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev, err =generic_ide_ioctl (drive, bdev, cmd, arg); out: -unlock_kernel (); +mutex_unlock (&ide_floppy_ioctl_mutex);return err; }
drivers/ide/ide-gd.c +5 -5
@@ -1,4 +1,3 @@ -#include <linux/smp_lock.h> #include <linux/module.h> #include <linux/types.h> #include <linux/string.h>
@@ -23,6 +22,7 @@#define IDE_GD_VERSION "1.18"/* module parameters */ +static DEFINE_MUTEX (ide_gd_mutex);static unsigned long debug_mask;module_param (debug_mask, ulong,0644 );
@@ -242,9 +242,9 @@ static int ide_gd_unlocked_open(struct block_device *bdev, fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&ide_gd_mutex); ret =ide_gd_open (bdev, mode); -unlock_kernel (); +mutex_unlock (&ide_gd_mutex);return ret; }
@@ -257,7 +257,7 @@ static int ide_gd_release(struct gendisk *disk, fmode_t mode)ide_debug_log (IDE_DBG_FUNC ,"enter" ); -lock_kernel (); +mutex_lock (&ide_gd_mutex);if (idkp->openers ==1 ) drive->disk_ops->flush (drive);
@@ -269,7 +269,7 @@ static int ide_gd_release(struct gendisk *disk, fmode_t mode) idkp->openers--;ide_disk_put (idkp); -unlock_kernel (); +mutex_unlock (&ide_gd_mutex);return 0 ; }
drivers/ide/ide-tape.c +9 -10
@@ -32,11 +32,9 @@#include <linux/errno.h> #include <linux/genhd.h> #include <linux/seq_file.h> -#include <linux/smp_lock.h> #include <linux/slab.h> #include <linux/pci.h> #include <linux/ide.h> -#include <linux/smp_lock.h> #include <linux/completion.h> #include <linux/bitops.h> #include <linux/mutex.h>
@@ -220,6 +218,7 @@ typedef struct ide_tape_obj {char write_prot; } idetape_tape_t; +static DEFINE_MUTEX (ide_tape_mutex);static DEFINE_MUTEX (idetape_ref_mutex);static DEFINE_MUTEX (idetape_chrdev_mutex);
@@ -1426,9 +1425,9 @@ static long idetape_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { long ret; -lock_kernel (); +mutex_lock (&ide_tape_mutex); ret =do_idetape_chrdev_ioctl (file, cmd, arg); -unlock_kernel (); +mutex_unlock (&ide_tape_mutex);return ret; }
@@ -1909,9 +1908,9 @@ static int idetape_open(struct block_device *bdev, fmode_t mode) {struct ide_tape_obj *tape; -lock_kernel (); +mutex_lock (&ide_tape_mutex); tape =ide_tape_get (bdev->bd_disk, false,0 ); -unlock_kernel (); +mutex_unlock (&ide_tape_mutex);if (!tape)return -ENXIO ;
@@ -1923,9 +1922,9 @@ static int idetape_release(struct gendisk *disk, fmode_t mode) {struct ide_tape_obj *tape =ide_drv_g (disk, ide_tape_obj); -lock_kernel (); +mutex_lock (&ide_tape_mutex);ide_tape_put (tape); -unlock_kernel (); +mutex_unlock (&ide_tape_mutex);return 0 ; }
@@ -1937,11 +1936,11 @@ static int idetape_ioctl(struct block_device *bdev, fmode_t mode,ide_drive_t *drive = tape->drive;int err; -lock_kernel (); +mutex_lock (&ide_tape_mutex); err =generic_ide_ioctl (drive, bdev, cmd, arg);if (err == -EINVAL ) err =idetape_blkdev_ioctl (drive, cmd, arg); -unlock_kernel (); +mutex_unlock (&ide_tape_mutex);return err; }
drivers/md/dm.c +5 -5
@@ -15,7 +15,6 @@#include <linux/blkpg.h> #include <linux/bio.h> #include <linux/buffer_head.h> -#include <linux/smp_lock.h> #include <linux/mempool.h> #include <linux/slab.h> #include <linux/idr.h>
@@ -33,6 +32,7 @@#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE"#define DM_COOKIE_LENGTH 24 +static DEFINE_MUTEX (dm_mutex);static const char *_name =DM_NAME ;static unsigned int major =0 ;
@@ -344,7 +344,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode) {struct mapped_device *md; -lock_kernel (); +mutex_lock (&dm_mutex);spin_lock (&_minor_lock); md = bdev->bd_disk->private_data;
@@ -362,7 +362,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode) out:spin_unlock (&_minor_lock); -unlock_kernel (); +mutex_unlock (&dm_mutex);return md ?0 : -ENXIO ; }
@@ -371,10 +371,10 @@ static int dm_blk_close(struct gendisk *disk, fmode_t mode) {struct mapped_device *md = disk->private_data; -lock_kernel (); +mutex_lock (&dm_mutex);atomic_dec (&md->open_count);dm_put (md); -unlock_kernel (); +mutex_unlock (&dm_mutex);return 0 ; }
drivers/md/md.c +7 -6
@@ -36,7 +36,7 @@#include <linux/blkdev.h> #include <linux/sysctl.h> #include <linux/seq_file.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/buffer_head.h> /* for invalidate_bdev */ #include <linux/poll.h> #include <linux/ctype.h>
@@ -57,6 +57,7 @@#define DEBUG 0 #define dprintk(x...) ((void)(DEBUG && printk(x))) +static DEFINE_MUTEX (md_mutex);#ifndef MODULE static void autostart_arrays (int part);
@@ -5953,7 +5954,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)mddev_t *mddev =mddev_find (bdev->bd_dev);int err; -lock_kernel (); +mutex_lock (&md_mutex);if (mddev->gendisk != bdev->bd_disk) {/* we are racing with mddev_put which is discarding this * bd_disk.
@@ -5962,7 +5963,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)/* Wait until bdev->bd_disk is definitely gone */ flush_scheduled_work ();/* Then retry the open from the top */ -unlock_kernel (); +mutex_unlock (&md_mutex);return -ERESTARTSYS ; }BUG_ON (mddev != bdev->bd_disk->private_data);
@@ -5976,7 +5977,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)check_disk_size_change (mddev->gendisk, bdev); out: -unlock_kernel (); +mutex_unlock (&md_mutex);return err; }
@@ -5985,10 +5986,10 @@ static int md_release(struct gendisk *disk, fmode_t mode)mddev_t *mddev = disk->private_data;BUG_ON (!mddev); -lock_kernel (); +mutex_lock (&md_mutex);atomic_dec (&mddev->openers);mddev_put (mddev); -unlock_kernel (); +mutex_unlock (&md_mutex);return 0 ; }
drivers/memstick/core/mspro_block.c +6 -5
@@ -18,11 +18,12 @@#include <linux/kthread.h> #include <linux/delay.h> #include <linux/slab.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/memstick.h> #define DRIVER_NAME "mspro_block" +static DEFINE_MUTEX (mspro_block_mutex);static int major;module_param (major, int,0644 );
@@ -180,7 +181,7 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)struct mspro_block_data *msb = disk->private_data;int rc = -ENXIO ; -lock_kernel (); +mutex_lock (&mspro_block_mutex);mutex_lock (&mspro_block_disk_lock);if (msb && msb->card) {
@@ -192,7 +193,7 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode) }mutex_unlock (&mspro_block_disk_lock); -unlock_kernel (); +mutex_unlock (&mspro_block_mutex);return rc; }
@@ -225,9 +226,9 @@ static int mspro_block_disk_release(struct gendisk *disk)static int mspro_block_bd_release (struct gendisk *disk,fmode_t mode) {int ret; -lock_kernel (); +mutex_lock (&mspro_block_mutex); ret =mspro_block_disk_release (disk); -unlock_kernel (); +mutex_unlock (&mspro_block_mutex);return ret; }
drivers/message/i2o/i2o_block.c +8 -7
@@ -53,7 +53,7 @@#include <linux/module.h> #include <linux/slab.h> #include <linux/i2o.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/mempool.h>
@@ -69,6 +69,7 @@#define OSM_VERSION "1.325"#define OSM_DESCRIPTION "I2O Block Device OSM" +static DEFINE_MUTEX (i2o_block_mutex);static struct i2o_driver i2o_block_driver;/* global Block OSM request mempool */
@@ -578,7 +579,7 @@ static int i2o_block_open(struct block_device *bdev, fmode_t mode)if (!dev->i2o_dev)return -ENODEV ; -lock_kernel (); +mutex_lock (&i2o_block_mutex);if (dev->power >0x1f )i2o_block_device_power (dev,0x02 );
@@ -587,7 +588,7 @@ static int i2o_block_open(struct block_device *bdev, fmode_t mode)i2o_block_device_lock (dev->i2o_dev,-1 );osm_debug ("Ready.\n" ); -unlock_kernel (); +mutex_unlock (&i2o_block_mutex);return 0 ; };
@@ -618,7 +619,7 @@ static int i2o_block_release(struct gendisk *disk, fmode_t mode)if (!dev->i2o_dev)return 0 ; -lock_kernel (); +mutex_lock (&i2o_block_mutex);i2o_block_device_flush (dev->i2o_dev);i2o_block_device_unlock (dev->i2o_dev,-1 );
@@ -629,7 +630,7 @@ static int i2o_block_release(struct gendisk *disk, fmode_t mode) operation =0x24 ;i2o_block_device_power (dev, operation); -unlock_kernel (); +mutex_unlock (&i2o_block_mutex);return 0 ; }
@@ -664,7 +665,7 @@ static int i2o_block_ioctl(struct block_device *bdev, fmode_t mode,if (!capable (CAP_SYS_ADMIN ))return -EPERM ; -lock_kernel (); +mutex_lock (&i2o_block_mutex);switch (cmd) {case BLKI2OGRSTRAT : ret =put_user (dev->rcache, (int __user *)arg);
@@ -688,7 +689,7 @@ static int i2o_block_ioctl(struct block_device *bdev, fmode_t mode, ret =0 ;break ; } -unlock_kernel (); +mutex_unlock (&i2o_block_mutex);return ret; };
drivers/mmc/card/block.c +5 -5
@@ -29,7 +29,6 @@#include <linux/kdev_t.h> #include <linux/blkdev.h> #include <linux/mutex.h> -#include <linux/smp_lock.h> #include <linux/scatterlist.h> #include <linux/string_helpers.h>
@@ -51,6 +50,7 @@ MODULE_ALIAS("mmc:block");#define MMC_SHIFT 3#define MMC_NUM_MINORS (256 >> MMC_SHIFT) +static DEFINE_MUTEX (block_mutex); static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS);/*
@@ -108,7 +108,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)struct mmc_blk_data *md =mmc_blk_get (bdev->bd_disk);int ret = -ENXIO ; -lock_kernel (); +mutex_lock (&block_mutex);if (md) {if (md->usage ==2 )check_disk_change (bdev);
@@ -119,7 +119,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode) ret = -EROFS ; } } -unlock_kernel (); +mutex_unlock (&block_mutex);return ret; }
@@ -128,9 +128,9 @@ static int mmc_blk_release(struct gendisk *disk, fmode_t mode) {struct mmc_blk_data *md = disk->private_data; -lock_kernel (); +mutex_lock (&block_mutex);mmc_blk_put (md); -unlock_kernel (); +mutex_unlock (&block_mutex);return 0 ; }
drivers/mtd/mtd_blkdevs.c +7 -7
@@ -29,7 +29,6 @@#include <linux/blkdev.h> #include <linux/blkpg.h> #include <linux/spinlock.h> -#include <linux/smp_lock.h> #include <linux/hdreg.h> #include <linux/init.h> #include <linux/mutex.h>
@@ -38,6 +37,7 @@#include "mtdcore.h" +static DEFINE_MUTEX (mtd_blkdevs_mutex);static LIST_HEAD (blktrans_majors);static DEFINE_MUTEX (blktrans_ref_mutex);
@@ -181,7 +181,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)if (!dev)return -ERESTARTSYS ;/* FIXME: busy loop! -arnd*/ -lock_kernel (); +mutex_lock (&mtd_blkdevs_mutex);mutex_lock (&dev->lock);if (!dev->mtd) {
@@ -198,7 +198,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) unlock:mutex_unlock (&dev->lock);blktrans_dev_put (dev); -unlock_kernel (); +mutex_unlock (&mtd_blkdevs_mutex);return ret; }
@@ -210,7 +210,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)if (!dev)return ret; -lock_kernel (); +mutex_lock (&mtd_blkdevs_mutex);mutex_lock (&dev->lock);/* Release one reference, we sure its not the last one here*/
@@ -223,7 +223,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode) unlock:mutex_unlock (&dev->lock);blktrans_dev_put (dev); -unlock_kernel (); +mutex_unlock (&mtd_blkdevs_mutex);return ret; }
@@ -256,7 +256,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,if (!dev)return ret; -lock_kernel (); +mutex_lock (&mtd_blkdevs_mutex);mutex_lock (&dev->lock);if (!dev->mtd)
@@ -271,7 +271,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode, } unlock:mutex_unlock (&dev->lock); -unlock_kernel (); +mutex_unlock (&mtd_blkdevs_mutex);blktrans_dev_put (dev);return ret; }
drivers/s390/char/tape_block.c +7 -6
@@ -16,7 +16,7 @@#include <linux/fs.h> #include <linux/module.h> #include <linux/blkdev.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/interrupt.h> #include <linux/buffer_head.h> #include <linux/kernel.h>
@@ -45,6 +45,7 @@/* * file operation structure for tape block frontend */ +static DEFINE_MUTEX (tape_block_mutex);static int tapeblock_open (struct block_device *,fmode_t );static int tapeblock_release (struct gendisk *,fmode_t );static int tapeblock_medium_changed (struct gendisk *);
@@ -362,7 +363,7 @@ tapeblock_open(struct block_device *bdev, fmode_t mode)struct tape_device * device;int rc; -lock_kernel (); +mutex_lock (&tape_block_mutex); device =tape_get_device (disk->private_data);if (device->required_tapemarks) {
@@ -386,14 +387,14 @@ tapeblock_open(struct block_device *bdev, fmode_t mode)* is called. */ tape_state_set (device,TS_BLKUSE ); -unlock_kernel (); +mutex_unlock (&tape_block_mutex);return 0 ; release:tape_release (device); put_device:tape_put_device (device); -unlock_kernel (); +mutex_unlock (&tape_block_mutex);return rc; }
@@ -408,11 +409,11 @@ tapeblock_release(struct gendisk *disk, fmode_t mode) {struct tape_device *device = disk->private_data; -lock_kernel (); +mutex_lock (&tape_block_mutex);tape_state_set (device,TS_IN_USE );tape_release (device);tape_put_device (device); -unlock_kernel (); +mutex_unlock (&tape_block_mutex);return 0 ; }
drivers/scsi/sr.c +7 -7
@@ -44,7 +44,6 @@#include <linux/init.h> #include <linux/blkdev.h> #include <linux/mutex.h> -#include <linux/smp_lock.h> #include <linux/slab.h> #include <asm/uaccess.h>
@@ -76,6 +75,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM); CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \ CDC_MRW|CDC_MRW_W|CDC_RAM) +static DEFINE_MUTEX (sr_mutex);static int sr_probe (struct device *);static int sr_remove (struct device *);static int sr_done (struct scsi_cmnd *);
@@ -470,24 +470,24 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode)struct scsi_cd *cd;int ret = -ENXIO ; -lock_kernel (); +mutex_lock (&sr_mutex); cd =scsi_cd_get (bdev->bd_disk);if (cd) { ret =cdrom_open (&cd->cdi, bdev, mode);if (ret)scsi_cd_put (cd); } -unlock_kernel (); +mutex_unlock (&sr_mutex);return ret; }static int sr_block_release (struct gendisk *disk,fmode_t mode) {struct scsi_cd *cd =scsi_cd (disk); -lock_kernel (); +mutex_lock (&sr_mutex);cdrom_release (&cd->cdi, mode);scsi_cd_put (cd); -unlock_kernel (); +mutex_unlock (&sr_mutex);return 0 ; }
@@ -499,7 +499,7 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,void __user *argp = (void __user *)arg;int ret; -lock_kernel (); +mutex_lock (&sr_mutex);/* * Send SCSI addressing ioctls directly to mid level, send other
@@ -529,7 +529,7 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, ret =scsi_ioctl (sdev, cmd, argp); out: -unlock_kernel (); +mutex_unlock (&sr_mutex);return ret; }
drivers/scsi/st.c +6 -6
@@ -39,7 +39,6 @@ static const char *verstr = "20081215";#include <linux/cdev.h> #include <linux/delay.h> #include <linux/mutex.h> -#include <linux/smp_lock.h> #include <asm/uaccess.h> #include <asm/dma.h>
@@ -76,6 +75,7 @@ static const char *verstr = "20081215";#include "st_options.h" #include "st.h" +static DEFINE_MUTEX (st_mutex);static int buffer_kbs;static int max_sg_segs;static int try_direct_io =TRY_DIRECT_IO ;
@@ -1180,7 +1180,7 @@ static int st_open(struct inode *inode, struct file *filp)int dev =TAPE_NR (inode);char *name; -lock_kernel (); +mutex_lock (&st_mutex);/* * We really want to do nonseekable_open(inode, filp); here, but some * versions of tar incorrectly call lseek on tapes and bail out if that
@@ -1189,7 +1189,7 @@ static int st_open(struct inode *inode, struct file *filp) filp->f_mode &= ~(FMODE_PREAD |FMODE_PWRITE );if (!(STp =scsi_tape_get (dev))) { -unlock_kernel (); +mutex_unlock (&st_mutex);return -ENXIO ; }
@@ -1200,7 +1200,7 @@ static int st_open(struct inode *inode, struct file *filp)if (STp->in_use) {write_unlock (&st_dev_arr_lock);scsi_tape_put (STp); -unlock_kernel (); +mutex_unlock (&st_mutex); DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); ) return (-EBUSY); }
@@ -1249,14 +1249,14 @@ static int st_open(struct inode *inode, struct file *filp) retval = (-EIO ); goto err_out; } -unlock_kernel (); +mutex_unlock (&st_mutex);return 0 ; err_out:normalize_buffer (STp->buffer); STp->in_use =0 ;scsi_tape_put (STp); -unlock_kernel (); +mutex_unlock (&st_mutex);return retval; }
drivers/staging/hv/blkvsc_drv.c +6 -5
@@ -25,7 +25,7 @@#include <linux/major.h> #include <linux/delay.h> #include <linux/hdreg.h> -#include <linux/smp_lock.h> +#include <linux/mutex.h> #include <linux/slab.h> #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h>
@@ -124,6 +124,7 @@ struct blkvsc_driver_context { };/* Static decl */ +static DEFINE_MUTEX (blkvsc_mutex);static int blkvsc_probe (struct device *dev);static int blkvsc_remove (struct device *device);static void blkvsc_shutdown (struct device *device);
@@ -1309,7 +1310,7 @@ static int blkvsc_open(struct block_device *bdev, fmode_t mode)DPRINT_DBG (BLKVSC_DRV ,"- users %d disk %s\n" , blkdev->users, blkdev->gd->disk_name); -lock_kernel (); +mutex_lock (&blkvsc_mutex);spin_lock (&blkdev->lock);if (!blkdev->users && blkdev->device_type ==DVD_TYPE ) {
@@ -1321,7 +1322,7 @@ static int blkvsc_open(struct block_device *bdev, fmode_t mode) blkdev->users++;spin_unlock (&blkdev->lock); -unlock_kernel (); +mutex_unlock (&blkvsc_mutex);return 0 ; }
@@ -1332,7 +1333,7 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode)DPRINT_DBG (BLKVSC_DRV ,"- users %d disk %s\n" , blkdev->users, blkdev->gd->disk_name); -lock_kernel (); +mutex_lock (&blkvsc_mutex);spin_lock (&blkdev->lock);if (blkdev->users ==1 ) {spin_unlock (&blkdev->lock);
@@ -1343,7 +1344,7 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode) blkdev->users--;spin_unlock (&blkdev->lock); -unlock_kernel (); +mutex_unlock (&blkvsc_mutex);return 0 ; }
drivers/staging/spectra/ffsport.c +4 -3
@@ -27,7 +27,6 @@#include <linux/kthread.h> #include <linux/log2.h> #include <linux/init.h> -#include <linux/smp_lock.h> /**** Helper functions used for Div, Remainder operation on u64 ****/
@@ -589,14 +588,16 @@ int GLOB_SBD_ioctl(struct block_device *bdev, fmode_t mode,return -ENOTTY ; } +static DEFINE_MUTEX (ffsport_mutex); +int GLOB_SBD_unlocked_ioctl (struct block_device *bdev,fmode_t mode,unsigned int cmd,unsigned long arg) {int ret; -lock_kernel (); +mutex_lock (&ffsport_mutex); ret =GLOB_SBD_ioctl (bdev, mode, cmd, arg); -unlock_kernel (); +mutex_unlock (&ffsport_mutex);return ret; }
Signature · 1 line
1.7.1
Re: [PATCH 7/7] block: autoconvert trivial BKL users to private mutex
FYI: virtio-blk just has the BKL because of an autoconversion from old ->ioctl to the unlocked version. I have a patch pending to kill it.
Hi Arnd,
Quoted 3 lines · On Tue, 14 Sep 2010 21:53:35 +0200 Arnd Bergmann <[email protected]> wrote:
Stephen, please add git+ssh://master.kernel.org/pub/scm/linux/kernel/git/arnd/bkl.git trivial
Added from today.
Thanks for adding your subsystem tree as a participant of linux-next. As you may know, this is not a judgment of your code. The purpose of linux-next is for integration testing and to lower the impact of conflicts between subsystems in the next merge window.
You will need to ensure that the patches/commits in your tree/series have been:
* submitted under GPL v2 (or later) and include the Contributor's Signed-off-by,
* posted to the relevant mailing list,
* reviewed by you (or another maintainer of your subsystem tree),
* successfully unit tested, and
* destined for the current or next Linux merge window.
Basically, this should be just what you would send to Linus (or ask him to fetch). It is allowed to be rebased if you deem it necessary.
Signature · 15 lines
Cheers, Stephen Rothwell [email protected] Legal Stuff: By participating in linux-next, your subsystem tree contributions are public and will be included in the linux-next trees. You may be sent e-mail messages indicating errors or other issues when the patches/commits from your subsystem tree are merged and tested in linux-next. These messages may also be cross-posted to the linux-next mailing list, the linux-kernel mailing list, etc. The linux-next tree project and IBM (my employer) make no warranties regarding the linux-next project, the testing procedures, the results, the e-mails, etc. If you don't agree to these ground rules, let me know and I'll remove your tree from participation in linux-next.