Skip to content

Commit a3108ca

Browse files
arndbdavem330
authored andcommitted
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>
1 parent f8324e2 commit a3108ca

5 files changed

Lines changed: 24 additions & 23 deletions

File tree

‎drivers/sbus/char/display7seg.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <linux/miscdevice.h>
1414
#include <linux/ioport.h> /* request_region */
1515
#include <linux/slab.h>
16-
#include <linux/smp_lock.h>
16+
#include <linux/mutex.h>
1717
#include <linux/of.h>
1818
#include <linux/of_device.h>
1919
#include <asm/atomic.h>
@@ -26,6 +26,7 @@
2626
#define DRIVER_NAME "d7s"
2727
#define PFX DRIVER_NAME ": "
2828

29+
static DEFINE_MUTEX(d7s_mutex);
2930
static int sol_compat = 0; /* Solaris compatibility mode */
3031

3132
/* Solaris compatibility flag -
@@ -74,7 +75,6 @@ static int d7s_open(struct inode *inode, struct file *f)
7475
{
7576
if (D7S_MINOR != iminor(inode))
7677
return -ENODEV;
77-
cycle_kernel_lock();
7878
atomic_inc(&d7s_users);
7979
return 0;
8080
}
@@ -110,7 +110,7 @@ static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
110110
if (D7S_MINOR != iminor(file->f_path.dentry->d_inode))
111111
return -ENODEV;
112112

113-
lock_kernel();
113+
mutex_lock(&d7s_mutex);
114114
switch (cmd) {
115115
case D7SIOCWR:
116116
/* 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)
151151
writeb(regs, p->regs);
152152
break;
153153
};
154-
unlock_kernel();
154+
mutex_unlock(&d7s_mutex);
155155

156156
return error;
157157
}

‎drivers/sbus/char/envctrl.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <linux/kmod.h>
2828
#include <linux/reboot.h>
2929
#include <linux/slab.h>
30-
#include <linux/smp_lock.h>
3130
#include <linux/of.h>
3231
#include <linux/of_device.h>
3332

@@ -699,7 +698,6 @@ envctrl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
699698
static int
700699
envctrl_open(struct inode *inode, struct file *file)
701700
{
702-
cycle_kernel_lock();
703701
file->private_data = NULL;
704702
return 0;
705703
}

‎drivers/sbus/char/flash.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <linux/fcntl.h>
1111
#include <linux/poll.h>
1212
#include <linux/init.h>
13-
#include <linux/smp_lock.h>
13+
#include <linux/mutex.h>
1414
#include <linux/spinlock.h>
1515
#include <linux/mm.h>
1616
#include <linux/of.h>
@@ -22,6 +22,7 @@
2222
#include <asm/io.h>
2323
#include <asm/upa.h>
2424

25+
static DEFINE_MUTEX(flash_mutex);
2526
static DEFINE_SPINLOCK(flash_lock);
2627
static struct {
2728
unsigned long read_base; /* Physical read address */
@@ -80,7 +81,7 @@ flash_mmap(struct file *file, struct vm_area_struct *vma)
8081
static long long
8182
flash_llseek(struct file *file, long long offset, int origin)
8283
{
83-
lock_kernel();
84+
mutex_lock(&flash_mutex);
8485
switch (origin) {
8586
case 0:
8687
file->f_pos = offset;
@@ -94,10 +95,10 @@ flash_llseek(struct file *file, long long offset, int origin)
9495
file->f_pos = flash.read_size;
9596
break;
9697
default:
97-
unlock_kernel();
98+
mutex_unlock(&flash_mutex);
9899
return -EINVAL;
99100
}
100-
unlock_kernel();
101+
mutex_unlock(&flash_mutex);
101102
return file->f_pos;
102103
}
103104

