aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sbus/char/flash.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2010-07-21 02:36:39 -0400
committerDavid S. Miller <davem@davemloft.net>2010-07-21 02:36:39 -0400
commita3108ca2323dec0f6321c3f7706cdaed51f694ea (patch)
treeae3ef899219893cf3de5d543d4e3dc7027c00212 /drivers/sbus/char/flash.c
parentf8324e20f8289dffc646d64366332e05eaacab25 (diff)
sbus: 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> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/sbus/char/flash.c')
-rw-r--r--drivers/sbus/char/flash.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/sbus/char/flash.c b/drivers/sbus/char/flash.c
index 368d66294d83..ed9494e18859 100644
--- a/drivers/sbus/char/flash.c
+++ b/drivers/sbus/char/flash.c
@@ -10,7 +10,7 @@
10#include <linux/fcntl.h> 10#include <linux/fcntl.h>
11#include <linux/poll.h> 11#include <linux/poll.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/smp_lock.h> 13#include <linux/mutex.h>
14#include <linux/spinlock.h> 14#include <linux/spinlock.h>
15#include <linux/mm.h> 15#include <linux/mm.h>
16#include <linux/of.h> 16#include <linux/of.h>
@@ -22,6 +22,7 @@
22#include <asm/io.h> 22#include <asm/io.h>
23#include <asm/upa.h> 23#include <asm/upa.h>
24 24
25static DEFINE_MUTEX(flash_mutex);
25static DEFINE_SPINLOCK(flash_lock); 26static DEFINE_SPINLOCK(flash_lock);
26static struct { 27static struct {
27 unsigned long read_base; /* Physical read address */ 28 unsigned long read_base; /* Physical read address */
@@ -80,7 +81,7 @@ flash_mmap(struct file *file, struct vm_area_struct *vma)
80static long long 81static long long
81flash_llseek(struct file *file, long long offset, int origin) 82flash_llseek(struct file *file, long long offset, int origin)
82{ 83{
83 lock_kernel(); 84 mutex_lock(&flash_mutex);
84 switch (origin) { 85 switch (origin) {
85 case 0: 86 case 0:
86 file->f_pos = offset; 87 file->f_pos = offset;
@@ -94,10 +95,10 @@ flash_llseek(struct file *file, long long offset, int origin)
94 file->f_pos = flash.read_size; 95 file->f_pos = flash.read_size;
95 break; 96 break;
96 default: 97 default:
97 unlock_kernel(); 98 mutex_unlock(&flash_mutex);
98 return -EINVAL; 99 return -EINVAL;
99 } 100 }
100 unlock_kernel(); 101 mutex_unlock(&flash_mutex);
101 return file->f_pos; 102 return file->f_pos;
102} 103}
103 104
@@ -125,13 +126,13 @@ flash_read(struct file * file, char __user * buf,
125static int 126static int
126flash_open(struct inode *inode, struct file *file) 127flash_open(struct inode *inode, struct file *file)
127{ 128{
128 lock_kernel(); 129 mutex_lock(&flash_mutex);
129 if (test_and_set_bit(0, (void *)&flash.busy) != 0) { 130 if (test_and_set_bit(0, (void *)&flash.busy) != 0) {
130 unlock_kernel(); 131 mutex_unlock(&flash_mutex);
131 return -EBUSY; 132 return -EBUSY;
132 } 133 }
133 134
134 unlock_kernel(); 135 mutex_unlock(&flash_mutex);
135 return 0; 136 return 0;
136} 137}
137 138