aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/message
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2010-06-02 08:28:52 -0400
committerArnd Bergmann <arnd@arndb.de>2010-09-15 15:00:45 -0400
commitc45d15d24eb2b49bf734e1e5e7e103befb76b19b (patch)
treedd768c089fd3393e8fa2c4f4fb50cedb1044037d /drivers/message
parent49553c2ef88749dd502687f4eb9c258bb10a4f44 (diff)
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>
Diffstat (limited to 'drivers/message')
-rw-r--r--drivers/message/fusion/mptctl.c15
-rw-r--r--drivers/message/i2o/i2o_config.c23
2 files changed, 20 insertions, 18 deletions
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index d8ddfdf8be14..a3856ed90aef 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -54,7 +54,7 @@
54#include <linux/pci.h> 54#include <linux/pci.h>
55#include <linux/delay.h> /* for mdelay */ 55#include <linux/delay.h> /* for mdelay */
56#include <linux/miscdevice.h> 56#include <linux/miscdevice.h>
57#include <linux/smp_lock.h> 57#include <linux/mutex.h>
58#include <linux/compat.h> 58#include <linux/compat.h>
59 59
60#include <asm/io.h> 60#include <asm/io.h>
@@ -83,6 +83,7 @@ MODULE_VERSION(my_VERSION);
83 83
84/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 84/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
85 85
86static DEFINE_MUTEX(mpctl_mutex);
86static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS; 87static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS;
87static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS; 88static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS;
88 89
@@ -601,12 +602,12 @@ mptctl_fasync(int fd, struct file *filep, int mode)
601 MPT_ADAPTER *ioc; 602 MPT_ADAPTER *ioc;
602 int ret; 603 int ret;
603 604
604 lock_kernel(); 605 mutex_lock(&mpctl_mutex);
605 list_for_each_entry(ioc, &ioc_list, list) 606 list_for_each_entry(ioc, &ioc_list, list)
606 ioc->aen_event_read_flag=0; 607 ioc->aen_event_read_flag=0;
607 608
608 ret = fasync_helper(fd, filep, mode, &async_queue); 609 ret = fasync_helper(fd, filep, mode, &async_queue);
609 unlock_kernel(); 610 mutex_unlock(&mpctl_mutex);
610 return ret; 611 return ret;
611} 612}
612 613
@@ -698,9 +699,9 @@ static long
698mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 699mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
699{ 700{
700 long ret; 701 long ret;
701 lock_kernel(); 702 mutex_lock(&mpctl_mutex);
702 ret = __mptctl_ioctl(file, cmd, arg); 703 ret = __mptctl_ioctl(file, cmd, arg);
703 unlock_kernel(); 704 mutex_unlock(&mpctl_mutex);
704 return ret; 705 return ret;
705} 706}
706 707
@@ -2926,7 +2927,7 @@ compat_mpt_command(struct file *filp, unsigned int cmd,
2926static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg) 2927static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
2927{ 2928{
2928 long ret; 2929 long ret;
2929 lock_kernel(); 2930 mutex_lock(&mpctl_mutex);
2930 switch (cmd) { 2931 switch (cmd) {
2931 case MPTIOCINFO: 2932 case MPTIOCINFO:
2932 case MPTIOCINFO1: 2933 case MPTIOCINFO1:
@@ -2951,7 +2952,7 @@ static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long a
2951 ret = -ENOIOCTLCMD; 2952 ret = -ENOIOCTLCMD;
2952 break; 2953 break;
2953 } 2954 }
2954 unlock_kernel(); 2955 mutex_unlock(&mpctl_mutex);
2955 return ret; 2956 return ret;
2956} 2957}
2957 2958
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index 068ba0785bb4..7d3cc575c361 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -31,7 +31,7 @@
31 */ 31 */
32 32
33#include <linux/miscdevice.h> 33#include <linux/miscdevice.h>
34#include <linux/smp_lock.h> 34#include <linux/mutex.h>
35#include <linux/compat.h> 35#include <linux/compat.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37 37
@@ -41,6 +41,7 @@
41 41
42#define SG_TABLESIZE 30 42#define SG_TABLESIZE 30
43 43
44static DEFINE_MUTEX(i2o_cfg_mutex);
44static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long); 45static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long);
45 46
46static spinlock_t i2o_config_lock; 47static spinlock_t i2o_config_lock;
@@ -741,7 +742,7 @@ static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
741 unsigned long arg) 742 unsigned long arg)
742{ 743{
743 int ret; 744 int ret;
744 lock_kernel(); 745 mutex_lock(&i2o_cfg_mutex);
745 switch (cmd) { 746 switch (cmd) {
746 case I2OGETIOPS: 747 case I2OGETIOPS:
747 ret = i2o_cfg_ioctl(file, cmd, arg); 748 ret = i2o_cfg_ioctl(file, cmd, arg);
@@ -753,7 +754,7 @@ static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
753 ret = -ENOIOCTLCMD; 754 ret = -ENOIOCTLCMD;
754 break; 755 break;
755 } 756 }
756 unlock_kernel(); 757 mutex_unlock(&i2o_cfg_mutex);
757 return ret; 758 return ret;
758} 759}
759 760
@@ -981,7 +982,7 @@ static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
981{ 982{
982 int ret; 983 int ret;
983 984
984 lock_kernel(); 985 mutex_lock(&i2o_cfg_mutex);
985 switch (cmd) { 986 switch (cmd) {
986 case I2OGETIOPS: 987 case I2OGETIOPS:
987 ret = i2o_cfg_getiops(arg); 988 ret = i2o_cfg_getiops(arg);
@@ -1037,7 +1038,7 @@ static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
1037 osm_debug("unknown ioctl called!\n"); 1038 osm_debug("unknown ioctl called!\n");
1038 ret = -EINVAL; 1039 ret = -EINVAL;
1039 } 1040 }
1040 unlock_kernel(); 1041 mutex_unlock(&i2o_cfg_mutex);
1041 return ret; 1042 return ret;
1042} 1043}
1043 1044
@@ -1051,7 +1052,7 @@ static int cfg_open(struct inode *inode, struct file *file)
1051 if (!tmp) 1052 if (!tmp)
1052 return -ENOMEM; 1053 return -ENOMEM;
1053 1054
1054 lock_kernel(); 1055 mutex_lock(&i2o_cfg_mutex);
1055 file->private_data = (void *)(i2o_cfg_info_id++); 1056 file->private_data = (void *)(i2o_cfg_info_id++);
1056 tmp->fp = file; 1057 tmp->fp = file;
1057 tmp->fasync = NULL; 1058 tmp->fasync = NULL;
@@ -1065,7 +1066,7 @@ static int cfg_open(struct inode *inode, struct file *file)
1065 spin_lock_irqsave(&i2o_config_lock, flags); 1066 spin_lock_irqsave(&i2o_config_lock, flags);
1066 open_files = tmp; 1067 open_files = tmp;
1067 spin_unlock_irqrestore(&i2o_config_lock, flags); 1068 spin_unlock_irqrestore(&i2o_config_lock, flags);
1068 unlock_kernel(); 1069 mutex_unlock(&i2o_cfg_mutex);
1069 1070
1070 return 0; 1071 return 0;
1071} 1072}
@@ -1076,14 +1077,14 @@ static int cfg_fasync(int fd, struct file *fp, int on)
1076 struct i2o_cfg_info *p; 1077 struct i2o_cfg_info *p;
1077 int ret = -EBADF; 1078 int ret = -EBADF;
1078 1079
1079 lock_kernel(); 1080 mutex_lock(&i2o_cfg_mutex);
1080 for (p = open_files; p; p = p->next) 1081 for (p = open_files; p; p = p->next)
1081 if (p->q_id == id) 1082 if (p->q_id == id)
1082 break; 1083 break;
1083 1084
1084 if (p) 1085 if (p)
1085 ret = fasync_helper(fd, fp, on, &p->fasync); 1086 ret = fasync_helper(fd, fp, on, &p->fasync);
1086 unlock_kernel(); 1087 mutex_unlock(&i2o_cfg_mutex);
1087 return ret; 1088 return ret;
1088} 1089}
1089 1090
@@ -1093,7 +1094,7 @@ static int cfg_release(struct inode *inode, struct file *file)
1093 struct i2o_cfg_info *p, **q; 1094 struct i2o_cfg_info *p, **q;
1094 unsigned long flags; 1095 unsigned long flags;
1095 1096
1096 lock_kernel(); 1097 mutex_lock(&i2o_cfg_mutex);
1097 spin_lock_irqsave(&i2o_config_lock, flags); 1098 spin_lock_irqsave(&i2o_config_lock, flags);
1098 for (q = &open_files; (p = *q) != NULL; q = &p->next) { 1099 for (q = &open_files; (p = *q) != NULL; q = &p->next) {
1099 if (p->q_id == id) { 1100 if (p->q_id == id) {
@@ -1103,7 +1104,7 @@ static int cfg_release(struct inode *inode, struct file *file)
1103 } 1104 }
1104 } 1105 }
1105 spin_unlock_irqrestore(&i2o_config_lock, flags); 1106 spin_unlock_irqrestore(&i2o_config_lock, flags);
1106 unlock_kernel(); 1107 mutex_unlock(&i2o_cfg_mutex);
1107 1108
1108 return 0; 1109 return 0;
1109} 1110}