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