From 76a64921dad9acd76270dc74249f0dfe11c84bb8 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Sun, 11 Jul 2010 11:18:53 +0000 Subject: isdn: 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.*/d' ${file} else sed -i 's/include.*.*$/include /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.*\/d' ${file} \ -e '/cycle_kernel_lock()/d' fi Signed-off-by: Arnd Bergmann Cc: Karsten Keil Cc: netdev@vger.kernel.org Signed-off-by: David S. Miller --- drivers/isdn/i4l/isdn_common.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'drivers/isdn/i4l') diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c index a44cdb492ea9..15632bd2f643 100644 --- a/drivers/isdn/i4l/isdn_common.c +++ b/drivers/isdn/i4l/isdn_common.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include "isdn_common.h" #include "isdn_tty.h" #include "isdn_net.h" @@ -42,6 +42,7 @@ MODULE_LICENSE("GPL"); isdn_dev *dev; +static DEFINE_MUTEX(isdn_mutex); static char *isdn_revision = "$Revision: 1.1.2.3 $"; extern char *isdn_net_revision; @@ -1070,7 +1071,7 @@ isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off) int retval; char *p; - lock_kernel(); + mutex_lock(&isdn_mutex); if (minor == ISDN_MINOR_STATUS) { if (!file->private_data) { if (file->f_flags & O_NONBLOCK) { @@ -1163,7 +1164,7 @@ isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off) #endif retval = -ENODEV; out: - unlock_kernel(); + mutex_unlock(&isdn_mutex); return retval; } @@ -1180,7 +1181,7 @@ isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off if (!dev->drivers) return -ENODEV; - lock_kernel(); + mutex_lock(&isdn_mutex); if (minor <= ISDN_MINOR_BMAX) { printk(KERN_WARNING "isdn_write minor %d obsolete!\n", minor); drvidx = isdn_minor2drv(minor); @@ -1225,7 +1226,7 @@ isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off #endif retval = -ENODEV; out: - unlock_kernel(); + mutex_unlock(&isdn_mutex); return retval; } @@ -1236,7 +1237,7 @@ isdn_poll(struct file *file, poll_table * wait) unsigned int minor = iminor(file->f_path.dentry->d_inode); int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL); - lock_kernel(); + mutex_lock(&isdn_mutex); if (minor == ISDN_MINOR_STATUS) { poll_wait(file, &(dev->info_waitq), wait); /* mask = POLLOUT | POLLWRNORM; */ @@ -1266,7 +1267,7 @@ isdn_poll(struct file *file, poll_table * wait) #endif mask = POLLERR; out: - unlock_kernel(); + mutex_unlock(&isdn_mutex); return mask; } @@ -1727,9 +1728,9 @@ isdn_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int ret; - lock_kernel(); + mutex_lock(&isdn_mutex); ret = isdn_ioctl(file, cmd, arg); - unlock_kernel(); + mutex_unlock(&isdn_mutex); return ret; } @@ -1745,7 +1746,7 @@ isdn_open(struct inode *ino, struct file *filep) int chidx; int retval = -ENODEV; - lock_kernel(); + mutex_lock(&isdn_mutex); if (minor == ISDN_MINOR_STATUS) { infostruct *p; @@ -1796,7 +1797,7 @@ isdn_open(struct inode *ino, struct file *filep) #endif out: nonseekable_open(ino, filep); - unlock_kernel(); + mutex_unlock(&isdn_mutex); return retval; } @@ -1805,7 +1806,7 @@ isdn_close(struct inode *ino, struct file *filep) { uint minor = iminor(ino); - lock_kernel(); + mutex_lock(&isdn_mutex); if (minor == ISDN_MINOR_STATUS) { infostruct *p = dev->infochain; infostruct *q = NULL; @@ -1839,7 +1840,7 @@ isdn_close(struct inode *ino, struct file *filep) #endif out: - unlock_kernel(); + mutex_unlock(&isdn_mutex); return 0; } -- cgit v1.2.2