@@ -125,13 +126,13 @@ flash_read(struct file * file, char __user * buf,
125126
static int
126127
flash_open(struct inode *inode, struct file *file)
127128
{
128-
lock_kernel();
129+
mutex_lock(&flash_mutex);
129130
if (test_and_set_bit(0, (void *)&flash.busy) != 0) {
130-
unlock_kernel();
131+
mutex_unlock(&flash_mutex);
131132
return -EBUSY;
132133
}
133134

134-
unlock_kernel();
135+
mutex_unlock(&flash_mutex);
135136
return 0;
136137
}
137138

‎drivers/sbus/char/openprom.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <linux/kernel.h>
3434
#include <linux/errno.h>
3535
#include <linux/slab.h>
36-
#include <linux/smp_lock.h>
36+
#include <linux/mutex.h>
3737
#include <linux/string.h>
3838
#include <linux/miscdevice.h>
3939
#include <linux/init.h>
@@ -61,6 +61,7 @@ typedef struct openprom_private_data
6161
} DATA;
6262

6363
/* ID of the PROM node containing all of the EEPROM options. */
64+
static DEFINE_MUTEX(openprom_mutex);
6465
static struct device_node *options_node;
6566

6667
/*
@@ -316,7 +317,7 @@ static long openprom_sunos_ioctl(struct file * file,
316317
if (bufsize < 0)
317318
return bufsize;
318319

319-
lock_kernel();
320+
mutex_lock(&openprom_mutex);
320321

321322
switch (cmd) {
322323
case OPROMGETOPT:
@@ -367,7 +368,7 @@ static long openprom_sunos_ioctl(struct file * file,
367368
}
368369

369370
kfree(opp);
370-
unlock_kernel();
371+
mutex_unlock(&openprom_mutex);
371372

372373
return error;
373374
}
@@ -558,7 +559,7 @@ static int openprom_bsd_ioctl(struct file * file,
558559
void __user *argp = (void __user *)arg;
559560
int err;
560561

561-
lock_kernel();
562+
mutex_lock(&openprom_mutex);
562563
switch (cmd) {
563564
case OPIOCGET:
564565
err = opiocget(argp, data);
@@ -589,7 +590,7 @@ static int openprom_bsd_ioctl(struct file * file,
589590
err = -EINVAL;
590591
break;
591592
};
592-
unlock_kernel();
593+
mutex_unlock(&openprom_mutex);
593594

594595
return err;
595596
}
@@ -697,11 +698,11 @@ static int openprom_open(struct inode * inode, struct file * file)
697698
if (!data)
698699
return -ENOMEM;
699700

700-
lock_kernel();
701+
mutex_lock(&openprom_mutex);
701702
data->current_node = of_find_node_by_path("/");
702703
data->lastnode = data->current_node;
703704
file->private_data = (void *) data;
704-
unlock_kernel();
705+
mutex_unlock(&openprom_mutex);
705706

706707
return 0;
707708
}

‎drivers/sbus/char/uctrl.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <linux/delay.h>
1010
#include <linux/interrupt.h>
1111
#include <linux/slab.h>
12-
#include <linux/smp_lock.h>
12+
#include <linux/mutex.h>
1313
#include <linux/ioport.h>
1414
#include <linux/init.h>
1515
#include <linux/miscdevice.h>
@@ -72,6 +72,7 @@ struct ts102_regs {
7272
#define UCTRL_STAT_RXNE_STA 0x04 /* receive FIFO not empty status */
7373
#define UCTRL_STAT_RXO_STA 0x08 /* receive FIFO overflow status */
7474

75+
static DEFINE_MUTEX(uctrl_mutex);
7576
static const char *uctrl_extstatus[16] = {
7677
"main power available",
7778
"internal battery attached",
@@ -210,10 +211,10 @@ uctrl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
210211
static int
211212
uctrl_open(struct inode *inode, struct file *file)
212213
{
213-
lock_kernel();
214+
mutex_lock(&uctrl_mutex);
214215
uctrl_get_event_status(global_driver);
215216
uctrl_get_external_status(global_driver);
216-
unlock_kernel();
217+
mutex_unlock(&uctrl_mutex);
217218
return 0;
218219
}
219220

0 commit comments

Comments
 (0)