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

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: linux-scsi@vger.kernel.org
Cc: "James E.J. Bottomley" <James.Bottomley@suse.de>

+86 -85
+8 -7
drivers/message/fusion/mptctl.c
··· 54 54 #include <linux/pci.h> 55 55 #include <linux/delay.h> /* for mdelay */ 56 56 #include <linux/miscdevice.h> 57 - #include <linux/smp_lock.h> 57 + #include <linux/mutex.h> 58 58 #include <linux/compat.h> 59 59 60 60 #include <asm/io.h> ··· 83 83 84 84 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 85 85 86 + static DEFINE_MUTEX(mpctl_mutex); 86 87 static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS; 87 88 static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS; 88 89 ··· 602 601 MPT_ADAPTER *ioc; 603 602 int ret; 604 603 605 - lock_kernel(); 604 + mutex_lock(&mpctl_mutex); 606 605 list_for_each_entry(ioc, &ioc_list, list) 607 606 ioc->aen_event_read_flag=0; 608 607 609 608 ret = fasync_helper(fd, filep, mode, &async_queue); 610 - unlock_kernel(); 609 + mutex_unlock(&mpctl_mutex); 611 610 return ret; 612 611 } 613 612 ··· 699 698 mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 700 699 { 701 700 long ret; 702 - lock_kernel(); 701 + mutex_lock(&mpctl_mutex); 703 702 ret = __mptctl_ioctl(file, cmd, arg); 704 - unlock_kernel(); 703 + mutex_unlock(&mpctl_mutex); 705 704 return ret; 706 705 } 707 706 ··· 2927 2926 static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg) 2928 2927 { 2929 2928 long ret; 2930 - lock_kernel(); 2929 + mutex_lock(&mpctl_mutex); 2931 2930 switch (cmd) { 2932 2931 case MPTIOCINFO: 2933 2932 case MPTIOCINFO1: ··· 2952 2951 ret = -ENOIOCTLCMD; 2953 2952 break; 2954 2953 } 2955 - unlock_kernel(); 2954 + mutex_unlock(&mpctl_mutex); 2956 2955 return ret; 2957 2956 } 2958 2957
+12 -11
drivers/message/i2o/i2o_config.c
··· 31 31 */ 32 32 33 33 #include <linux/miscdevice.h> 34 - #include <linux/smp_lock.h> 34 + #include <linux/mutex.h> 35 35 #include <linux/compat.h> 36 36 #include <linux/slab.h> 37 37 ··· 41 41 42 42 #define SG_TABLESIZE 30 43 43 44 + static DEFINE_MUTEX(i2o_cfg_mutex); 44 45 static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long); 45 46 46 47 static spinlock_t i2o_config_lock; ··· 742 741 unsigned long arg) 743 742 { 744 743 int ret; 745 - lock_kernel(); 744 + mutex_lock(&i2o_cfg_mutex); 746 745 switch (cmd) { 747 746 case I2OGETIOPS: 748 747 ret = i2o_cfg_ioctl(file, cmd, arg); ··· 754 753 ret = -ENOIOCTLCMD; 755 754 break; 756 755 } 757 - unlock_kernel(); 756 + mutex_unlock(&i2o_cfg_mutex); 758 757 return ret; 759 758 } 760 759 ··· 982 981 { 983 982 int ret; 984 983 985 - lock_kernel(); 984 + mutex_lock(&i2o_cfg_mutex); 986 985 switch (cmd) { 987 986 case I2OGETIOPS: 988 987 ret = i2o_cfg_getiops(arg); ··· 1038 1037 osm_debug("unknown ioctl called!\n"); 1039 1038 ret = -EINVAL; 1040 1039 } 1041 - unlock_kernel(); 1040 + mutex_unlock(&i2o_cfg_mutex); 1042 1041 return ret; 1043 1042 } 1044 1043 ··· 1052 1051 if (!tmp) 1053 1052 return -ENOMEM; 1054 1053 1055 - lock_kernel(); 1054 + mutex_lock(&i2o_cfg_mutex); 1056 1055 file->private_data = (void *)(i2o_cfg_info_id++); 1057 1056 tmp->fp = file; 1058 1057 tmp->fasync = NULL; ··· 1066 1065 spin_lock_irqsave(&i2o_config_lock, flags); 1067 1066 open_files = tmp; 1068 1067 spin_unlock_irqrestore(&i2o_config_lock, flags); 1069 - unlock_kernel(); 1068 + mutex_unlock(&i2o_cfg_mutex); 1070 1069 1071 1070 return 0; 1072 1071 } ··· 1077 1076 struct i2o_cfg_info *p; 1078 1077 int ret = -EBADF; 1079 1078 1080 - lock_kernel(); 1079 + mutex_lock(&i2o_cfg_mutex); 1081 1080 for (p = open_files; p; p = p->next) 1082 1081 if (p->q_id == id) 1083 1082 break; 1084 1083 1085 1084 if (p) 1086 1085 ret = fasync_helper(fd, fp, on, &p->fasync); 1087 - unlock_kernel(); 1086 + mutex_unlock(&i2o_cfg_mutex); 1088 1087 return ret; 1089 1088 } 1090 1089 ··· 1094 1093 struct i2o_cfg_info *p, **q; 1095 1094 unsigned long flags; 1096 1095 1097 - lock_kernel(); 1096 + mutex_lock(&i2o_cfg_mutex); 1098 1097 spin_lock_irqsave(&i2o_config_lock, flags); 1099 1098 for (q = &open_files; (p = *q) != NULL; q = &p->next) { 1100 1099 if (p->q_id == id) { ··· 1104 1103 } 1105 1104 } 1106 1105 spin_unlock_irqrestore(&i2o_config_lock, flags); 1107 - unlock_kernel(); 1106 + mutex_unlock(&i2o_cfg_mutex); 1108 1107 1109 1108 return 0; 1110 1109 }
+3 -4
drivers/scsi/3w-9xxx.c
··· 92 92 #include <linux/pci.h> 93 93 #include <linux/time.h> 94 94 #include <linux/mutex.h> 95 - #include <linux/smp_lock.h> 96 95 #include <linux/slab.h> 97 96 #include <asm/io.h> 98 97 #include <asm/irq.h> ··· 104 105 105 106 /* Globals */ 106 107 #define TW_DRIVER_VERSION "2.26.02.014" 108 + static DEFINE_MUTEX(twa_chrdev_mutex); 107 109 static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT]; 108 110 static unsigned int twa_device_extension_count; 109 111 static int twa_major = -1; ··· 658 658 int retval = TW_IOCTL_ERROR_OS_EFAULT; 659 659 void __user *argp = (void __user *)arg; 660 660 661 - lock_kernel(); 661 + mutex_lock(&twa_chrdev_mutex); 662 662 663 663 /* Only let one of these through at a time */ 664 664 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { ··· 879 879 out2: 880 880 mutex_unlock(&tw_dev->ioctl_lock); 881 881 out: 882 - unlock_kernel(); 882 + mutex_unlock(&twa_chrdev_mutex); 883 883 return retval; 884 884 } /* End twa_chrdev_ioctl() */ 885 885 ··· 890 890 unsigned int minor_number; 891 891 int retval = TW_IOCTL_ERROR_OS_ENODEV; 892 892 893 - cycle_kernel_lock(); 894 893 minor_number = iminor(inode); 895 894 if (minor_number >= twa_device_extension_count) 896 895 goto out;
+3 -4
drivers/scsi/3w-sas.c
··· 64 64 #include <linux/pci.h> 65 65 #include <linux/time.h> 66 66 #include <linux/mutex.h> 67 - #include <linux/smp_lock.h> 68 67 #include <linux/slab.h> 69 68 #include <asm/io.h> 70 69 #include <asm/irq.h> ··· 76 77 77 78 /* Globals */ 78 79 #define TW_DRIVER_VERSION "3.26.02.000" 80 + static DEFINE_MUTEX(twl_chrdev_mutex); 79 81 static TW_Device_Extension *twl_device_extension_list[TW_MAX_SLOT]; 80 82 static unsigned int twl_device_extension_count; 81 83 static int twl_major = -1; ··· 764 764 int retval = -EFAULT; 765 765 void __user *argp = (void __user *)arg; 766 766 767 - lock_kernel(); 767 + mutex_lock(&twl_chrdev_mutex); 768 768 769 769 /* Only let one of these through at a time */ 770 770 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { ··· 861 861 out2: 862 862 mutex_unlock(&tw_dev->ioctl_lock); 863 863 out: 864 - unlock_kernel(); 864 + mutex_unlock(&twl_chrdev_mutex); 865 865 return retval; 866 866 } /* End twl_chrdev_ioctl() */ 867 867 ··· 876 876 goto out; 877 877 } 878 878 879 - cycle_kernel_lock(); 880 879 minor_number = iminor(inode); 881 880 if (minor_number >= twl_device_extension_count) 882 881 goto out;
+4 -5
drivers/scsi/3w-xxxx.c
··· 199 199 200 200 #include <linux/module.h> 201 201 #include <linux/reboot.h> 202 - #include <linux/smp_lock.h> 203 202 #include <linux/spinlock.h> 204 203 #include <linux/interrupt.h> 205 204 #include <linux/moduleparam.h> ··· 220 221 221 222 /* Globals */ 222 223 #define TW_DRIVER_VERSION "1.26.02.003" 224 + static DEFINE_MUTEX(tw_mutex); 223 225 static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT]; 224 226 static int tw_device_extension_count = 0; 225 227 static int twe_major = -1; ··· 900 900 901 901 dprintk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl()\n"); 902 902 903 - lock_kernel(); 903 + mutex_lock(&tw_mutex); 904 904 /* Only let one of these through at a time */ 905 905 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { 906 - unlock_kernel(); 906 + mutex_unlock(&tw_mutex); 907 907 return -EINTR; 908 908 } 909 909 ··· 1034 1034 dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, cpu_addr, dma_handle); 1035 1035 out: 1036 1036 mutex_unlock(&tw_dev->ioctl_lock); 1037 - unlock_kernel(); 1037 + mutex_unlock(&tw_mutex); 1038 1038 return retval; 1039 1039 } /* End tw_chrdev_ioctl() */ 1040 1040 ··· 1044 1044 { 1045 1045 unsigned int minor_number; 1046 1046 1047 - cycle_kernel_lock(); 1048 1047 dprintk(KERN_WARNING "3w-xxxx: tw_ioctl_open()\n"); 1049 1048 1050 1049 minor_number = iminor(inode);
+8 -7
drivers/scsi/aacraid/linit.c
··· 38 38 #include <linux/moduleparam.h> 39 39 #include <linux/pci.h> 40 40 #include <linux/slab.h> 41 - #include <linux/smp_lock.h> 41 + #include <linux/mutex.h> 42 42 #include <linux/spinlock.h> 43 43 #include <linux/syscalls.h> 44 44 #include <linux/delay.h> ··· 76 76 MODULE_LICENSE("GPL"); 77 77 MODULE_VERSION(AAC_DRIVER_FULL_VERSION); 78 78 79 + static DEFINE_MUTEX(aac_mutex); 79 80 static LIST_HEAD(aac_devices); 80 81 static int aac_cfg_major = -1; 81 82 char aac_driver_version[] = AAC_DRIVER_FULL_VERSION; ··· 679 678 unsigned minor_number = iminor(inode); 680 679 int err = -ENODEV; 681 680 682 - lock_kernel(); /* BKL pushdown: nothing else protects this list */ 681 + mutex_lock(&aac_mutex); /* BKL pushdown: nothing else protects this list */ 683 682 list_for_each_entry(aac, &aac_devices, entry) { 684 683 if (aac->id == minor_number) { 685 684 file->private_data = aac; ··· 687 686 break; 688 687 } 689 688 } 690 - unlock_kernel(); 689 + mutex_unlock(&aac_mutex); 691 690 692 691 return err; 693 692 } ··· 712 711 int ret; 713 712 if (!capable(CAP_SYS_RAWIO)) 714 713 return -EPERM; 715 - lock_kernel(); 714 + mutex_lock(&aac_mutex); 716 715 ret = aac_do_ioctl(file->private_data, cmd, (void __user *)arg); 717 - unlock_kernel(); 716 + mutex_unlock(&aac_mutex); 718 717 719 718 return ret; 720 719 } ··· 723 722 static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long arg) 724 723 { 725 724 long ret; 726 - lock_kernel(); 725 + mutex_lock(&aac_mutex); 727 726 switch (cmd) { 728 727 case FSACTL_MINIPORT_REV_CHECK: 729 728 case FSACTL_SENDFIB: ··· 757 756 ret = -ENOIOCTLCMD; 758 757 break; 759 758 } 760 - unlock_kernel(); 759 + mutex_unlock(&aac_mutex); 761 760 return ret; 762 761 } 763 762
+4 -4
drivers/scsi/ch.c
··· 22 22 #include <linux/chio.h> /* here are all the ioctls */ 23 23 #include <linux/mutex.h> 24 24 #include <linux/idr.h> 25 - #include <linux/smp_lock.h> 26 25 #include <linux/slab.h> 27 26 28 27 #include <scsi/scsi.h> ··· 43 44 MODULE_ALIAS_CHARDEV_MAJOR(SCSI_CHANGER_MAJOR); 44 45 MODULE_ALIAS_SCSI_DEVICE(TYPE_MEDIUM_CHANGER); 45 46 47 + static DEFINE_MUTEX(ch_mutex); 46 48 static int init = 1; 47 49 module_param(init, int, 0444); 48 50 MODULE_PARM_DESC(init, \ ··· 581 581 scsi_changer *ch; 582 582 int minor = iminor(inode); 583 583 584 - lock_kernel(); 584 + mutex_lock(&ch_mutex); 585 585 spin_lock(&ch_index_lock); 586 586 ch = idr_find(&ch_index_idr, minor); 587 587 588 588 if (NULL == ch || scsi_device_get(ch->device)) { 589 589 spin_unlock(&ch_index_lock); 590 - unlock_kernel(); 590 + mutex_unlock(&ch_mutex); 591 591 return -ENXIO; 592 592 } 593 593 spin_unlock(&ch_index_lock); 594 594 595 595 file->private_data = ch; 596 - unlock_kernel(); 596 + mutex_unlock(&ch_mutex); 597 597 return 0; 598 598 } 599 599
+9 -9
drivers/scsi/dpt_i2o.c
··· 49 49 #include <linux/kernel.h> /* for printk */ 50 50 #include <linux/sched.h> 51 51 #include <linux/reboot.h> 52 - #include <linux/smp_lock.h> 53 52 #include <linux/spinlock.h> 54 53 #include <linux/dma-mapping.h> 55 54 ··· 75 76 * Needed for our management apps 76 77 *============================================================================ 77 78 */ 79 + static DEFINE_MUTEX(adpt_mutex); 78 80 static dpt_sig_S DPTI_sig = { 79 81 {'d', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION, 80 82 #ifdef __i386__ ··· 1732 1732 int minor; 1733 1733 adpt_hba* pHba; 1734 1734 1735 - lock_kernel(); 1735 + mutex_lock(&adpt_mutex); 1736 1736 //TODO check for root access 1737 1737 // 1738 1738 minor = iminor(inode); 1739 1739 if (minor >= hba_count) { 1740 - unlock_kernel(); 1740 + mutex_unlock(&adpt_mutex); 1741 1741 return -ENXIO; 1742 1742 } 1743 1743 mutex_lock(&adpt_configuration_lock); ··· 1748 1748 } 1749 1749 if (pHba == NULL) { 1750 1750 mutex_unlock(&adpt_configuration_lock); 1751 - unlock_kernel(); 1751 + mutex_unlock(&adpt_mutex); 1752 1752 return -ENXIO; 1753 1753 } 1754 1754 ··· 1759 1759 1760 1760 pHba->in_use = 1; 1761 1761 mutex_unlock(&adpt_configuration_lock); 1762 - unlock_kernel(); 1762 + mutex_unlock(&adpt_mutex); 1763 1763 1764 1764 return 0; 1765 1765 } ··· 2160 2160 2161 2161 inode = file->f_dentry->d_inode; 2162 2162 2163 - lock_kernel(); 2163 + mutex_lock(&adpt_mutex); 2164 2164 ret = adpt_ioctl(inode, file, cmd, arg); 2165 - unlock_kernel(); 2165 + mutex_unlock(&adpt_mutex); 2166 2166 2167 2167 return ret; 2168 2168 } ··· 2176 2176 2177 2177 inode = file->f_dentry->d_inode; 2178 2178 2179 - lock_kernel(); 2179 + mutex_lock(&adpt_mutex); 2180 2180 2181 2181 switch(cmd) { 2182 2182 case DPT_SIGNATURE: ··· 2194 2194 ret = -ENOIOCTLCMD; 2195 2195 } 2196 2196 2197 - unlock_kernel(); 2197 + mutex_unlock(&adpt_mutex); 2198 2198 2199 2199 return ret; 2200 2200 }
+6 -5
drivers/scsi/gdth.c
··· 120 120 #include <linux/timer.h> 121 121 #include <linux/dma-mapping.h> 122 122 #include <linux/list.h> 123 - #include <linux/smp_lock.h> 123 + #include <linux/mutex.h> 124 124 #include <linux/slab.h> 125 125 126 126 #ifdef GDTH_RTC ··· 140 140 #include <scsi/scsi_host.h> 141 141 #include "gdth.h" 142 142 143 + static DEFINE_MUTEX(gdth_mutex); 143 144 static void gdth_delay(int milliseconds); 144 145 static void gdth_eval_mapping(u32 size, u32 *cyls, int *heads, int *secs); 145 146 static irqreturn_t gdth_interrupt(int irq, void *dev_id); ··· 4043 4042 { 4044 4043 gdth_ha_str *ha; 4045 4044 4046 - lock_kernel(); 4045 + mutex_lock(&gdth_mutex); 4047 4046 list_for_each_entry(ha, &gdth_instances, list) { 4048 4047 if (!ha->sdev) 4049 4048 ha->sdev = scsi_get_host_dev(ha->shost); 4050 4049 } 4051 - unlock_kernel(); 4050 + mutex_unlock(&gdth_mutex); 4052 4051 4053 4052 TRACE(("gdth_open()\n")); 4054 4053 return 0; ··· 4616 4615 { 4617 4616 int ret; 4618 4617 4619 - lock_kernel(); 4618 + mutex_lock(&gdth_mutex); 4620 4619 ret = gdth_ioctl(file, cmd, arg); 4621 - unlock_kernel(); 4620 + mutex_unlock(&gdth_mutex); 4622 4621 4623 4622 return ret; 4624 4623 }
+4 -4
drivers/scsi/megaraid.c
··· 46 46 #include <linux/pci.h> 47 47 #include <linux/init.h> 48 48 #include <linux/dma-mapping.h> 49 - #include <linux/smp_lock.h> 49 + #include <linux/mutex.h> 50 50 #include <linux/slab.h> 51 51 #include <scsi/scsicam.h> 52 52 ··· 62 62 MODULE_LICENSE ("GPL"); 63 63 MODULE_VERSION(MEGARAID_MODULE_VERSION); 64 64 65 + static DEFINE_MUTEX(megadev_mutex); 65 66 static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN; 66 67 module_param(max_cmd_per_lun, uint, 0); 67 68 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)"); ··· 3283 3282 static int 3284 3283 megadev_open (struct inode *inode, struct file *filep) 3285 3284 { 3286 - cycle_kernel_lock(); 3287 3285 /* 3288 3286 * Only allow superuser to access private ioctl interface 3289 3287 */ ··· 3701 3701 { 3702 3702 int ret; 3703 3703 3704 - lock_kernel(); 3704 + mutex_lock(&megadev_mutex); 3705 3705 ret = megadev_ioctl(filep, cmd, arg); 3706 - unlock_kernel(); 3706 + mutex_unlock(&megadev_mutex); 3707 3707 3708 3708 return ret; 3709 3709 }
+4 -4
drivers/scsi/megaraid/megaraid_mm.c
··· 16 16 */ 17 17 #include <linux/sched.h> 18 18 #include <linux/slab.h> 19 - #include <linux/smp_lock.h> 19 + #include <linux/mutex.h> 20 20 #include "megaraid_mm.h" 21 21 22 22 23 23 // Entry points for char node driver 24 + static DEFINE_MUTEX(mraid_mm_mutex); 24 25 static int mraid_mm_open(struct inode *, struct file *); 25 26 static long mraid_mm_unlocked_ioctl(struct file *, uint, unsigned long); 26 27 ··· 99 98 */ 100 99 if (!capable(CAP_SYS_ADMIN)) return (-EACCES); 101 100 102 - cycle_kernel_lock(); 103 101 return 0; 104 102 } 105 103 ··· 224 224 int err; 225 225 226 226 /* inconsistant: mraid_mm_compat_ioctl doesn't take the BKL */ 227 - lock_kernel(); 227 + mutex_lock(&mraid_mm_mutex); 228 228 err = mraid_mm_ioctl(filep, cmd, arg); 229 - unlock_kernel(); 229 + mutex_unlock(&mraid_mm_mutex); 230 230 231 231 return err; 232 232 }
-2
drivers/scsi/megaraid/megaraid_sas.c
··· 33 33 #include <linux/spinlock.h> 34 34 #include <linux/interrupt.h> 35 35 #include <linux/delay.h> 36 - #include <linux/smp_lock.h> 37 36 #include <linux/uio.h> 38 37 #include <linux/slab.h> 39 38 #include <asm/uaccess.h> ··· 3556 3557 */ 3557 3558 static int megasas_mgmt_open(struct inode *inode, struct file *filep) 3558 3559 { 3559 - cycle_kernel_lock(); 3560 3560 /* 3561 3561 * Allow only those users with admin rights 3562 3562 */
+6 -5
drivers/scsi/mpt2sas/mpt2sas_ctl.c
··· 51 51 #include <linux/types.h> 52 52 #include <linux/pci.h> 53 53 #include <linux/delay.h> 54 - #include <linux/smp_lock.h> 54 + #include <linux/mutex.h> 55 55 #include <linux/compat.h> 56 56 #include <linux/poll.h> 57 57 ··· 61 61 #include "mpt2sas_base.h" 62 62 #include "mpt2sas_ctl.h" 63 63 64 + static DEFINE_MUTEX(_ctl_mutex); 64 65 static struct fasync_struct *async_queue; 65 66 static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait); 66 67 ··· 2239 2238 { 2240 2239 long ret; 2241 2240 2242 - lock_kernel(); 2241 + mutex_lock(&_ctl_mutex); 2243 2242 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); 2244 - unlock_kernel(); 2243 + mutex_unlock(&_ctl_mutex); 2245 2244 return ret; 2246 2245 } 2247 2246 ··· 2310 2309 { 2311 2310 long ret; 2312 2311 2313 - lock_kernel(); 2312 + mutex_lock(&_ctl_mutex); 2314 2313 if (cmd == MPT2COMMAND32) 2315 2314 ret = _ctl_compat_mpt_command(file, cmd, arg); 2316 2315 else 2317 2316 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); 2318 - unlock_kernel(); 2317 + mutex_unlock(&_ctl_mutex); 2319 2318 return ret; 2320 2319 } 2321 2320 #endif
+8 -7
drivers/scsi/osst.c
··· 51 51 #include <linux/moduleparam.h> 52 52 #include <linux/delay.h> 53 53 #include <linux/jiffies.h> 54 - #include <linux/smp_lock.h> 54 + #include <linux/mutex.h> 55 55 #include <asm/uaccess.h> 56 56 #include <asm/dma.h> 57 57 #include <asm/system.h> ··· 80 80 #include "osst_options.h" 81 81 #include "osst_detect.h" 82 82 83 + static DEFINE_MUTEX(osst_int_mutex); 83 84 static int max_dev = 0; 84 85 static int write_threshold_kbs = 0; 85 86 static int max_sg_segs = 0; ··· 4808 4807 { 4809 4808 int ret; 4810 4809 4811 - lock_kernel(); 4810 + mutex_lock(&osst_int_mutex); 4812 4811 ret = __os_scsi_tape_open(inode, filp); 4813 - unlock_kernel(); 4812 + mutex_unlock(&osst_int_mutex); 4814 4813 return ret; 4815 4814 } 4816 4815 ··· 4944 4943 char * name = tape_name(STp); 4945 4944 void __user * p = (void __user *)arg; 4946 4945 4947 - lock_kernel(); 4946 + mutex_lock(&osst_int_mutex); 4948 4947 if (mutex_lock_interruptible(&STp->lock)) { 4949 - unlock_kernel(); 4948 + mutex_unlock(&osst_int_mutex); 4950 4949 return -ERESTARTSYS; 4951 4950 } 4952 4951 ··· 5261 5260 mutex_unlock(&STp->lock); 5262 5261 5263 5262 retval = scsi_ioctl(STp->device, cmd_in, p); 5264 - unlock_kernel(); 5263 + mutex_unlock(&osst_int_mutex); 5265 5264 return retval; 5266 5265 5267 5266 out: 5268 5267 if (SRpnt) osst_release_request(SRpnt); 5269 5268 5270 5269 mutex_unlock(&STp->lock); 5271 - unlock_kernel(); 5270 + mutex_unlock(&osst_int_mutex); 5272 5271 5273 5272 return retval; 5274 5273 }
-2
drivers/scsi/scsi_tgt_if.c
··· 22 22 #include <linux/miscdevice.h> 23 23 #include <linux/gfp.h> 24 24 #include <linux/file.h> 25 - #include <linux/smp_lock.h> 26 25 #include <net/tcp.h> 27 26 #include <scsi/scsi.h> 28 27 #include <scsi/scsi_cmnd.h> ··· 322 323 { 323 324 tx_ring.tr_idx = rx_ring.tr_idx = 0; 324 325 325 - cycle_kernel_lock(); 326 326 return 0; 327 327 } 328 328
+7 -5
drivers/scsi/sg.c
··· 49 49 #include <linux/blkdev.h> 50 50 #include <linux/delay.h> 51 51 #include <linux/blktrace_api.h> 52 - #include <linux/smp_lock.h> 52 + #include <linux/mutex.h> 53 53 54 54 #include "scsi.h" 55 55 #include <scsi/scsi_dbg.h> ··· 102 102 103 103 static int sg_add(struct device *, struct class_interface *); 104 104 static void sg_remove(struct device *, struct class_interface *); 105 + 106 + static DEFINE_MUTEX(sg_mutex); 105 107 106 108 static DEFINE_IDR(sg_index_idr); 107 109 static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock ··· 231 229 int res; 232 230 int retval; 233 231 234 - lock_kernel(); 232 + mutex_lock(&sg_mutex); 235 233 nonseekable_open(inode, filp); 236 234 SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev, flags)); 237 235 sdp = sg_get_dev(dev); ··· 316 314 sg_put: 317 315 if (sdp) 318 316 sg_put_dev(sdp); 319 - unlock_kernel(); 317 + mutex_unlock(&sg_mutex); 320 318 return retval; 321 319 } 322 320 ··· 1094 1092 { 1095 1093 int ret; 1096 1094 1097 - lock_kernel(); 1095 + mutex_lock(&sg_mutex); 1098 1096 ret = sg_ioctl(filp, cmd_in, arg); 1099 - unlock_kernel(); 1097 + mutex_unlock(&sg_mutex); 1100 1098 1101 1099 return ret; 1102 1100 }