aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdchar.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2010-06-02 08:28:52 -0400
committerArnd Bergmann <arnd@arndb.de>2010-09-15 15:00:46 -0400
commit5aa82940b23d0c6e4083d48e387a16b8ad530a47 (patch)
treeea6fe6dd8a545e104aa5a139d048123a522897a7 /drivers/mtd/mtdchar.c
parentc45d15d24eb2b49bf734e1e5e7e103befb76b19b (diff)
mtd: 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> Cc: David Woodhouse <David.Woodhouse@intel.com> Cc: linux-mtd@lists.infradead.org
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-rw-r--r--drivers/mtd/mtdchar.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index a825002123c8..5ef45487b65f 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -26,7 +26,7 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/sched.h> 28#include <linux/sched.h>
29#include <linux/smp_lock.h> 29#include <linux/mutex.h>
30#include <linux/backing-dev.h> 30#include <linux/backing-dev.h>
31#include <linux/compat.h> 31#include <linux/compat.h>
32#include <linux/mount.h> 32#include <linux/mount.h>
@@ -37,6 +37,7 @@
37#include <asm/uaccess.h> 37#include <asm/uaccess.h>
38 38
39#define MTD_INODE_FS_MAGIC 0x11307854 39#define MTD_INODE_FS_MAGIC 0x11307854
40static DEFINE_MUTEX(mtd_mutex);
40static struct vfsmount *mtd_inode_mnt __read_mostly; 41static struct vfsmount *mtd_inode_mnt __read_mostly;
41 42
42/* 43/*
@@ -90,7 +91,7 @@ static int mtd_open(struct inode *inode, struct file *file)
90 if ((file->f_mode & FMODE_WRITE) && (minor & 1)) 91 if ((file->f_mode & FMODE_WRITE) && (minor & 1))
91 return -EACCES; 92 return -EACCES;
92 93
93 lock_kernel(); 94 mutex_lock(&mtd_mutex);
94 mtd = get_mtd_device(NULL, devnum); 95 mtd = get_mtd_device(NULL, devnum);
95 96
96 if (IS_ERR(mtd)) { 97 if (IS_ERR(mtd)) {
@@ -138,7 +139,7 @@ static int mtd_open(struct inode *inode, struct file *file)
138 file->private_data = mfi; 139 file->private_data = mfi;
139 140
140out: 141out:
141 unlock_kernel(); 142 mutex_unlock(&mtd_mutex);
142 return ret; 143 return ret;
143} /* mtd_open */ 144} /* mtd_open */
144 145
@@ -866,9 +867,9 @@ static long mtd_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
866{ 867{
867 int ret; 868 int ret;
868 869
869 lock_kernel(); 870 mutex_lock(&mtd_mutex);
870 ret = mtd_ioctl(file, cmd, arg); 871 ret = mtd_ioctl(file, cmd, arg);
871 unlock_kernel(); 872 mutex_unlock(&mtd_mutex);
872 873
873 return ret; 874 return ret;
874} 875}
@@ -892,7 +893,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd,
892 void __user *argp = compat_ptr(arg); 893 void __user *argp = compat_ptr(arg);
893 int ret = 0; 894 int ret = 0;
894 895
895 lock_kernel(); 896 mutex_lock(&mtd_mutex);
896 897
897 switch (cmd) { 898 switch (cmd) {
898 case MEMWRITEOOB32: 899 case MEMWRITEOOB32:
@@ -927,7 +928,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd,
927 ret = mtd_ioctl(file, cmd, (unsigned long)argp); 928 ret = mtd_ioctl(file, cmd, (unsigned long)argp);
928 } 929 }
929 930
930 unlock_kernel(); 931 mutex_unlock(&mtd_mutex);
931 932
932 return ret; 933 return ret;
933} 934}