aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/ch.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:45 -0400
commitc45d15d24eb2b49bf734e1e5e7e103befb76b19b (patch)
treedd768c089fd3393e8fa2c4f4fb50cedb1044037d /drivers/scsi/ch.c
parent49553c2ef88749dd502687f4eb9c258bb10a4f44 (diff)
scsi: 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: linux-scsi@vger.kernel.org Cc: "James E.J. Bottomley" <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/ch.c')
-rw-r--r--drivers/scsi/ch.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index d6532187f616..e805c8fda239 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -22,7 +22,6 @@
22#include <linux/chio.h> /* here are all the ioctls */ 22#include <linux/chio.h> /* here are all the ioctls */
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/idr.h> 24#include <linux/idr.h>
25#include <linux/smp_lock.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
27 26
28#include <scsi/scsi.h> 27#include <scsi/scsi.h>
@@ -44,6 +43,7 @@ MODULE_LICENSE("GPL");
44MODULE_ALIAS_CHARDEV_MAJOR(SCSI_CHANGER_MAJOR); 43MODULE_ALIAS_CHARDEV_MAJOR(SCSI_CHANGER_MAJOR);
45MODULE_ALIAS_SCSI_DEVICE(TYPE_MEDIUM_CHANGER); 44MODULE_ALIAS_SCSI_DEVICE(TYPE_MEDIUM_CHANGER);
46 45
46static DEFINE_MUTEX(ch_mutex);
47static int init = 1; 47static int init = 1;
48module_param(init, int, 0444); 48module_param(init, int, 0444);
49MODULE_PARM_DESC(init, \ 49MODULE_PARM_DESC(init, \
@@ -581,19 +581,19 @@ ch_open(struct inode *inode, struct file *file)
581 scsi_changer *ch; 581 scsi_changer *ch;
582 int minor = iminor(inode); 582 int minor = iminor(inode);
583 583
584 lock_kernel(); 584 mutex_lock(&ch_mutex);
585 spin_lock(&ch_index_lock); 585 spin_lock(&ch_index_lock);
586 ch = idr_find(&ch_index_idr, minor); 586 ch = idr_find(&ch_index_idr, minor);
587 587
588 if (NULL == ch || scsi_device_get(ch->device)) { 588 if (NULL == ch || scsi_device_get(ch->device)) {
589 spin_unlock(&ch_index_lock); 589 spin_unlock(&ch_index_lock);
590 unlock_kernel(); 590 mutex_unlock(&ch_mutex);
591 return -ENXIO; 591 return -ENXIO;
592 } 592 }
593 spin_unlock(&ch_index_lock); 593 spin_unlock(&ch_index_lock);
594 594
595 file->private_data = ch; 595 file->private_data = ch;
596 unlock_kernel(); 596 mutex_unlock(&ch_mutex);
597 return 0; 597 return 0;
598} 598}
599 599