cris: 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: Jesper Nilsson <jesper.nilsson@axis.com>
This commit is contained in:
Jesper Nilsson 2010-07-30 19:15:24 +02:00
parent 90276a1a64
commit 096b7bdc86
4 changed files with 6 additions and 12 deletions

View File

@ -28,7 +28,6 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/smp_lock.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include "i2c.h" #include "i2c.h"
@ -376,7 +375,6 @@ int __init eeprom_init(void)
/* Opens the device. */ /* Opens the device. */
static int eeprom_open(struct inode * inode, struct file * file) static int eeprom_open(struct inode * inode, struct file * file)
{ {
cycle_kernel_lock();
if(iminor(inode) != EEPROM_MINOR_NR) if(iminor(inode) != EEPROM_MINOR_NR)
return -ENXIO; return -ENXIO;
if(imajor(inode) != EEPROM_MAJOR_NR) if(imajor(inode) != EEPROM_MAJOR_NR)

View File

@ -14,7 +14,6 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/smp_lock.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/fs.h> #include <linux/fs.h>
@ -566,7 +565,6 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg)
static int static int
i2c_open(struct inode *inode, struct file *filp) i2c_open(struct inode *inode, struct file *filp)
{ {
cycle_kernel_lock();
return 0; return 0;
} }

View File

@ -11,7 +11,6 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/smp_lock.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/stddef.h> #include <linux/stddef.h>
@ -2307,7 +2306,6 @@ static int cryptocop_open(struct inode *inode, struct file *filp)
{ {
int p = iminor(inode); int p = iminor(inode);
cycle_kernel_lock();
if (p != CRYPTOCOP_MINOR) return -EINVAL; if (p != CRYPTOCOP_MINOR) return -EINVAL;
filp->private_data = NULL; filp->private_data = NULL;

View File

@ -32,7 +32,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/smp_lock.h> #include <linux/mutex.h>
#include <asm/etraxi2c.h> #include <asm/etraxi2c.h>
@ -47,6 +47,7 @@
#define D(x) #define D(x)
#define I2C_MAJOR 123 /* LOCAL/EXPERIMENTAL */ #define I2C_MAJOR 123 /* LOCAL/EXPERIMENTAL */
static DEFINE_MUTEX(i2c_mutex);
static const char i2c_name[] = "i2c"; static const char i2c_name[] = "i2c";
#define CLOCK_LOW_TIME 8 #define CLOCK_LOW_TIME 8
@ -636,7 +637,6 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg)
static int static int
i2c_open(struct inode *inode, struct file *filp) i2c_open(struct inode *inode, struct file *filp)
{ {
cycle_kernel_lock();
return 0; return 0;
} }
@ -665,11 +665,11 @@ i2c_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
I2C_ARGREG(arg), I2C_ARGREG(arg),
I2C_ARGVALUE(arg))); I2C_ARGVALUE(arg)));
lock_kernel(); mutex_lock(&i2c_mutex);
ret = i2c_writereg(I2C_ARGSLAVE(arg), ret = i2c_writereg(I2C_ARGSLAVE(arg),
I2C_ARGREG(arg), I2C_ARGREG(arg),
I2C_ARGVALUE(arg)); I2C_ARGVALUE(arg));
unlock_kernel(); mutex_unlock(&i2c_mutex);
return ret; return ret;
case I2C_READREG: case I2C_READREG:
@ -679,9 +679,9 @@ i2c_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
D(printk("i2cr %d %d ", D(printk("i2cr %d %d ",
I2C_ARGSLAVE(arg), I2C_ARGSLAVE(arg),
I2C_ARGREG(arg))); I2C_ARGREG(arg)));
lock_kernel(); mutex_lock(&i2c_mutex);
val = i2c_readreg(I2C_ARGSLAVE(arg), I2C_ARGREG(arg)); val = i2c_readreg(I2C_ARGSLAVE(arg), I2C_ARGREG(arg));
unlock_kernel(); mutex_unlock(&i2c_mutex);
D(printk("= %d\n", val)); D(printk("= %d\n", val));
return val; return val;
} }