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>
This commit is contained in:

committed by
David S. Miller

parent
f8324e20f8
commit
a3108ca232
@@ -33,7 +33,7 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/smp_lock.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/init.h>
|
||||
@@ -61,6 +61,7 @@ typedef struct openprom_private_data
|
||||
} DATA;
|
||||
|
||||
/* ID of the PROM node containing all of the EEPROM options. */
|
||||
static DEFINE_MUTEX(openprom_mutex);
|
||||
static struct device_node *options_node;
|
||||
|
||||
/*
|
||||
@@ -316,7 +317,7 @@ static long openprom_sunos_ioctl(struct file * file,
|
||||
if (bufsize < 0)
|
||||
return bufsize;
|
||||
|
||||
lock_kernel();
|
||||
mutex_lock(&openprom_mutex);
|
||||
|
||||
switch (cmd) {
|
||||
case OPROMGETOPT:
|
||||
@@ -367,7 +368,7 @@ static long openprom_sunos_ioctl(struct file * file,
|
||||
}
|
||||
|
||||
kfree(opp);
|
||||
unlock_kernel();
|
||||
mutex_unlock(&openprom_mutex);
|
||||
|
||||
return error;
|
||||
}
|
||||
@@ -558,7 +559,7 @@ static int openprom_bsd_ioctl(struct file * file,
|
||||
void __user *argp = (void __user *)arg;
|
||||
int err;
|
||||
|
||||
lock_kernel();
|
||||
mutex_lock(&openprom_mutex);
|
||||
switch (cmd) {
|
||||
case OPIOCGET:
|
||||
err = opiocget(argp, data);
|
||||
@@ -589,7 +590,7 @@ static int openprom_bsd_ioctl(struct file * file,
|
||||
err = -EINVAL;
|
||||
break;
|
||||
};
|
||||
unlock_kernel();
|
||||
mutex_unlock(&openprom_mutex);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -697,11 +698,11 @@ static int openprom_open(struct inode * inode, struct file * file)
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
lock_kernel();
|
||||
mutex_lock(&openprom_mutex);
|
||||
data->current_node = of_find_node_by_path("/");
|
||||
data->lastnode = data->current_node;
|
||||
file->private_data = (void *) data;
|
||||
unlock_kernel();
|
||||
mutex_unlock(&openprom_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user