aboutsummaryrefslogtreecommitdiffstats
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:48 -0400
commit609146fdb319cebce93be550938ab852f7bade90 (patch)
tree9cac0f94d17294c2a58ec1d39f86e5d7e5bb1c82
parentd851b6e04ee978b0c1b187bee682592aa72f22ea (diff)
ipmi: 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> Acked-by: Corey Minyard <cminyard@mvista.com> Cc: openipmi-developer@lists.sourceforge.net
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c14
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c8
2 files changed, 11 insertions, 11 deletions
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index d8ec92a38980..44833de47728 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -44,7 +44,6 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/device.h> 45#include <linux/device.h>
46#include <linux/compat.h> 46#include <linux/compat.h>
47#include <linux/smp_lock.h>
48 47
49struct ipmi_file_private 48struct ipmi_file_private
50{ 49{
@@ -59,6 +58,7 @@ struct ipmi_file_private
59 unsigned int default_retry_time_ms; 58 unsigned int default_retry_time_ms;
60}; 59};
61 60
61static DEFINE_MUTEX(ipmi_mutex);
62static void file_receive_handler(struct ipmi_recv_msg *msg, 62static void file_receive_handler(struct ipmi_recv_msg *msg,
63 void *handler_data) 63 void *handler_data)
64{ 64{
@@ -102,9 +102,9 @@ static int ipmi_fasync(int fd, struct file *file, int on)
102 struct ipmi_file_private *priv = file->private_data; 102 struct ipmi_file_private *priv = file->private_data;
103 int result; 103 int result;
104 104
105 lock_kernel(); /* could race against open() otherwise */ 105 mutex_lock(&ipmi_mutex); /* could race against open() otherwise */
106 result = fasync_helper(fd, file, on, &priv->fasync_queue); 106 result = fasync_helper(fd, file, on, &priv->fasync_queue);
107 unlock_kernel(); 107 mutex_unlock(&ipmi_mutex);
108 108
109 return (result); 109 return (result);
110} 110}
@@ -125,7 +125,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
125 if (!priv) 125 if (!priv)
126 return -ENOMEM; 126 return -ENOMEM;
127 127
128 lock_kernel(); 128 mutex_lock(&ipmi_mutex);
129 priv->file = file; 129 priv->file = file;
130 130
131 rv = ipmi_create_user(if_num, 131 rv = ipmi_create_user(if_num,
@@ -150,7 +150,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
150 priv->default_retry_time_ms = 0; 150 priv->default_retry_time_ms = 0;
151 151
152out: 152out:
153 unlock_kernel(); 153 mutex_unlock(&ipmi_mutex);
154 return rv; 154 return rv;
155} 155}
156 156
@@ -639,9 +639,9 @@ static long ipmi_unlocked_ioctl(struct file *file,
639{ 639{
640 int ret; 640 int ret;
641 641
642 lock_kernel(); 642 mutex_lock(&ipmi_mutex);
643 ret = ipmi_ioctl(file, cmd, data); 643 ret = ipmi_ioctl(file, cmd, data);
644 unlock_kernel(); 644 mutex_unlock(&ipmi_mutex);
645 645
646 return ret; 646 return ret;
647} 647}
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 654d566ca57c..ed10b741962d 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -35,7 +35,7 @@
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36#include <linux/ipmi.h> 36#include <linux/ipmi.h>
37#include <linux/ipmi_smi.h> 37#include <linux/ipmi_smi.h>
38#include <linux/smp_lock.h> 38#include <linux/mutex.h>
39#include <linux/watchdog.h> 39#include <linux/watchdog.h>
40#include <linux/miscdevice.h> 40#include <linux/miscdevice.h>
41#include <linux/init.h> 41#include <linux/init.h>
@@ -149,6 +149,7 @@
149#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int) 149#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int)
150#endif 150#endif
151 151
152static DEFINE_MUTEX(ipmi_watchdog_mutex);
152static int nowayout = WATCHDOG_NOWAYOUT; 153static int nowayout = WATCHDOG_NOWAYOUT;
153 154
154static ipmi_user_t watchdog_user; 155static ipmi_user_t watchdog_user;
@@ -748,9 +749,9 @@ static long ipmi_unlocked_ioctl(struct file *file,
748{ 749{
749 int ret; 750 int ret;
750 751
751 lock_kernel(); 752 mutex_lock(&ipmi_watchdog_mutex);
752 ret = ipmi_ioctl(file, cmd, arg); 753 ret = ipmi_ioctl(file, cmd, arg);
753 unlock_kernel(); 754 mutex_unlock(&ipmi_watchdog_mutex);
754 755
755 return ret; 756 return ret;
756} 757}
@@ -844,7 +845,6 @@ static int ipmi_open(struct inode *ino, struct file *filep)
844 if (test_and_set_bit(0, &ipmi_wdog_open)) 845 if (test_and_set_bit(0, &ipmi_wdog_open))
845 return -EBUSY; 846 return -EBUSY;
846 847
847 cycle_kernel_lock();
848 848
849 /* 849 /*
850 * Don't start the timer now, let it start on the 850 * Don't start the timer now, let it start on the