aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
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
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')
-rw-r--r--drivers/sbus/char/display7seg.c8
-rw-r--r--drivers/sbus/char/envctrl.c2
-rw-r--r--drivers/sbus/char/flash.c15
-rw-r--r--drivers/sbus/char/openprom.c15
-rw-r--r--drivers/sbus/char/uctrl.c7
5 files changed, 24 insertions, 23 deletions
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index 7baf1b644039..4ad4d2c91075 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -13,7 +13,7 @@
13#include <linux/miscdevice.h> 13#include <linux/miscdevice.h>
14#include <linux/ioport.h> /* request_region */ 14#include <linux/ioport.h> /* request_region */
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/smp_lock.h> 16#include <linux/mutex.h>
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/of_device.h> 18#include <linux/of_device.h>
19#include <asm/atomic.h> 19#include <asm/atomic.h>
@@ -26,6 +26,7 @@
26#define DRIVER_NAME "d7s" 26#define DRIVER_NAME "d7s"
27#define PFX DRIVER_NAME ": " 27#define PFX DRIVER_NAME ": "
28 28
29static DEFINE_MUTEX(d7s_mutex);
29static int sol_compat = 0; /* Solaris compatibility mode */ 30static int sol_compat = 0; /* Solaris compatibility mode */
30 31
31/* Solaris compatibility flag - 32/* Solaris compatibility flag -
@@ -74,7 +75,6 @@ static int d7s_open(struct inode *inode, struct file *f)
74{ 75{
75 if (D7S_MINOR != iminor(inode)) 76 if (D7S_MINOR != iminor(inode))
76 return -ENODEV; 77 return -ENODEV;
77 cycle_kernel_lock();
78 atomic_inc(&d7s_users); 78 atomic_inc(&d7s_users);
79 return 0; 79 return 0;
80} 80}
@@ -110,7 +110,7 @@ static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
110 if (D7S_MINOR != iminor(file->f_path.dentry->d_inode)) 110 if (D7S_MINOR != iminor(file->f_path.dentry->d_inode))
111 return -ENODEV; 111 return -ENODEV;
112 112
113 lock_kernel(); 113 mutex_lock(&d7s_mutex);
114 switch (cmd) { 114 switch (cmd) {
115 case D7SIOCWR: 115 case D7SIOCWR:
116 /* assign device register values we mask-out D7S_FLIP 116 /* assign device register values we mask-out D7S_FLIP
@@ -151,7 +151,7 @@ static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
151 writeb(regs, p->regs); 151 writeb(regs, p->regs);
152 break; 152 break;
153 }; 153 };
154 unlock_kernel(); 154 mutex_unlock(&d7s_mutex);
155 155
156 return error; 156 return error;
157} 157}
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index c8166ecf5276..bd0bbc621351 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -27,7 +27,6 @@
27#include <linux/kmod.h> 27#include <linux/kmod.h>
28#include <linux/reboot.h> 28#include <linux/reboot.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/smp_lock.h>
31#include <linux/of.h> 30#include <linux/of.h>
32#include <linux/of_device.h> 31#include <linux/of_device.h>
33 32
@@ -699,7 +698,6 @@ envctrl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
699static int 698static int
700envctrl_open(struct inode *inode, struct file *file) 699envctrl_open(struct inode *inode, struct file *file)
701{ 700{
702 cycle_kernel_lock();
703 file->private_data = NULL; 701 file->private_data = NULL;
704 return 0; 702 return 0;
705} 703}
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
diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
index aacbe14e2e7a..8d6e508222b8 100644
--- a/drivers/sbus/char/openprom.c
+++ b/drivers/sbus/char/openprom.c
@@ -33,7 +33,7 @@
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/smp_lock.h> 36#include <linux/mutex.h>
37#include <linux/string.h> 37#include <linux/string.h>
38#include <linux/miscdevice.h> 38#include <linux/miscdevice.h>
39#include <linux/init.h> 39#include <linux/init.h>
@@ -61,6 +61,7 @@ typedef struct openprom_private_data
61} DATA; 61} DATA;
62 62
63/* ID of the PROM node containing all of the EEPROM options. */ 63/* ID of the PROM node containing all of the EEPROM options. */
64static DEFINE_MUTEX(openprom_mutex);
64static struct device_node *options_node; 65static struct device_node *options_node;
65 66
66/* 67/*
@@ -316,7 +317,7 @@ static long openprom_sunos_ioctl(struct file * file,
316 if (bufsize < 0) 317 if (bufsize < 0)
317 return bufsize; 318 return bufsize;
318 319
319 lock_kernel(); 320 mutex_lock(&openprom_mutex);
320 321
321 switch (cmd) { 322 switch (cmd) {
322 case OPROMGETOPT: 323 case OPROMGETOPT:
@@ -367,7 +368,7 @@ static long openprom_sunos_ioctl(struct file * file,
367 } 368 }
368 369
369 kfree(opp); 370 kfree(opp);
370 unlock_kernel(); 371 mutex_unlock(&openprom_mutex);
371 372
372 return error; 373 return error;
373} 374}
@@ -558,7 +559,7 @@ static int openprom_bsd_ioctl(struct file * file,
558 void __user *argp = (void __user *)arg; 559 void __user *argp = (void __user *)arg;
559 int err; 560 int err;
560 561
561 lock_kernel(); 562 mutex_lock(&openprom_mutex);
562 switch (cmd) { 563 switch (cmd) {
563 case OPIOCGET: 564 case OPIOCGET:
564 err = opiocget(argp, data); 565 err = opiocget(argp, data);
@@ -589,7 +590,7 @@ static int openprom_bsd_ioctl(struct file * file,
589 err = -EINVAL; 590 err = -EINVAL;
590 break; 591 break;
591 }; 592 };
592 unlock_kernel(); 593 mutex_unlock(&openprom_mutex);
593 594
594 return err; 595 return err;
595} 596}
@@ -697,11 +698,11 @@ static int openprom_open(struct inode * inode, struct file * file)
697 if (!data) 698 if (!data)
698 return -ENOMEM; 699 return -ENOMEM;
699 700
700 lock_kernel(); 701 mutex_lock(&openprom_mutex);
701 data->current_node = of_find_node_by_path("/"); 702 data->current_node = of_find_node_by_path("/");
702 data->lastnode = data->current_node; 703 data->lastnode = data->current_node;
703 file->private_data = (void *) data; 704 file->private_data = (void *) data;
704 unlock_kernel(); 705 mutex_unlock(&openprom_mutex);
705 706
706 return 0; 707 return 0;
707} 708}
diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
index 5f253665a1da..079da4cb45a5 100644
--- a/drivers/sbus/char/uctrl.c
+++ b/drivers/sbus/char/uctrl.c
@@ -9,7 +9,7 @@
9#include <linux/delay.h> 9#include <linux/delay.h>
10#include <linux/interrupt.h> 10#include <linux/interrupt.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/smp_lock.h> 12#include <linux/mutex.h>
13#include <linux/ioport.h> 13#include <linux/ioport.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/miscdevice.h> 15#include <linux/miscdevice.h>
@@ -72,6 +72,7 @@ struct ts102_regs {
72#define UCTRL_STAT_RXNE_STA 0x04 /* receive FIFO not empty status */ 72#define UCTRL_STAT_RXNE_STA 0x04 /* receive FIFO not empty status */
73#define UCTRL_STAT_RXO_STA 0x08 /* receive FIFO overflow status */ 73#define UCTRL_STAT_RXO_STA 0x08 /* receive FIFO overflow status */
74 74
75static DEFINE_MUTEX(uctrl_mutex);
75static const char *uctrl_extstatus[16] = { 76static const char *uctrl_extstatus[16] = {
76 "main power available", 77 "main power available",
77 "internal battery attached", 78 "internal battery attached",
@@ -210,10 +211,10 @@ uctrl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
210static int 211static int
211uctrl_open(struct inode *inode, struct file *file) 212uctrl_open(struct inode *inode, struct file *file)
212{ 213{
213 lock_kernel(); 214 mutex_lock(&uctrl_mutex);
214 uctrl_get_event_status(global_driver); 215 uctrl_get_event_status(global_driver);
215 uctrl_get_external_status(global_driver); 216 uctrl_get_external_status(global_driver);
216 unlock_kernel(); 217 mutex_unlock(&uctrl_mutex);
217 return 0; 218 return 0;
218} 219}
219 220