aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-10-22 13:49:54 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-22 13:49:54 -0400
commitc37927d4359e81b85de644f8fb08878717cf5f3f (patch)
tree25dabf2d905e1410819d1bdaba0bf5f779100d3c
parent5704e44d283e907623e3775c1262f206a2c48cf3 (diff)
parent2a48fc0ab24241755dc93bfd4f01d68efab47f5a (diff)
Merge branch 'trivial' of git://git.kernel.org/pub/scm/linux/kernel/git/arnd/bkl
* 'trivial' of git://git.kernel.org/pub/scm/linux/kernel/git/arnd/bkl: block: autoconvert trivial BKL users to private mutex drivers: autoconvert trivial BKL users to private mutex ipmi: autoconvert trivial BKL users to private mutex mac: autoconvert trivial BKL users to private mutex mtd: autoconvert trivial BKL users to private mutex scsi: autoconvert trivial BKL users to private mutex Fix up trivial conflicts (due to addition of private mutex right next to deletion of a version string) in drivers/char/pcmcia/cm40[04]0_cs.c
-rw-r--r--block/bsg.c3
-rw-r--r--drivers/block/DAC960.c11
-rw-r--r--drivers/block/amiflop.c19
-rw-r--r--drivers/block/aoe/aoeblk.c9
-rw-r--r--drivers/block/aoe/aoechr.c9
-rw-r--r--drivers/block/ataflop.c15
-rw-r--r--drivers/block/brd.c7
-rw-r--r--drivers/block/cciss.c14
-rw-r--r--drivers/block/cpqarray.c15
-rw-r--r--drivers/block/drbd/drbd_main.c11
-rw-r--r--drivers/block/floppy.c16
-rw-r--r--drivers/block/loop.c11
-rw-r--r--drivers/block/nbd.c7
-rw-r--r--drivers/block/paride/pcd.c15
-rw-r--r--drivers/block/paride/pd.c15
-rw-r--r--drivers/block/paride/pf.c17
-rw-r--r--drivers/block/paride/pg.c7
-rw-r--r--drivers/block/paride/pt.c19
-rw-r--r--drivers/block/pktcdvd.c16
-rw-r--r--drivers/block/swim.c15
-rw-r--r--drivers/block/swim3.c15
-rw-r--r--drivers/block/ub.c15
-rw-r--r--drivers/block/viodasd.c11
-rw-r--r--drivers/block/xd.c7
-rw-r--r--drivers/block/xen-blkfront.c11
-rw-r--r--drivers/block/xsysace.c11
-rw-r--r--drivers/block/z2ram.c15
-rw-r--r--drivers/cdrom/gdrom.c15
-rw-r--r--drivers/cdrom/viocd.c15
-rw-r--r--drivers/char/apm-emulation.c11
-rw-r--r--drivers/char/applicom.c9
-rw-r--r--drivers/char/ds1302.c15
-rw-r--r--drivers/char/ds1620.c8
-rw-r--r--drivers/char/dsp56k.c27
-rw-r--r--drivers/char/dtlk.c8
-rw-r--r--drivers/char/generic_nvram.c7
-rw-r--r--drivers/char/genrtc.c13
-rw-r--r--drivers/char/i8k.c7
-rw-r--r--drivers/char/ip2/ip2main.c8
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c14
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c8
-rw-r--r--drivers/char/lp.c15
-rw-r--r--drivers/char/mbcs.c8
-rw-r--r--drivers/char/mmtimer.c7
-rw-r--r--drivers/char/mwave/mwavedd.c44
-rw-r--r--drivers/char/nvram.c11
-rw-r--r--drivers/char/nwflash.c12
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c12
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c8
-rw-r--r--drivers/char/ppdev.c8
-rw-r--r--drivers/char/rio/rio_linux.c7
-rw-r--r--drivers/char/snsc.c9
-rw-r--r--drivers/char/toshiba.c9
-rw-r--r--drivers/char/viotape.c11
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c6
-rw-r--r--drivers/hwmon/fschmd.c6
-rw-r--r--drivers/hwmon/w83793.c6
-rw-r--r--drivers/ide/ide-cd.c14
-rw-r--r--drivers/ide/ide-disk_ioctl.c7
-rw-r--r--drivers/ide/ide-floppy_ioctl.c7
-rw-r--r--drivers/ide/ide-gd.c10
-rw-r--r--drivers/ide/ide-tape.c19
-rw-r--r--drivers/input/misc/hp_sdc_rtc.c7
-rw-r--r--drivers/macintosh/adb.c10
-rw-r--r--drivers/macintosh/smu.c6
-rw-r--r--drivers/macintosh/via-pmu.c11
-rw-r--r--drivers/md/dm.c10
-rw-r--r--drivers/md/md.c13
-rw-r--r--drivers/memstick/core/mspro_block.c11
-rw-r--r--drivers/message/fusion/mptctl.c15
-rw-r--r--drivers/message/i2o/i2o_block.c15
-rw-r--r--drivers/message/i2o/i2o_config.c23
-rw-r--r--drivers/misc/phantom.c11
-rw-r--r--drivers/mmc/card/block.c10
-rw-r--r--drivers/mtd/mtd_blkdevs.c14
-rw-r--r--drivers/mtd/mtdchar.c15
-rw-r--r--drivers/pci/hotplug/cpqphp_sysfs.c13
-rw-r--r--drivers/rtc/rtc-m41t80.c13
-rw-r--r--drivers/s390/char/tape_block.c13
-rw-r--r--drivers/sbus/char/jsflash.c24
-rw-r--r--drivers/scsi/3w-9xxx.c7
-rw-r--r--drivers/scsi/3w-sas.c7
-rw-r--r--drivers/scsi/3w-xxxx.c9
-rw-r--r--drivers/scsi/aacraid/linit.c15
-rw-r--r--drivers/scsi/ch.c8
-rw-r--r--drivers/scsi/dpt_i2o.c18
-rw-r--r--drivers/scsi/gdth.c11
-rw-r--r--drivers/scsi/megaraid.c8
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.c8
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c2
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_ctl.c11
-rw-r--r--drivers/scsi/osst.c15
-rw-r--r--drivers/scsi/scsi_tgt_if.c2
-rw-r--r--drivers/scsi/sg.c12
-rw-r--r--drivers/scsi/sr.c14
-rw-r--r--drivers/scsi/st.c12
-rw-r--r--drivers/staging/hv/blkvsc_drv.c11
-rw-r--r--drivers/staging/spectra/ffsport.c7
-rw-r--r--drivers/telephony/ixj.c7
-rw-r--r--drivers/watchdog/cpwd.c15
100 files changed, 614 insertions, 556 deletions
diff --git a/block/bsg.c b/block/bsg.c
index 0c00870553a3..d3afe702ede7 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -20,7 +20,6 @@
20#include <linux/uio.h> 20#include <linux/uio.h>
21#include <linux/idr.h> 21#include <linux/idr.h>
22#include <linux/bsg.h> 22#include <linux/bsg.h>
23#include <linux/smp_lock.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25 24
26#include <scsi/scsi.h> 25#include <scsi/scsi.h>
@@ -843,9 +842,7 @@ static int bsg_open(struct inode *inode, struct file *file)
843{ 842{
844 struct bsg_device *bd; 843 struct bsg_device *bd;
845 844
846 lock_kernel();
847 bd = bsg_get_device(inode, file); 845 bd = bsg_get_device(inode, file);
848 unlock_kernel();
849 846
850 if (IS_ERR(bd)) 847 if (IS_ERR(bd))
851 return PTR_ERR(bd); 848 return PTR_ERR(bd);
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 4e2c367fec11..da0f6ddd7621 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -36,7 +36,7 @@
36#include <linux/ioport.h> 36#include <linux/ioport.h>
37#include <linux/mm.h> 37#include <linux/mm.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/smp_lock.h> 39#include <linux/mutex.h>
40#include <linux/proc_fs.h> 40#include <linux/proc_fs.h>
41#include <linux/seq_file.h> 41#include <linux/seq_file.h>
42#include <linux/reboot.h> 42#include <linux/reboot.h>
@@ -54,6 +54,7 @@
54#define DAC960_GAM_MINOR 252 54#define DAC960_GAM_MINOR 252
55 55
56 56
57static DEFINE_MUTEX(DAC960_mutex);
57static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers]; 58static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];
58static int DAC960_ControllerCount; 59static int DAC960_ControllerCount;
59static struct proc_dir_entry *DAC960_ProcDirectoryEntry; 60static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
@@ -81,7 +82,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
81 int drive_nr = (long)disk->private_data; 82 int drive_nr = (long)disk->private_data;
82 int ret = -ENXIO; 83 int ret = -ENXIO;
83 84
84 lock_kernel(); 85 mutex_lock(&DAC960_mutex);
85 if (p->FirmwareType == DAC960_V1_Controller) { 86 if (p->FirmwareType == DAC960_V1_Controller) {
86 if (p->V1.LogicalDriveInformation[drive_nr]. 87 if (p->V1.LogicalDriveInformation[drive_nr].
87 LogicalDriveState == DAC960_V1_LogicalDrive_Offline) 88 LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
@@ -99,7 +100,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
99 goto out; 100 goto out;
100 ret = 0; 101 ret = 0;
101out: 102out:
102 unlock_kernel(); 103 mutex_unlock(&DAC960_mutex);
103 return ret; 104 return ret;
104} 105}
105 106
@@ -6625,7 +6626,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
6625 long ErrorCode = 0; 6626 long ErrorCode = 0;
6626 if (!capable(CAP_SYS_ADMIN)) return -EACCES; 6627 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
6627 6628
6628 lock_kernel(); 6629 mutex_lock(&DAC960_mutex);
6629 switch (Request) 6630 switch (Request)
6630 { 6631 {
6631 case DAC960_IOCTL_GET_CONTROLLER_COUNT: 6632 case DAC960_IOCTL_GET_CONTROLLER_COUNT:
@@ -7056,7 +7057,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
7056 default: 7057 default:
7057 ErrorCode = -ENOTTY; 7058 ErrorCode = -ENOTTY;
7058 } 7059 }
7059 unlock_kernel(); 7060 mutex_unlock(&DAC960_mutex);
7060 return ErrorCode; 7061 return ErrorCode;
7061} 7062}
7062 7063
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 76f114f0bba3..4b852c962266 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -60,7 +60,7 @@
60#include <linux/hdreg.h> 60#include <linux/hdreg.h>
61#include <linux/delay.h> 61#include <linux/delay.h>
62#include <linux/init.h> 62#include <linux/init.h>
63#include <linux/smp_lock.h> 63#include <linux/mutex.h>
64#include <linux/amifdreg.h> 64#include <linux/amifdreg.h>
65#include <linux/amifd.h> 65#include <linux/amifd.h>
66#include <linux/buffer_head.h> 66#include <linux/buffer_head.h>
@@ -109,6 +109,7 @@
109#define FD_HD_3 0x55555555 /* high-density 3.5" (1760K) drive */ 109#define FD_HD_3 0x55555555 /* high-density 3.5" (1760K) drive */
110#define FD_DD_5 0xaaaaaaaa /* double-density 5.25" (440K) drive */ 110#define FD_DD_5 0xaaaaaaaa /* double-density 5.25" (440K) drive */
111 111
112static DEFINE_MUTEX(amiflop_mutex);
112static unsigned long int fd_def_df0 = FD_DD_3; /* default for df0 if it doesn't identify */ 113static unsigned long int fd_def_df0 = FD_DD_3; /* default for df0 if it doesn't identify */
113 114
114module_param(fd_def_df0, ulong, 0); 115module_param(fd_def_df0, ulong, 0);
@@ -1506,9 +1507,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1506{ 1507{
1507 int ret; 1508 int ret;
1508 1509
1509 lock_kernel(); 1510 mutex_lock(&amiflop_mutex);
1510 ret = fd_locked_ioctl(bdev, mode, cmd, param); 1511 ret = fd_locked_ioctl(bdev, mode, cmd, param);
1511 unlock_kernel(); 1512 mutex_unlock(&amiflop_mutex);
1512 1513
1513 return ret; 1514 return ret;
1514} 1515}
@@ -1555,11 +1556,11 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1555 int old_dev; 1556 int old_dev;
1556 unsigned long flags; 1557 unsigned long flags;
1557 1558
1558 lock_kernel(); 1559 mutex_lock(&amiflop_mutex);
1559 old_dev = fd_device[drive]; 1560 old_dev = fd_device[drive];
1560 1561
1561 if (fd_ref[drive] && old_dev != system) { 1562 if (fd_ref[drive] && old_dev != system) {
1562 unlock_kernel(); 1563 mutex_unlock(&amiflop_mutex);
1563 return -EBUSY; 1564 return -EBUSY;
1564 } 1565 }
1565 1566
@@ -1575,7 +1576,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1575 rel_fdc(); 1576 rel_fdc();
1576 1577
1577 if (wrprot) { 1578 if (wrprot) {
1578 unlock_kernel(); 1579 mutex_unlock(&amiflop_mutex);
1579 return -EROFS; 1580 return -EROFS;
1580 } 1581 }
1581 } 1582 }
@@ -1594,7 +1595,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1594 printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive, 1595 printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive,
1595 unit[drive].type->name, data_types[system].name); 1596 unit[drive].type->name, data_types[system].name);
1596 1597
1597 unlock_kernel(); 1598 mutex_unlock(&amiflop_mutex);
1598 return 0; 1599 return 0;
1599} 1600}
1600 1601
@@ -1603,7 +1604,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
1603 struct amiga_floppy_struct *p = disk->private_data; 1604 struct amiga_floppy_struct *p = disk->private_data;
1604 int drive = p - unit; 1605 int drive = p - unit;
1605 1606
1606 lock_kernel(); 1607 mutex_lock(&amiflop_mutex);
1607 if (unit[drive].dirty == 1) { 1608 if (unit[drive].dirty == 1) {
1608 del_timer (flush_track_timer + drive); 1609 del_timer (flush_track_timer + drive);
1609 non_int_flush_track (drive); 1610 non_int_flush_track (drive);
@@ -1617,7 +1618,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
1617/* the mod_use counter is handled this way */ 1618/* the mod_use counter is handled this way */
1618 floppy_off (drive | 0x40000000); 1619 floppy_off (drive | 0x40000000);
1619#endif 1620#endif
1620 unlock_kernel(); 1621 mutex_unlock(&amiflop_mutex);
1621 return 0; 1622 return 0;
1622} 1623}
1623 1624
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index a946929735a5..f21c237a9e5e 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -12,9 +12,10 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/genhd.h> 13#include <linux/genhd.h>
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/smp_lock.h> 15#include <linux/mutex.h>
16#include "aoe.h" 16#include "aoe.h"
17 17
18static DEFINE_MUTEX(aoeblk_mutex);
18static struct kmem_cache *buf_pool_cache; 19static struct kmem_cache *buf_pool_cache;
19 20
20static ssize_t aoedisk_show_state(struct device *dev, 21static ssize_t aoedisk_show_state(struct device *dev,
@@ -125,16 +126,16 @@ aoeblk_open(struct block_device *bdev, fmode_t mode)
125 struct aoedev *d = bdev->bd_disk->private_data; 126 struct aoedev *d = bdev->bd_disk->private_data;
126 ulong flags; 127 ulong flags;
127 128
128 lock_kernel(); 129 mutex_lock(&aoeblk_mutex);
129 spin_lock_irqsave(&d->lock, flags); 130 spin_lock_irqsave(&d->lock, flags);
130 if (d->flags & DEVFL_UP) { 131 if (d->flags & DEVFL_UP) {
131 d->nopen++; 132 d->nopen++;
132 spin_unlock_irqrestore(&d->lock, flags); 133 spin_unlock_irqrestore(&d->lock, flags);
133 unlock_kernel(); 134 mutex_unlock(&aoeblk_mutex);
134 return 0; 135 return 0;
135 } 136 }
136 spin_unlock_irqrestore(&d->lock, flags); 137 spin_unlock_irqrestore(&d->lock, flags);
137 unlock_kernel(); 138 mutex_unlock(&aoeblk_mutex);
138 return -ENODEV; 139 return -ENODEV;
139} 140}
140 141
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 4a1b9e7464aa..05d5ef172ca5 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -9,7 +9,7 @@
9#include <linux/completion.h> 9#include <linux/completion.h>
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/smp_lock.h> 12#include <linux/mutex.h>
13#include <linux/skbuff.h> 13#include <linux/skbuff.h>
14#include "aoe.h" 14#include "aoe.h"
15 15
@@ -37,6 +37,7 @@ struct ErrMsg {
37 char *msg; 37 char *msg;
38}; 38};
39 39
40static DEFINE_MUTEX(aoechr_mutex);
40static struct ErrMsg emsgs[NMSG]; 41static struct ErrMsg emsgs[NMSG];
41static int emsgs_head_idx, emsgs_tail_idx; 42static int emsgs_head_idx, emsgs_tail_idx;
42static struct completion emsgs_comp; 43static struct completion emsgs_comp;
@@ -183,16 +184,16 @@ aoechr_open(struct inode *inode, struct file *filp)
183{ 184{
184 int n, i; 185 int n, i;
185 186
186 lock_kernel(); 187 mutex_lock(&aoechr_mutex);
187 n = iminor(inode); 188 n = iminor(inode);
188 filp->private_data = (void *) (unsigned long) n; 189 filp->private_data = (void *) (unsigned long) n;
189 190
190 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 191 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
191 if (chardevs[i].minor == n) { 192 if (chardevs[i].minor == n) {
192 unlock_kernel(); 193 mutex_unlock(&aoechr_mutex);
193 return 0; 194 return 0;
194 } 195 }
195 unlock_kernel(); 196 mutex_unlock(&aoechr_mutex);
196 return -EINVAL; 197 return -EINVAL;
197} 198}
198 199
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index aceb96476524..8c021bb7a991 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -67,7 +67,7 @@
67#include <linux/delay.h> 67#include <linux/delay.h>
68#include <linux/init.h> 68#include <linux/init.h>
69#include <linux/blkdev.h> 69#include <linux/blkdev.h>
70#include <linux/smp_lock.h> 70#include <linux/mutex.h>
71 71
72#include <asm/atafd.h> 72#include <asm/atafd.h>
73#include <asm/atafdreg.h> 73#include <asm/atafdreg.h>
@@ -79,6 +79,7 @@
79 79
80#undef DEBUG 80#undef DEBUG
81 81
82static DEFINE_MUTEX(ataflop_mutex);
82static struct request_queue *floppy_queue; 83static struct request_queue *floppy_queue;
83static struct request *fd_request; 84static struct request *fd_request;
84 85
@@ -1671,9 +1672,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1671{ 1672{
1672 int ret; 1673 int ret;
1673 1674
1674 lock_kernel(); 1675 mutex_lock(&ataflop_mutex);
1675 ret = fd_locked_ioctl(bdev, mode, cmd, arg); 1676 ret = fd_locked_ioctl(bdev, mode, cmd, arg);
1676 unlock_kernel(); 1677 mutex_unlock(&ataflop_mutex);
1677 1678
1678 return ret; 1679 return ret;
1679} 1680}
@@ -1854,9 +1855,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
1854{ 1855{
1855 int ret; 1856 int ret;
1856 1857
1857 lock_kernel(); 1858 mutex_lock(&ataflop_mutex);
1858 ret = floppy_open(bdev, mode); 1859 ret = floppy_open(bdev, mode);
1859 unlock_kernel(); 1860 mutex_unlock(&ataflop_mutex);
1860 1861
1861 return ret; 1862 return ret;
1862} 1863}
@@ -1864,14 +1865,14 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
1864static int floppy_release(struct gendisk *disk, fmode_t mode) 1865static int floppy_release(struct gendisk *disk, fmode_t mode)
1865{ 1866{
1866 struct atari_floppy_struct *p = disk->private_data; 1867 struct atari_floppy_struct *p = disk->private_data;
1867 lock_kernel(); 1868 mutex_lock(&ataflop_mutex);
1868 if (p->ref < 0) 1869 if (p->ref < 0)
1869 p->ref = 0; 1870 p->ref = 0;
1870 else if (!p->ref--) { 1871 else if (!p->ref--) {
1871 printk(KERN_ERR "floppy_release with fd_ref == 0"); 1872 printk(KERN_ERR "floppy_release with fd_ref == 0");
1872 p->ref = 0; 1873 p->ref = 0;
1873 } 1874 }
1874 unlock_kernel(); 1875 mutex_unlock(&ataflop_mutex);
1875 return 0; 1876 return 0;
1876} 1877}
1877 1878
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 1c7f63792ff8..82bfd5bb4a97 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -15,7 +15,7 @@
15#include <linux/blkdev.h> 15#include <linux/blkdev.h>
16#include <linux/bio.h> 16#include <linux/bio.h>
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/smp_lock.h> 18#include <linux/mutex.h>
19#include <linux/radix-tree.h> 19#include <linux/radix-tree.h>
20#include <linux/buffer_head.h> /* invalidate_bh_lrus() */ 20#include <linux/buffer_head.h> /* invalidate_bh_lrus() */
21#include <linux/slab.h> 21#include <linux/slab.h>
@@ -55,6 +55,7 @@ struct brd_device {
55/* 55/*
56 * Look up and return a brd's page for a given sector. 56 * Look up and return a brd's page for a given sector.
57 */ 57 */
58static DEFINE_MUTEX(brd_mutex);
58static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector) 59static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)
59{ 60{
60 pgoff_t idx; 61 pgoff_t idx;
@@ -402,7 +403,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
402 * ram device BLKFLSBUF has special semantics, we want to actually 403 * ram device BLKFLSBUF has special semantics, we want to actually
403 * release and destroy the ramdisk data. 404 * release and destroy the ramdisk data.
404 */ 405 */
405 lock_kernel(); 406 mutex_lock(&brd_mutex);
406 mutex_lock(&bdev->bd_mutex); 407 mutex_lock(&bdev->bd_mutex);
407 error = -EBUSY; 408 error = -EBUSY;
408 if (bdev->bd_openers <= 1) { 409 if (bdev->bd_openers <= 1) {
@@ -419,7 +420,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
419 error = 0; 420 error = 0;
420 } 421 }
421 mutex_unlock(&bdev->bd_mutex); 422 mutex_unlock(&bdev->bd_mutex);
422 unlock_kernel(); 423 mutex_unlock(&brd_mutex);
423 424
424 return error; 425 return error;
425} 426}
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 5e4fadcdece9..c484c96e22a6 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -26,7 +26,6 @@
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/smp_lock.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <linux/major.h> 30#include <linux/major.h>
32#include <linux/fs.h> 31#include <linux/fs.h>
@@ -66,6 +65,7 @@ MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");
66MODULE_VERSION("3.6.26"); 65MODULE_VERSION("3.6.26");
67MODULE_LICENSE("GPL"); 66MODULE_LICENSE("GPL");
68 67
68static DEFINE_MUTEX(cciss_mutex);
69static int cciss_allow_hpsa; 69static int cciss_allow_hpsa;
70module_param(cciss_allow_hpsa, int, S_IRUGO|S_IWUSR); 70module_param(cciss_allow_hpsa, int, S_IRUGO|S_IWUSR);
71MODULE_PARM_DESC(cciss_allow_hpsa, 71MODULE_PARM_DESC(cciss_allow_hpsa,
@@ -1059,9 +1059,9 @@ static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode)
1059{ 1059{
1060 int ret; 1060 int ret;
1061 1061
1062 lock_kernel(); 1062 mutex_lock(&cciss_mutex);
1063 ret = cciss_open(bdev, mode); 1063 ret = cciss_open(bdev, mode);
1064 unlock_kernel(); 1064 mutex_unlock(&cciss_mutex);
1065 1065
1066 return ret; 1066 return ret;
1067} 1067}
@@ -1074,13 +1074,13 @@ static int cciss_release(struct gendisk *disk, fmode_t mode)
1074 ctlr_info_t *h; 1074 ctlr_info_t *h;
1075 drive_info_struct *drv; 1075 drive_info_struct *drv;
1076 1076
1077 lock_kernel(); 1077 mutex_lock(&cciss_mutex);
1078 h = get_host(disk); 1078 h = get_host(disk);
1079 drv = get_drv(disk); 1079 drv = get_drv(disk);
1080 dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name); 1080 dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name);
1081 drv->usage_count--; 1081 drv->usage_count--;
1082 h->usage_count--; 1082 h->usage_count--;
1083 unlock_kernel(); 1083 mutex_unlock(&cciss_mutex);
1084 return 0; 1084 return 0;
1085} 1085}
1086 1086
@@ -1088,9 +1088,9 @@ static int do_ioctl(struct block_device *bdev, fmode_t mode,
1088 unsigned cmd, unsigned long arg) 1088 unsigned cmd, unsigned long arg)
1089{ 1089{
1090 int ret; 1090 int ret;
1091 lock_kernel(); 1091 mutex_lock(&cciss_mutex);
1092 ret = cciss_ioctl(bdev, mode, cmd, arg); 1092 ret = cciss_ioctl(bdev, mode, cmd, arg);
1093 unlock_kernel(); 1093 mutex_unlock(&cciss_mutex);
1094 return ret; 1094 return ret;
1095} 1095}
1096 1096
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index d53b0291c44b..946dad4caef3 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -35,7 +35,7 @@
35#include <linux/seq_file.h> 35#include <linux/seq_file.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/hdreg.h> 37#include <linux/hdreg.h>
38#include <linux/smp_lock.h> 38#include <linux/mutex.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/blkdev.h> 40#include <linux/blkdev.h>
41#include <linux/genhd.h> 41#include <linux/genhd.h>
@@ -68,6 +68,7 @@ MODULE_LICENSE("GPL");
68 68
69#define CPQARRAY_DMA_MASK 0xFFFFFFFF /* 32 bit DMA */ 69#define CPQARRAY_DMA_MASK 0xFFFFFFFF /* 32 bit DMA */
70 70
71static DEFINE_MUTEX(cpqarray_mutex);
71static int nr_ctlr; 72static int nr_ctlr;
72static ctlr_info_t *hba[MAX_CTLR]; 73static ctlr_info_t *hba[MAX_CTLR];
73 74
@@ -845,9 +846,9 @@ static int ida_unlocked_open(struct block_device *bdev, fmode_t mode)
845{ 846{
846 int ret; 847 int ret;
847 848
848 lock_kernel(); 849 mutex_lock(&cpqarray_mutex);
849 ret = ida_open(bdev, mode); 850 ret = ida_open(bdev, mode);
850 unlock_kernel(); 851 mutex_unlock(&cpqarray_mutex);
851 852
852 return ret; 853 return ret;
853} 854}
@@ -859,10 +860,10 @@ static int ida_release(struct gendisk *disk, fmode_t mode)
859{ 860{
860 ctlr_info_t *host; 861 ctlr_info_t *host;
861 862
862 lock_kernel(); 863 mutex_lock(&cpqarray_mutex);
863 host = get_host(disk); 864 host = get_host(disk);
864 host->usage_count--; 865 host->usage_count--;
865 unlock_kernel(); 866 mutex_unlock(&cpqarray_mutex);
866 867
867 return 0; 868 return 0;
868} 869}
@@ -1217,9 +1218,9 @@ static int ida_ioctl(struct block_device *bdev, fmode_t mode,
1217{ 1218{
1218 int ret; 1219 int ret;
1219 1220
1220 lock_kernel(); 1221 mutex_lock(&cpqarray_mutex);
1221 ret = ida_locked_ioctl(bdev, mode, cmd, param); 1222 ret = ida_locked_ioctl(bdev, mode, cmd, param);
1222 unlock_kernel(); 1223 mutex_unlock(&cpqarray_mutex);
1223 1224
1224 return ret; 1225 return ret;
1225} 1226}
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index fa650dd85b90..e4b56119866e 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -32,7 +32,7 @@
32#include <asm/types.h> 32#include <asm/types.h>
33#include <net/sock.h> 33#include <net/sock.h>
34#include <linux/ctype.h> 34#include <linux/ctype.h>
35#include <linux/smp_lock.h> 35#include <linux/mutex.h>
36#include <linux/fs.h> 36#include <linux/fs.h>
37#include <linux/file.h> 37#include <linux/file.h>
38#include <linux/proc_fs.h> 38#include <linux/proc_fs.h>
@@ -64,6 +64,7 @@ struct after_state_chg_work {
64 struct completion *done; 64 struct completion *done;
65}; 65};
66 66
67static DEFINE_MUTEX(drbd_main_mutex);
67int drbdd_init(struct drbd_thread *); 68int drbdd_init(struct drbd_thread *);
68int drbd_worker(struct drbd_thread *); 69int drbd_worker(struct drbd_thread *);
69int drbd_asender(struct drbd_thread *); 70int drbd_asender(struct drbd_thread *);
@@ -2536,7 +2537,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2536 unsigned long flags; 2537 unsigned long flags;
2537 int rv = 0; 2538 int rv = 0;
2538 2539
2539 lock_kernel(); 2540 mutex_lock(&drbd_main_mutex);
2540 spin_lock_irqsave(&mdev->req_lock, flags); 2541 spin_lock_irqsave(&mdev->req_lock, flags);
2541 /* to have a stable mdev->state.role 2542 /* to have a stable mdev->state.role
2542 * and no race with updating open_cnt */ 2543 * and no race with updating open_cnt */
@@ -2551,7 +2552,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2551 if (!rv) 2552 if (!rv)
2552 mdev->open_cnt++; 2553 mdev->open_cnt++;
2553 spin_unlock_irqrestore(&mdev->req_lock, flags); 2554 spin_unlock_irqrestore(&mdev->req_lock, flags);
2554 unlock_kernel(); 2555 mutex_unlock(&drbd_main_mutex);
2555 2556
2556 return rv; 2557 return rv;
2557} 2558}
@@ -2559,9 +2560,9 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2559static int drbd_release(struct gendisk *gd, fmode_t mode) 2560static int drbd_release(struct gendisk *gd, fmode_t mode)
2560{ 2561{
2561 struct drbd_conf *mdev = gd->private_data; 2562 struct drbd_conf *mdev = gd->private_data;
2562 lock_kernel(); 2563 mutex_lock(&drbd_main_mutex);
2563 mdev->open_cnt--; 2564 mdev->open_cnt--;
2564 unlock_kernel(); 2565 mutex_unlock(&drbd_main_mutex);
2565 return 0; 2566 return 0;
2566} 2567}
2567 2568
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index cf04c1b234ed..3b57459bb745 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -178,7 +178,6 @@ static int print_unex = 1;
178#include <linux/slab.h> 178#include <linux/slab.h>
179#include <linux/mm.h> 179#include <linux/mm.h>
180#include <linux/bio.h> 180#include <linux/bio.h>
181#include <linux/smp_lock.h>
182#include <linux/string.h> 181#include <linux/string.h>
183#include <linux/jiffies.h> 182#include <linux/jiffies.h>
184#include <linux/fcntl.h> 183#include <linux/fcntl.h>
@@ -199,6 +198,7 @@ static int print_unex = 1;
199 * It's been recommended that take about 1/4 of the default speed 198 * It's been recommended that take about 1/4 of the default speed
200 * in some more extreme cases. 199 * in some more extreme cases.
201 */ 200 */
201static DEFINE_MUTEX(floppy_mutex);
202static int slow_floppy; 202static int slow_floppy;
203 203
204#include <asm/dma.h> 204#include <asm/dma.h>
@@ -3553,9 +3553,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
3553{ 3553{
3554 int ret; 3554 int ret;
3555 3555
3556 lock_kernel(); 3556 mutex_lock(&floppy_mutex);
3557 ret = fd_locked_ioctl(bdev, mode, cmd, param); 3557 ret = fd_locked_ioctl(bdev, mode, cmd, param);
3558 unlock_kernel(); 3558 mutex_unlock(&floppy_mutex);
3559 3559
3560 return ret; 3560 return ret;
3561} 3561}
@@ -3616,7 +3616,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
3616{ 3616{
3617 int drive = (long)disk->private_data; 3617 int drive = (long)disk->private_data;
3618 3618
3619 lock_kernel(); 3619 mutex_lock(&floppy_mutex);
3620 mutex_lock(&open_lock); 3620 mutex_lock(&open_lock);
3621 if (UDRS->fd_ref < 0) 3621 if (UDRS->fd_ref < 0)
3622 UDRS->fd_ref = 0; 3622 UDRS->fd_ref = 0;
@@ -3627,7 +3627,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
3627 if (!UDRS->fd_ref) 3627 if (!UDRS->fd_ref)
3628 opened_bdev[drive] = NULL; 3628 opened_bdev[drive] = NULL;
3629 mutex_unlock(&open_lock); 3629 mutex_unlock(&open_lock);
3630 unlock_kernel(); 3630 mutex_unlock(&floppy_mutex);
3631 3631
3632 return 0; 3632 return 0;
3633} 3633}
@@ -3645,7 +3645,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
3645 int res = -EBUSY; 3645 int res = -EBUSY;
3646 char *tmp; 3646 char *tmp;
3647 3647
3648 lock_kernel(); 3648 mutex_lock(&floppy_mutex);
3649 mutex_lock(&open_lock); 3649 mutex_lock(&open_lock);
3650 old_dev = UDRS->fd_device; 3650 old_dev = UDRS->fd_device;
3651 if (opened_bdev[drive] && opened_bdev[drive] != bdev) 3651 if (opened_bdev[drive] && opened_bdev[drive] != bdev)
@@ -3722,7 +3722,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
3722 goto out; 3722 goto out;
3723 } 3723 }
3724 mutex_unlock(&open_lock); 3724 mutex_unlock(&open_lock);
3725 unlock_kernel(); 3725 mutex_unlock(&floppy_mutex);
3726 return 0; 3726 return 0;
3727out: 3727out:
3728 if (UDRS->fd_ref < 0) 3728 if (UDRS->fd_ref < 0)
@@ -3733,7 +3733,7 @@ out:
3733 opened_bdev[drive] = NULL; 3733 opened_bdev[drive] = NULL;
3734out2: 3734out2:
3735 mutex_unlock(&open_lock); 3735 mutex_unlock(&open_lock);
3736 unlock_kernel(); 3736 mutex_unlock(&floppy_mutex);
3737 return res; 3737 return res;
3738} 3738}
3739 3739
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 91797bbbe702..a10c8c9b6b78 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -67,7 +67,7 @@
67#include <linux/compat.h> 67#include <linux/compat.h>
68#include <linux/suspend.h> 68#include <linux/suspend.h>
69#include <linux/freezer.h> 69#include <linux/freezer.h>
70#include <linux/smp_lock.h> 70#include <linux/mutex.h>
71#include <linux/writeback.h> 71#include <linux/writeback.h>
72#include <linux/buffer_head.h> /* for invalidate_bdev() */ 72#include <linux/buffer_head.h> /* for invalidate_bdev() */
73#include <linux/completion.h> 73#include <linux/completion.h>
@@ -77,6 +77,7 @@
77 77
78#include <asm/uaccess.h> 78#include <asm/uaccess.h>
79 79
80static DEFINE_MUTEX(loop_mutex);
80static LIST_HEAD(loop_devices); 81static LIST_HEAD(loop_devices);
81static DEFINE_MUTEX(loop_devices_mutex); 82static DEFINE_MUTEX(loop_devices_mutex);
82 83
@@ -1409,11 +1410,11 @@ static int lo_open(struct block_device *bdev, fmode_t mode)
1409{ 1410{
1410 struct loop_device *lo = bdev->bd_disk->private_data; 1411 struct loop_device *lo = bdev->bd_disk->private_data;
1411 1412
1412 lock_kernel(); 1413 mutex_lock(&loop_mutex);
1413 mutex_lock(&lo->lo_ctl_mutex); 1414 mutex_lock(&lo->lo_ctl_mutex);
1414 lo->lo_refcnt++; 1415 lo->lo_refcnt++;
1415 mutex_unlock(&lo->lo_ctl_mutex); 1416 mutex_unlock(&lo->lo_ctl_mutex);
1416 unlock_kernel(); 1417 mutex_unlock(&loop_mutex);
1417 1418
1418 return 0; 1419 return 0;
1419} 1420}
@@ -1423,7 +1424,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1423 struct loop_device *lo = disk->private_data; 1424 struct loop_device *lo = disk->private_data;
1424 int err; 1425 int err;
1425 1426
1426 lock_kernel(); 1427 mutex_lock(&loop_mutex);
1427 mutex_lock(&lo->lo_ctl_mutex); 1428 mutex_lock(&lo->lo_ctl_mutex);
1428 1429
1429 if (--lo->lo_refcnt) 1430 if (--lo->lo_refcnt)
@@ -1448,7 +1449,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1448out: 1449out:
1449 mutex_unlock(&lo->lo_ctl_mutex); 1450 mutex_unlock(&lo->lo_ctl_mutex);
1450out_unlocked: 1451out_unlocked:
1451 lock_kernel(); 1452 mutex_unlock(&loop_mutex);
1452 return 0; 1453 return 0;
1453} 1454}
1454 1455
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 0daa422aa281..a32fb41246f8 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -24,7 +24,7 @@
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/file.h> 25#include <linux/file.h>
26#include <linux/ioctl.h> 26#include <linux/ioctl.h>
27#include <linux/smp_lock.h> 27#include <linux/mutex.h>
28#include <linux/compiler.h> 28#include <linux/compiler.h>
29#include <linux/err.h> 29#include <linux/err.h>
30#include <linux/kernel.h> 30#include <linux/kernel.h>
@@ -53,6 +53,7 @@
53#define DBG_BLKDEV 0x0100 53#define DBG_BLKDEV 0x0100
54#define DBG_RX 0x0200 54#define DBG_RX 0x0200
55#define DBG_TX 0x0400 55#define DBG_TX 0x0400
56static DEFINE_MUTEX(nbd_mutex);
56static unsigned int debugflags; 57static unsigned int debugflags;
57#endif /* NDEBUG */ 58#endif /* NDEBUG */
58 59
@@ -717,11 +718,11 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
717 dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n", 718 dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n",
718 lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg); 719 lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg);
719 720
720 lock_kernel(); 721 mutex_lock(&nbd_mutex);
721 mutex_lock(&lo->tx_lock); 722 mutex_lock(&lo->tx_lock);
722 error = __nbd_ioctl(bdev, lo, cmd, arg); 723 error = __nbd_ioctl(bdev, lo, cmd, arg);
723 mutex_unlock(&lo->tx_lock); 724 mutex_unlock(&lo->tx_lock);
724 unlock_kernel(); 725 mutex_unlock(&nbd_mutex);
725 726
726 return error; 727 return error;
727} 728}
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index 76f8565e1e8d..62cec6afd7ad 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -138,9 +138,10 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
138#include <linux/cdrom.h> 138#include <linux/cdrom.h>
139#include <linux/spinlock.h> 139#include <linux/spinlock.h>
140#include <linux/blkdev.h> 140#include <linux/blkdev.h>
141#include <linux/smp_lock.h> 141#include <linux/mutex.h>
142#include <asm/uaccess.h> 142#include <asm/uaccess.h>
143 143
144static DEFINE_MUTEX(pcd_mutex);
144static DEFINE_SPINLOCK(pcd_lock); 145static DEFINE_SPINLOCK(pcd_lock);
145 146
146module_param(verbose, bool, 0644); 147module_param(verbose, bool, 0644);
@@ -227,9 +228,9 @@ static int pcd_block_open(struct block_device *bdev, fmode_t mode)
227 struct pcd_unit *cd = bdev->bd_disk->private_data; 228 struct pcd_unit *cd = bdev->bd_disk->private_data;
228 int ret; 229 int ret;
229 230
230 lock_kernel(); 231 mutex_lock(&pcd_mutex);
231 ret = cdrom_open(&cd->info, bdev, mode); 232 ret = cdrom_open(&cd->info, bdev, mode);
232 unlock_kernel(); 233 mutex_unlock(&pcd_mutex);
233 234
234 return ret; 235 return ret;
235} 236}
@@ -237,9 +238,9 @@ static int pcd_block_open(struct block_device *bdev, fmode_t mode)
237static int pcd_block_release(struct gendisk *disk, fmode_t mode) 238static int pcd_block_release(struct gendisk *disk, fmode_t mode)
238{ 239{
239 struct pcd_unit *cd = disk->private_data; 240 struct pcd_unit *cd = disk->private_data;
240 lock_kernel(); 241 mutex_lock(&pcd_mutex);
241 cdrom_release(&cd->info, mode); 242 cdrom_release(&cd->info, mode);
242 unlock_kernel(); 243 mutex_unlock(&pcd_mutex);
243 return 0; 244 return 0;
244} 245}
245 246
@@ -249,9 +250,9 @@ static int pcd_block_ioctl(struct block_device *bdev, fmode_t mode,
249 struct pcd_unit *cd = bdev->bd_disk->private_data; 250 struct pcd_unit *cd = bdev->bd_disk->private_data;
250 int ret; 251 int ret;
251 252
252 lock_kernel(); 253 mutex_lock(&pcd_mutex);
253 ret = cdrom_ioctl(&cd->info, bdev, mode, cmd, arg); 254 ret = cdrom_ioctl(&cd->info, bdev, mode, cmd, arg);
254 unlock_kernel(); 255 mutex_unlock(&pcd_mutex);
255 256
256 return ret; 257 return ret;
257} 258}
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 985f0d4f1d1e..c0ee1558b9bb 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -153,10 +153,11 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_GEO, D_SBY, D_DLY, D_SLV};
153#include <linux/blkdev.h> 153#include <linux/blkdev.h>
154#include <linux/blkpg.h> 154#include <linux/blkpg.h>
155#include <linux/kernel.h> 155#include <linux/kernel.h>
156#include <linux/smp_lock.h> 156#include <linux/mutex.h>
157#include <asm/uaccess.h> 157#include <asm/uaccess.h>
158#include <linux/workqueue.h> 158#include <linux/workqueue.h>
159 159
160static DEFINE_MUTEX(pd_mutex);
160static DEFINE_SPINLOCK(pd_lock); 161static DEFINE_SPINLOCK(pd_lock);
161 162
162module_param(verbose, bool, 0); 163module_param(verbose, bool, 0);
@@ -736,14 +737,14 @@ static int pd_open(struct block_device *bdev, fmode_t mode)
736{ 737{
737 struct pd_unit *disk = bdev->bd_disk->private_data; 738 struct pd_unit *disk = bdev->bd_disk->private_data;
738 739
739 lock_kernel(); 740 mutex_lock(&pd_mutex);
740 disk->access++; 741 disk->access++;
741 742
742 if (disk->removable) { 743 if (disk->removable) {
743 pd_special_command(disk, pd_media_check); 744 pd_special_command(disk, pd_media_check);
744 pd_special_command(disk, pd_door_lock); 745 pd_special_command(disk, pd_door_lock);
745 } 746 }
746 unlock_kernel(); 747 mutex_unlock(&pd_mutex);
747 return 0; 748 return 0;
748} 749}
749 750
@@ -771,10 +772,10 @@ static int pd_ioctl(struct block_device *bdev, fmode_t mode,
771 772
772 switch (cmd) { 773 switch (cmd) {
773 case CDROMEJECT: 774 case CDROMEJECT:
774 lock_kernel(); 775 mutex_lock(&pd_mutex);
775 if (disk->access == 1) 776 if (disk->access == 1)
776 pd_special_command(disk, pd_eject); 777 pd_special_command(disk, pd_eject);
777 unlock_kernel(); 778 mutex_unlock(&pd_mutex);
778 return 0; 779 return 0;
779 default: 780 default:
780 return -EINVAL; 781 return -EINVAL;
@@ -785,10 +786,10 @@ static int pd_release(struct gendisk *p, fmode_t mode)
785{ 786{
786 struct pd_unit *disk = p->private_data; 787 struct pd_unit *disk = p->private_data;
787 788
788 lock_kernel(); 789 mutex_lock(&pd_mutex);
789 if (!--disk->access && disk->removable) 790 if (!--disk->access && disk->removable)
790 pd_special_command(disk, pd_door_unlock); 791 pd_special_command(disk, pd_door_unlock);
791 unlock_kernel(); 792 mutex_unlock(&pd_mutex);
792 793
793 return 0; 794 return 0;
794} 795}
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index 4457b494882a..635f25dd9e10 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -152,9 +152,10 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_LUN, D_DLY};
152#include <linux/spinlock.h> 152#include <linux/spinlock.h>
153#include <linux/blkdev.h> 153#include <linux/blkdev.h>
154#include <linux/blkpg.h> 154#include <linux/blkpg.h>
155#include <linux/smp_lock.h> 155#include <linux/mutex.h>
156#include <asm/uaccess.h> 156#include <asm/uaccess.h>
157 157
158static DEFINE_MUTEX(pf_mutex);
158static DEFINE_SPINLOCK(pf_spin_lock); 159static DEFINE_SPINLOCK(pf_spin_lock);
159 160
160module_param(verbose, bool, 0644); 161module_param(verbose, bool, 0644);
@@ -302,7 +303,7 @@ static int pf_open(struct block_device *bdev, fmode_t mode)
302 struct pf_unit *pf = bdev->bd_disk->private_data; 303 struct pf_unit *pf = bdev->bd_disk->private_data;
303 int ret; 304 int ret;
304 305
305 lock_kernel(); 306 mutex_lock(&pf_mutex);
306 pf_identify(pf); 307 pf_identify(pf);
307 308
308 ret = -ENODEV; 309 ret = -ENODEV;
@@ -318,7 +319,7 @@ static int pf_open(struct block_device *bdev, fmode_t mode)
318 if (pf->removable) 319 if (pf->removable)
319 pf_lock(pf, 1); 320 pf_lock(pf, 1);
320out: 321out:
321 unlock_kernel(); 322 mutex_unlock(&pf_mutex);
322 return ret; 323 return ret;
323} 324}
324 325
@@ -349,9 +350,9 @@ static int pf_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, u
349 350
350 if (pf->access != 1) 351 if (pf->access != 1)
351 return -EBUSY; 352 return -EBUSY;
352 lock_kernel(); 353 mutex_lock(&pf_mutex);
353 pf_eject(pf); 354 pf_eject(pf);
354 unlock_kernel(); 355 mutex_unlock(&pf_mutex);
355 356
356 return 0; 357 return 0;
357} 358}
@@ -360,9 +361,9 @@ static int pf_release(struct gendisk *disk, fmode_t mode)
360{ 361{
361 struct pf_unit *pf = disk->private_data; 362 struct pf_unit *pf = disk->private_data;
362 363
363 lock_kernel(); 364 mutex_lock(&pf_mutex);
364 if (pf->access <= 0) { 365 if (pf->access <= 0) {
365 unlock_kernel(); 366 mutex_unlock(&pf_mutex);
366 return -EINVAL; 367 return -EINVAL;
367 } 368 }
368 369
@@ -371,7 +372,7 @@ static int pf_release(struct gendisk *disk, fmode_t mode)
371 if (!pf->access && pf->removable) 372 if (!pf->access && pf->removable)
372 pf_lock(pf, 0); 373 pf_lock(pf, 0);
373 374
374 unlock_kernel(); 375 mutex_unlock(&pf_mutex);
375 return 0; 376 return 0;
376 377
377} 378}
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index c397b3ddba9b..bed29cb9e6d9 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -162,7 +162,7 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
162#include <linux/pg.h> 162#include <linux/pg.h>
163#include <linux/device.h> 163#include <linux/device.h>
164#include <linux/sched.h> /* current, TASK_* */ 164#include <linux/sched.h> /* current, TASK_* */
165#include <linux/smp_lock.h> 165#include <linux/mutex.h>
166#include <linux/jiffies.h> 166#include <linux/jiffies.h>
167 167
168#include <asm/uaccess.h> 168#include <asm/uaccess.h>
@@ -193,6 +193,7 @@ module_param_array(drive3, int, NULL, 0);
193 193
194#define ATAPI_IDENTIFY 0x12 194#define ATAPI_IDENTIFY 0x12
195 195
196static DEFINE_MUTEX(pg_mutex);
196static int pg_open(struct inode *inode, struct file *file); 197static int pg_open(struct inode *inode, struct file *file);
197static int pg_release(struct inode *inode, struct file *file); 198static int pg_release(struct inode *inode, struct file *file);
198static ssize_t pg_read(struct file *filp, char __user *buf, 199static ssize_t pg_read(struct file *filp, char __user *buf,
@@ -518,7 +519,7 @@ static int pg_open(struct inode *inode, struct file *file)
518 struct pg *dev = &devices[unit]; 519 struct pg *dev = &devices[unit];
519 int ret = 0; 520 int ret = 0;
520 521
521 lock_kernel(); 522 mutex_lock(&pg_mutex);
522 if ((unit >= PG_UNITS) || (!dev->present)) { 523 if ((unit >= PG_UNITS) || (!dev->present)) {
523 ret = -ENODEV; 524 ret = -ENODEV;
524 goto out; 525 goto out;
@@ -547,7 +548,7 @@ static int pg_open(struct inode *inode, struct file *file)
547 file->private_data = dev; 548 file->private_data = dev;
548 549
549out: 550out:
550 unlock_kernel(); 551 mutex_unlock(&pg_mutex);
551 return ret; 552 return ret;
552} 553}
553 554
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index bc5825fdeaab..e4dda282e0a6 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -146,7 +146,7 @@ static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};
146#include <linux/mtio.h> 146#include <linux/mtio.h>
147#include <linux/device.h> 147#include <linux/device.h>
148#include <linux/sched.h> /* current, TASK_*, schedule_timeout() */ 148#include <linux/sched.h> /* current, TASK_*, schedule_timeout() */
149#include <linux/smp_lock.h> 149#include <linux/mutex.h>
150 150
151#include <asm/uaccess.h> 151#include <asm/uaccess.h>
152 152
@@ -189,6 +189,7 @@ module_param_array(drive3, int, NULL, 0);
189#define ATAPI_MODE_SENSE 0x1a 189#define ATAPI_MODE_SENSE 0x1a
190#define ATAPI_LOG_SENSE 0x4d 190#define ATAPI_LOG_SENSE 0x4d
191 191
192static DEFINE_MUTEX(pt_mutex);
192static int pt_open(struct inode *inode, struct file *file); 193static int pt_open(struct inode *inode, struct file *file);
193static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 194static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
194static int pt_release(struct inode *inode, struct file *file); 195static int pt_release(struct inode *inode, struct file *file);
@@ -650,9 +651,9 @@ static int pt_open(struct inode *inode, struct file *file)
650 struct pt_unit *tape = pt + unit; 651 struct pt_unit *tape = pt + unit;
651 int err; 652 int err;
652 653
653 lock_kernel(); 654 mutex_lock(&pt_mutex);
654 if (unit >= PT_UNITS || (!tape->present)) { 655 if (unit >= PT_UNITS || (!tape->present)) {
655 unlock_kernel(); 656 mutex_unlock(&pt_mutex);
656 return -ENODEV; 657 return -ENODEV;
657 } 658 }
658 659
@@ -681,12 +682,12 @@ static int pt_open(struct inode *inode, struct file *file)
681 } 682 }
682 683
683 file->private_data = tape; 684 file->private_data = tape;
684 unlock_kernel(); 685 mutex_unlock(&pt_mutex);
685 return 0; 686 return 0;
686 687
687out: 688out:
688 atomic_inc(&tape->available); 689 atomic_inc(&tape->available);
689 unlock_kernel(); 690 mutex_unlock(&pt_mutex);
690 return err; 691 return err;
691} 692}
692 693
@@ -704,15 +705,15 @@ static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
704 switch (mtop.mt_op) { 705 switch (mtop.mt_op) {
705 706
706 case MTREW: 707 case MTREW:
707 lock_kernel(); 708 mutex_lock(&pt_mutex);
708 pt_rewind(tape); 709 pt_rewind(tape);
709 unlock_kernel(); 710 mutex_unlock(&pt_mutex);
710 return 0; 711 return 0;
711 712
712 case MTWEOF: 713 case MTWEOF:
713 lock_kernel(); 714 mutex_lock(&pt_mutex);
714 pt_write_fm(tape); 715 pt_write_fm(tape);
715 unlock_kernel(); 716 mutex_unlock(&pt_mutex);
716 return 0; 717 return 0;
717 718
718 default: 719 default:
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 37a2bb595076..044b84e6f147 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -57,7 +57,6 @@
57#include <linux/seq_file.h> 57#include <linux/seq_file.h>
58#include <linux/miscdevice.h> 58#include <linux/miscdevice.h>
59#include <linux/freezer.h> 59#include <linux/freezer.h>
60#include <linux/smp_lock.h>
61#include <linux/mutex.h> 60#include <linux/mutex.h>
62#include <linux/slab.h> 61#include <linux/slab.h>
63#include <scsi/scsi_cmnd.h> 62#include <scsi/scsi_cmnd.h>
@@ -86,6 +85,7 @@
86 85
87#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1)) 86#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1))
88 87
88static DEFINE_MUTEX(pktcdvd_mutex);
89static struct pktcdvd_device *pkt_devs[MAX_WRITERS]; 89static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
90static struct proc_dir_entry *pkt_proc; 90static struct proc_dir_entry *pkt_proc;
91static int pktdev_major; 91static int pktdev_major;
@@ -2383,7 +2383,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode)
2383 2383
2384 VPRINTK(DRIVER_NAME": entering open\n"); 2384 VPRINTK(DRIVER_NAME": entering open\n");
2385 2385
2386 lock_kernel(); 2386 mutex_lock(&pktcdvd_mutex);
2387 mutex_lock(&ctl_mutex); 2387 mutex_lock(&ctl_mutex);
2388 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev)); 2388 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev));
2389 if (!pd) { 2389 if (!pd) {
@@ -2411,7 +2411,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode)
2411 } 2411 }
2412 2412
2413 mutex_unlock(&ctl_mutex); 2413 mutex_unlock(&ctl_mutex);
2414 unlock_kernel(); 2414 mutex_unlock(&pktcdvd_mutex);
2415 return 0; 2415 return 0;
2416 2416
2417out_dec: 2417out_dec:
@@ -2419,7 +2419,7 @@ out_dec:
2419out: 2419out:
2420 VPRINTK(DRIVER_NAME": failed open (%d)\n", ret); 2420 VPRINTK(DRIVER_NAME": failed open (%d)\n", ret);
2421 mutex_unlock(&ctl_mutex); 2421 mutex_unlock(&ctl_mutex);
2422 unlock_kernel(); 2422 mutex_unlock(&pktcdvd_mutex);
2423 return ret; 2423 return ret;
2424} 2424}
2425 2425
@@ -2428,7 +2428,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)
2428 struct pktcdvd_device *pd = disk->private_data; 2428 struct pktcdvd_device *pd = disk->private_data;
2429 int ret = 0; 2429 int ret = 0;
2430 2430
2431 lock_kernel(); 2431 mutex_lock(&pktcdvd_mutex);
2432 mutex_lock(&ctl_mutex); 2432 mutex_lock(&ctl_mutex);
2433 pd->refcnt--; 2433 pd->refcnt--;
2434 BUG_ON(pd->refcnt < 0); 2434 BUG_ON(pd->refcnt < 0);
@@ -2437,7 +2437,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)
2437 pkt_release_dev(pd, flush); 2437 pkt_release_dev(pd, flush);
2438 } 2438 }
2439 mutex_unlock(&ctl_mutex); 2439 mutex_unlock(&ctl_mutex);
2440 unlock_kernel(); 2440 mutex_unlock(&pktcdvd_mutex);
2441 return ret; 2441 return ret;
2442} 2442}
2443 2443
@@ -2773,7 +2773,7 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
2773 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd, 2773 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd,
2774 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); 2774 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
2775 2775
2776 lock_kernel(); 2776 mutex_lock(&pktcdvd_mutex);
2777 switch (cmd) { 2777 switch (cmd) {
2778 case CDROMEJECT: 2778 case CDROMEJECT:
2779 /* 2779 /*
@@ -2798,7 +2798,7 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
2798 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd); 2798 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd);
2799 ret = -ENOTTY; 2799 ret = -ENOTTY;
2800 } 2800 }
2801 unlock_kernel(); 2801 mutex_unlock(&pktcdvd_mutex);
2802 2802
2803 return ret; 2803 return ret;
2804} 2804}
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 2e46815876df..75333d0a3327 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -20,7 +20,7 @@
20#include <linux/fd.h> 20#include <linux/fd.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/blkdev.h> 22#include <linux/blkdev.h>
23#include <linux/smp_lock.h> 23#include <linux/mutex.h>
24#include <linux/hdreg.h> 24#include <linux/hdreg.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
@@ -222,6 +222,7 @@ extern int swim_read_sector_header(struct swim __iomem *base,
222extern int swim_read_sector_data(struct swim __iomem *base, 222extern int swim_read_sector_data(struct swim __iomem *base,
223 unsigned char *data); 223 unsigned char *data);
224 224
225static DEFINE_MUTEX(swim_mutex);
225static inline void set_swim_mode(struct swim __iomem *base, int enable) 226static inline void set_swim_mode(struct swim __iomem *base, int enable)
226{ 227{
227 struct iwm __iomem *iwm_base; 228 struct iwm __iomem *iwm_base;
@@ -666,9 +667,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
666{ 667{
667 int ret; 668 int ret;
668 669
669 lock_kernel(); 670 mutex_lock(&swim_mutex);
670 ret = floppy_open(bdev, mode); 671 ret = floppy_open(bdev, mode);
671 unlock_kernel(); 672 mutex_unlock(&swim_mutex);
672 673
673 return ret; 674 return ret;
674} 675}
@@ -678,7 +679,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
678 struct floppy_state *fs = disk->private_data; 679 struct floppy_state *fs = disk->private_data;
679 struct swim __iomem *base = fs->swd->base; 680 struct swim __iomem *base = fs->swd->base;
680 681
681 lock_kernel(); 682 mutex_lock(&swim_mutex);
682 if (fs->ref_count < 0) 683 if (fs->ref_count < 0)
683 fs->ref_count = 0; 684 fs->ref_count = 0;
684 else if (fs->ref_count > 0) 685 else if (fs->ref_count > 0)
@@ -686,7 +687,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
686 687
687 if (fs->ref_count == 0) 688 if (fs->ref_count == 0)
688 swim_motor(base, OFF); 689 swim_motor(base, OFF);
689 unlock_kernel(); 690 mutex_unlock(&swim_mutex);
690 691
691 return 0; 692 return 0;
692} 693}
@@ -704,9 +705,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
704 case FDEJECT: 705 case FDEJECT:
705 if (fs->ref_count != 1) 706 if (fs->ref_count != 1)
706 return -EBUSY; 707 return -EBUSY;
707 lock_kernel(); 708 mutex_lock(&swim_mutex);
708 err = floppy_eject(fs); 709 err = floppy_eject(fs);
709 unlock_kernel(); 710 mutex_unlock(&swim_mutex);
710 return err; 711 return err;
711 712
712 case FDGETPRM: 713 case FDGETPRM:
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index cc6a3864822c..bf3a5b859299 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -25,7 +25,7 @@
25#include <linux/ioctl.h> 25#include <linux/ioctl.h>
26#include <linux/blkdev.h> 26#include <linux/blkdev.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/smp_lock.h> 28#include <linux/mutex.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/spinlock.h> 30#include <linux/spinlock.h>
31#include <asm/io.h> 31#include <asm/io.h>
@@ -36,6 +36,7 @@
36#include <asm/machdep.h> 36#include <asm/machdep.h>
37#include <asm/pmac_feature.h> 37#include <asm/pmac_feature.h>
38 38
39static DEFINE_MUTEX(swim3_mutex);
39static struct request_queue *swim3_queue; 40static struct request_queue *swim3_queue;
40static struct gendisk *disks[2]; 41static struct gendisk *disks[2];
41static struct request *fd_req; 42static struct request *fd_req;
@@ -873,9 +874,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
873{ 874{
874 int ret; 875 int ret;
875 876
876 lock_kernel(); 877 mutex_lock(&swim3_mutex);
877 ret = floppy_locked_ioctl(bdev, mode, cmd, param); 878 ret = floppy_locked_ioctl(bdev, mode, cmd, param);
878 unlock_kernel(); 879 mutex_unlock(&swim3_mutex);
879 880
880 return ret; 881 return ret;
881} 882}
@@ -953,9 +954,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
953{ 954{
954 int ret; 955 int ret;
955 956
956 lock_kernel(); 957 mutex_lock(&swim3_mutex);
957 ret = floppy_open(bdev, mode); 958 ret = floppy_open(bdev, mode);
958 unlock_kernel(); 959 mutex_unlock(&swim3_mutex);
959 960
960 return ret; 961 return ret;
961} 962}
@@ -964,13 +965,13 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
964{ 965{
965 struct floppy_state *fs = disk->private_data; 966 struct floppy_state *fs = disk->private_data;
966 struct swim3 __iomem *sw = fs->swim3; 967 struct swim3 __iomem *sw = fs->swim3;
967 lock_kernel(); 968 mutex_lock(&swim3_mutex);
968 if (fs->ref_count > 0 && --fs->ref_count == 0) { 969 if (fs->ref_count > 0 && --fs->ref_count == 0) {
969 swim3_action(fs, MOTOR_OFF); 970 swim3_action(fs, MOTOR_OFF);
970 out_8(&sw->control_bic, 0xff); 971 out_8(&sw->control_bic, 0xff);
971 swim3_select(fs, RELAX); 972 swim3_select(fs, RELAX);
972 } 973 }
973 unlock_kernel(); 974 mutex_unlock(&swim3_mutex);
974 return 0; 975 return 0;
975} 976}
976 977
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index c48e14878582..b5690a045a01 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -28,7 +28,7 @@
28#include <linux/timer.h> 28#include <linux/timer.h>
29#include <linux/scatterlist.h> 29#include <linux/scatterlist.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/smp_lock.h> 31#include <linux/mutex.h>
32#include <scsi/scsi.h> 32#include <scsi/scsi.h>
33 33
34#define DRV_NAME "ub" 34#define DRV_NAME "ub"
@@ -248,6 +248,7 @@ struct ub_completion {
248 spinlock_t lock; 248 spinlock_t lock;
249}; 249};
250 250
251static DEFINE_MUTEX(ub_mutex);
251static inline void ub_init_completion(struct ub_completion *x) 252static inline void ub_init_completion(struct ub_completion *x)
252{ 253{
253 x->done = 0; 254 x->done = 0;
@@ -1715,9 +1716,9 @@ static int ub_bd_unlocked_open(struct block_device *bdev, fmode_t mode)
1715{ 1716{
1716 int ret; 1717 int ret;
1717 1718
1718 lock_kernel(); 1719 mutex_lock(&ub_mutex);
1719 ret = ub_bd_open(bdev, mode); 1720 ret = ub_bd_open(bdev, mode);
1720 unlock_kernel(); 1721 mutex_unlock(&ub_mutex);
1721 1722
1722 return ret; 1723 return ret;
1723} 1724}
@@ -1730,9 +1731,9 @@ static int ub_bd_release(struct gendisk *disk, fmode_t mode)
1730 struct ub_lun *lun = disk->private_data; 1731 struct ub_lun *lun = disk->private_data;
1731 struct ub_dev *sc = lun->udev; 1732 struct ub_dev *sc = lun->udev;
1732 1733
1733 lock_kernel(); 1734 mutex_lock(&ub_mutex);
1734 ub_put(sc); 1735 ub_put(sc);
1735 unlock_kernel(); 1736 mutex_unlock(&ub_mutex);
1736 1737
1737 return 0; 1738 return 0;
1738} 1739}
@@ -1747,9 +1748,9 @@ static int ub_bd_ioctl(struct block_device *bdev, fmode_t mode,
1747 void __user *usermem = (void __user *) arg; 1748 void __user *usermem = (void __user *) arg;
1748 int ret; 1749 int ret;
1749 1750
1750 lock_kernel(); 1751 mutex_lock(&ub_mutex);
1751 ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem); 1752 ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem);
1752 unlock_kernel(); 1753 mutex_unlock(&ub_mutex);
1753 1754
1754 return ret; 1755 return ret;
1755} 1756}
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index f651e51a3319..e2ff697697c2 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -41,7 +41,7 @@
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/string.h> 43#include <linux/string.h>
44#include <linux/smp_lock.h> 44#include <linux/mutex.h>
45#include <linux/dma-mapping.h> 45#include <linux/dma-mapping.h>
46#include <linux/completion.h> 46#include <linux/completion.h>
47#include <linux/device.h> 47#include <linux/device.h>
@@ -73,6 +73,7 @@ enum {
73 MAX_DISK_NAME = FIELD_SIZEOF(struct gendisk, disk_name) 73 MAX_DISK_NAME = FIELD_SIZEOF(struct gendisk, disk_name)
74}; 74};
75 75
76static DEFINE_MUTEX(viodasd_mutex);
76static DEFINE_SPINLOCK(viodasd_spinlock); 77static DEFINE_SPINLOCK(viodasd_spinlock);
77 78
78#define VIOMAXREQ 16 79#define VIOMAXREQ 16
@@ -180,9 +181,9 @@ static int viodasd_unlocked_open(struct block_device *bdev, fmode_t mode)
180{ 181{
181 int ret; 182 int ret;
182 183
183 lock_kernel(); 184 mutex_lock(&viodasd_mutex);
184 ret = viodasd_open(bdev, mode); 185 ret = viodasd_open(bdev, mode);
185 unlock_kernel(); 186 mutex_unlock(&viodasd_mutex);
186 187
187 return ret; 188 return ret;
188} 189}
@@ -196,7 +197,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)
196 struct viodasd_device *d = disk->private_data; 197 struct viodasd_device *d = disk->private_data;
197 HvLpEvent_Rc hvrc; 198 HvLpEvent_Rc hvrc;
198 199
199 lock_kernel(); 200 mutex_lock(&viodasd_mutex);
200 /* Send the event to OS/400. We DON'T expect a response */ 201 /* Send the event to OS/400. We DON'T expect a response */
201 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, 202 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
202 HvLpEvent_Type_VirtualIo, 203 HvLpEvent_Type_VirtualIo,
@@ -210,7 +211,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)
210 if (hvrc != 0) 211 if (hvrc != 0)
211 pr_warning("HV close call failed %d\n", (int)hvrc); 212 pr_warning("HV close call failed %d\n", (int)hvrc);
212 213
213 unlock_kernel(); 214 mutex_unlock(&viodasd_mutex);
214 215
215 return 0; 216 return 0;
216} 217}
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index d5a3cd750561..4abd2bcd20fb 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -46,7 +46,7 @@
46#include <linux/init.h> 46#include <linux/init.h>
47#include <linux/wait.h> 47#include <linux/wait.h>
48#include <linux/blkdev.h> 48#include <linux/blkdev.h>
49#include <linux/smp_lock.h> 49#include <linux/mutex.h>
50#include <linux/blkpg.h> 50#include <linux/blkpg.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/io.h> 52#include <linux/io.h>
@@ -58,6 +58,7 @@
58 58
59#include "xd.h" 59#include "xd.h"
60 60
61static DEFINE_MUTEX(xd_mutex);
61static void __init do_xd_setup (int *integers); 62static void __init do_xd_setup (int *integers);
62#ifdef MODULE 63#ifdef MODULE
63static int xd[5] = { -1,-1,-1,-1, }; 64static int xd[5] = { -1,-1,-1,-1, };
@@ -381,9 +382,9 @@ static int xd_ioctl(struct block_device *bdev, fmode_t mode,
381{ 382{
382 int ret; 383 int ret;
383 384
384 lock_kernel(); 385 mutex_lock(&xd_mutex);
385 ret = xd_locked_ioctl(bdev, mode, cmd, param); 386 ret = xd_locked_ioctl(bdev, mode, cmd, param);
386 unlock_kernel(); 387 mutex_unlock(&xd_mutex);
387 388
388 return ret; 389 return ret;
389} 390}
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index ab735a605cf3..3ff06f475eef 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -41,7 +41,7 @@
41#include <linux/cdrom.h> 41#include <linux/cdrom.h>
42#include <linux/module.h> 42#include <linux/module.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/smp_lock.h> 44#include <linux/mutex.h>
45#include <linux/scatterlist.h> 45#include <linux/scatterlist.h>
46 46
47#include <xen/xen.h> 47#include <xen/xen.h>
@@ -69,6 +69,7 @@ struct blk_shadow {
69 unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 69 unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST];
70}; 70};
71 71
72static DEFINE_MUTEX(blkfront_mutex);
72static const struct block_device_operations xlvbd_block_fops; 73static const struct block_device_operations xlvbd_block_fops;
73 74
74#define BLK_RING_SIZE __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE) 75#define BLK_RING_SIZE __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE)
@@ -1201,7 +1202,7 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)
1201 struct blkfront_info *info; 1202 struct blkfront_info *info;
1202 int err = 0; 1203 int err = 0;
1203 1204
1204 lock_kernel(); 1205 mutex_lock(&blkfront_mutex);
1205 1206
1206 info = disk->private_data; 1207 info = disk->private_data;
1207 if (!info) { 1208 if (!info) {
@@ -1219,7 +1220,7 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)
1219 mutex_unlock(&info->mutex); 1220 mutex_unlock(&info->mutex);
1220 1221
1221out: 1222out:
1222 unlock_kernel(); 1223 mutex_unlock(&blkfront_mutex);
1223 return err; 1224 return err;
1224} 1225}
1225 1226
@@ -1229,7 +1230,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
1229 struct block_device *bdev; 1230 struct block_device *bdev;
1230 struct xenbus_device *xbdev; 1231 struct xenbus_device *xbdev;
1231 1232
1232 lock_kernel(); 1233 mutex_lock(&blkfront_mutex);
1233 1234
1234 bdev = bdget_disk(disk, 0); 1235 bdev = bdget_disk(disk, 0);
1235 bdput(bdev); 1236 bdput(bdev);
@@ -1263,7 +1264,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
1263 } 1264 }
1264 1265
1265out: 1266out:
1266 unlock_kernel(); 1267 mutex_unlock(&blkfront_mutex);
1267 return 0; 1268 return 0;
1268} 1269}
1269 1270
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index 057413bb16e2..6e968cd4893c 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -89,7 +89,7 @@
89#include <linux/delay.h> 89#include <linux/delay.h>
90#include <linux/slab.h> 90#include <linux/slab.h>
91#include <linux/blkdev.h> 91#include <linux/blkdev.h>
92#include <linux/smp_lock.h> 92#include <linux/mutex.h>
93#include <linux/ata.h> 93#include <linux/ata.h>
94#include <linux/hdreg.h> 94#include <linux/hdreg.h>
95#include <linux/platform_device.h> 95#include <linux/platform_device.h>
@@ -214,6 +214,7 @@ struct ace_device {
214 u16 cf_id[ATA_ID_WORDS]; 214 u16 cf_id[ATA_ID_WORDS];
215}; 215};
216 216
217static DEFINE_MUTEX(xsysace_mutex);
217static int ace_major; 218static int ace_major;
218 219
219/* --------------------------------------------------------------------- 220/* ---------------------------------------------------------------------
@@ -903,13 +904,13 @@ static int ace_open(struct block_device *bdev, fmode_t mode)
903 904
904 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1); 905 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1);
905 906
906 lock_kernel(); 907 mutex_lock(&xsysace_mutex);
907 spin_lock_irqsave(&ace->lock, flags); 908 spin_lock_irqsave(&ace->lock, flags);
908 ace->users++; 909 ace->users++;
909 spin_unlock_irqrestore(&ace->lock, flags); 910 spin_unlock_irqrestore(&ace->lock, flags);
910 911
911 check_disk_change(bdev); 912 check_disk_change(bdev);
912 unlock_kernel(); 913 mutex_unlock(&xsysace_mutex);
913 914
914 return 0; 915 return 0;
915} 916}
@@ -922,7 +923,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)
922 923
923 dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1); 924 dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1);
924 925
925 lock_kernel(); 926 mutex_lock(&xsysace_mutex);
926 spin_lock_irqsave(&ace->lock, flags); 927 spin_lock_irqsave(&ace->lock, flags);
927 ace->users--; 928 ace->users--;
928 if (ace->users == 0) { 929 if (ace->users == 0) {
@@ -930,7 +931,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)
930 ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ); 931 ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ);
931 } 932 }
932 spin_unlock_irqrestore(&ace->lock, flags); 933 spin_unlock_irqrestore(&ace->lock, flags);
933 unlock_kernel(); 934 mutex_unlock(&xsysace_mutex);
934 return 0; 935 return 0;
935} 936}
936 937
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index d75b2bb601ad..dcd4cfcf4126 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -33,7 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/blkdev.h> 34#include <linux/blkdev.h>
35#include <linux/bitops.h> 35#include <linux/bitops.h>
36#include <linux/smp_lock.h> 36#include <linux/mutex.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38 38
39#include <asm/setup.h> 39#include <asm/setup.h>
@@ -57,6 +57,7 @@ extern struct mem_info m68k_memory[NUM_MEMINFO];
57 57
58#define Z2RAM_CHUNK1024 ( Z2RAM_CHUNKSIZE >> 10 ) 58#define Z2RAM_CHUNK1024 ( Z2RAM_CHUNKSIZE >> 10 )
59 59
60static DEFINE_MUTEX(z2ram_mutex);
60static u_long *z2ram_map = NULL; 61static u_long *z2ram_map = NULL;
61static u_long z2ram_size = 0; 62static u_long z2ram_size = 0;
62static int z2_count = 0; 63static int z2_count = 0;
@@ -154,7 +155,7 @@ static int z2_open(struct block_device *bdev, fmode_t mode)
154 155
155 device = MINOR(bdev->bd_dev); 156 device = MINOR(bdev->bd_dev);
156 157
157 lock_kernel(); 158 mutex_lock(&z2ram_mutex);
158 if ( current_device != -1 && current_device != device ) 159 if ( current_device != -1 && current_device != device )
159 { 160 {
160 rc = -EBUSY; 161 rc = -EBUSY;
@@ -296,25 +297,25 @@ static int z2_open(struct block_device *bdev, fmode_t mode)
296 set_capacity(z2ram_gendisk, z2ram_size >> 9); 297 set_capacity(z2ram_gendisk, z2ram_size >> 9);
297 } 298 }
298 299
299 unlock_kernel(); 300 mutex_unlock(&z2ram_mutex);
300 return 0; 301 return 0;
301 302
302err_out_kfree: 303err_out_kfree:
303 kfree(z2ram_map); 304 kfree(z2ram_map);
304err_out: 305err_out:
305 unlock_kernel(); 306 mutex_unlock(&z2ram_mutex);
306 return rc; 307 return rc;
307} 308}
308 309
309static int 310static int
310z2_release(struct gendisk *disk, fmode_t mode) 311z2_release(struct gendisk *disk, fmode_t mode)
311{ 312{
312 lock_kernel(); 313 mutex_lock(&z2ram_mutex);
313 if ( current_device == -1 ) { 314 if ( current_device == -1 ) {
314 unlock_kernel(); 315 mutex_unlock(&z2ram_mutex);
315 return 0; 316 return 0;
316 } 317 }
317 unlock_kernel(); 318 mutex_unlock(&z2ram_mutex);
318 /* 319 /*
319 * FIXME: unmap memory 320 * FIXME: unmap memory
320 */ 321 */
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 261107d1457c..3af6516919b7 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -34,7 +34,7 @@
34#include <linux/blkdev.h> 34#include <linux/blkdev.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/device.h> 36#include <linux/device.h>
37#include <linux/smp_lock.h> 37#include <linux/mutex.h>
38#include <linux/wait.h> 38#include <linux/wait.h>
39#include <linux/workqueue.h> 39#include <linux/workqueue.h>
40#include <linux/platform_device.h> 40#include <linux/platform_device.h>
@@ -81,6 +81,7 @@
81 81
82#define GDROM_DEFAULT_TIMEOUT (HZ * 7) 82#define GDROM_DEFAULT_TIMEOUT (HZ * 7)
83 83
84static DEFINE_MUTEX(gdrom_mutex);
84static const struct { 85static const struct {
85 int sense_key; 86 int sense_key;
86 const char * const text; 87 const char * const text;
@@ -494,17 +495,17 @@ static struct cdrom_device_ops gdrom_ops = {
494static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode) 495static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
495{ 496{
496 int ret; 497 int ret;
497 lock_kernel(); 498 mutex_lock(&gdrom_mutex);
498 ret = cdrom_open(gd.cd_info, bdev, mode); 499 ret = cdrom_open(gd.cd_info, bdev, mode);
499 unlock_kernel(); 500 mutex_unlock(&gdrom_mutex);
500 return ret; 501 return ret;
501} 502}
502 503
503static int gdrom_bdops_release(struct gendisk *disk, fmode_t mode) 504static int gdrom_bdops_release(struct gendisk *disk, fmode_t mode)
504{ 505{
505 lock_kernel(); 506 mutex_lock(&gdrom_mutex);
506 cdrom_release(gd.cd_info, mode); 507 cdrom_release(gd.cd_info, mode);
507 unlock_kernel(); 508 mutex_unlock(&gdrom_mutex);
508 return 0; 509 return 0;
509} 510}
510 511
@@ -518,9 +519,9 @@ static int gdrom_bdops_ioctl(struct block_device *bdev, fmode_t mode,
518{ 519{
519 int ret; 520 int ret;
520 521
521 lock_kernel(); 522 mutex_lock(&gdrom_mutex);
522 ret = cdrom_ioctl(gd.cd_info, bdev, mode, cmd, arg); 523 ret = cdrom_ioctl(gd.cd_info, bdev, mode, cmd, arg);
523 unlock_kernel(); 524 mutex_unlock(&gdrom_mutex);
524 525
525 return ret; 526 return ret;
526} 527}
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index 56bf9f44700c..be73a9b493a6 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -42,7 +42,7 @@
42#include <linux/module.h> 42#include <linux/module.h>
43#include <linux/completion.h> 43#include <linux/completion.h>
44#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
45#include <linux/smp_lock.h> 45#include <linux/mutex.h>
46#include <linux/seq_file.h> 46#include <linux/seq_file.h>
47#include <linux/scatterlist.h> 47#include <linux/scatterlist.h>
48 48
@@ -61,6 +61,7 @@
61 */ 61 */
62#define VIOCD_MAX_CD HVMAXARCHITECTEDVIRTUALCDROMS 62#define VIOCD_MAX_CD HVMAXARCHITECTEDVIRTUALCDROMS
63 63
64static DEFINE_MUTEX(viocd_mutex);
64static const struct vio_error_entry viocd_err_table[] = { 65static const struct vio_error_entry viocd_err_table[] = {
65 {0x0201, EINVAL, "Invalid Range"}, 66 {0x0201, EINVAL, "Invalid Range"},
66 {0x0202, EINVAL, "Invalid Token"}, 67 {0x0202, EINVAL, "Invalid Token"},
@@ -156,9 +157,9 @@ static int viocd_blk_open(struct block_device *bdev, fmode_t mode)
156 struct disk_info *di = bdev->bd_disk->private_data; 157 struct disk_info *di = bdev->bd_disk->private_data;
157 int ret; 158 int ret;
158 159
159 lock_kernel(); 160 mutex_lock(&viocd_mutex);
160 ret = cdrom_open(&di->viocd_info, bdev, mode); 161 ret = cdrom_open(&di->viocd_info, bdev, mode);
161 unlock_kernel(); 162 mutex_unlock(&viocd_mutex);
162 163
163 return ret; 164 return ret;
164} 165}
@@ -166,9 +167,9 @@ static int viocd_blk_open(struct block_device *bdev, fmode_t mode)
166static int viocd_blk_release(struct gendisk *disk, fmode_t mode) 167static int viocd_blk_release(struct gendisk *disk, fmode_t mode)
167{ 168{
168 struct disk_info *di = disk->private_data; 169 struct disk_info *di = disk->private_data;
169 lock_kernel(); 170 mutex_lock(&viocd_mutex);
170 cdrom_release(&di->viocd_info, mode); 171 cdrom_release(&di->viocd_info, mode);
171 unlock_kernel(); 172 mutex_unlock(&viocd_mutex);
172 return 0; 173 return 0;
173} 174}
174 175
@@ -178,9 +179,9 @@ static int viocd_blk_ioctl(struct block_device *bdev, fmode_t mode,
178 struct disk_info *di = bdev->bd_disk->private_data; 179 struct disk_info *di = bdev->bd_disk->private_data;
179 int ret; 180 int ret;
180 181
181 lock_kernel(); 182 mutex_lock(&viocd_mutex);
182 ret = cdrom_ioctl(&di->viocd_info, bdev, mode, cmd, arg); 183 ret = cdrom_ioctl(&di->viocd_info, bdev, mode, cmd, arg);
183 unlock_kernel(); 184 mutex_unlock(&viocd_mutex);
184 185
185 return ret; 186 return ret;
186} 187}
diff --git a/drivers/char/apm-emulation.c b/drivers/char/apm-emulation.c
index 033e1505fca9..6a420baea268 100644
--- a/drivers/char/apm-emulation.c
+++ b/drivers/char/apm-emulation.c
@@ -13,7 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/poll.h> 14#include <linux/poll.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/smp_lock.h> 16#include <linux/mutex.h>
17#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
18#include <linux/seq_file.h> 18#include <linux/seq_file.h>
19#include <linux/miscdevice.h> 19#include <linux/miscdevice.h>
@@ -126,6 +126,7 @@ struct apm_user {
126/* 126/*
127 * Local variables 127 * Local variables
128 */ 128 */
129static DEFINE_MUTEX(apm_mutex);
129static atomic_t suspend_acks_pending = ATOMIC_INIT(0); 130static atomic_t suspend_acks_pending = ATOMIC_INIT(0);
130static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0); 131static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0);
131static int apm_disabled; 132static int apm_disabled;
@@ -274,7 +275,7 @@ apm_ioctl(struct file *filp, u_int cmd, u_long arg)
274 if (!as->suser || !as->writer) 275 if (!as->suser || !as->writer)
275 return -EPERM; 276 return -EPERM;
276 277
277 lock_kernel(); 278 mutex_lock(&apm_mutex);
278 switch (cmd) { 279 switch (cmd) {
279 case APM_IOC_SUSPEND: 280 case APM_IOC_SUSPEND:
280 mutex_lock(&state_lock); 281 mutex_lock(&state_lock);
@@ -335,7 +336,7 @@ apm_ioctl(struct file *filp, u_int cmd, u_long arg)
335 mutex_unlock(&state_lock); 336 mutex_unlock(&state_lock);
336 break; 337 break;
337 } 338 }
338 unlock_kernel(); 339 mutex_unlock(&apm_mutex);
339 340
340 return err; 341 return err;
341} 342}
@@ -370,7 +371,7 @@ static int apm_open(struct inode * inode, struct file * filp)
370{ 371{
371 struct apm_user *as; 372 struct apm_user *as;
372 373
373 lock_kernel(); 374 mutex_lock(&apm_mutex);
374 as = kzalloc(sizeof(*as), GFP_KERNEL); 375 as = kzalloc(sizeof(*as), GFP_KERNEL);
375 if (as) { 376 if (as) {
376 /* 377 /*
@@ -390,7 +391,7 @@ static int apm_open(struct inode * inode, struct file * filp)
390 391
391 filp->private_data = as; 392 filp->private_data = as;
392 } 393 }
393 unlock_kernel(); 394 mutex_unlock(&apm_mutex);
394 395
395 return as ? 0 : -ENOMEM; 396 return as ? 0 : -ENOMEM;
396} 397}
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index f4ae0e0fb631..e7ba774beda6 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -26,7 +26,7 @@
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/smp_lock.h> 29#include <linux/mutex.h>
30#include <linux/miscdevice.h> 30#include <linux/miscdevice.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/wait.h> 32#include <linux/wait.h>
@@ -60,6 +60,7 @@
60#define PCI_DEVICE_ID_APPLICOM_PCI2000PFB 0x0003 60#define PCI_DEVICE_ID_APPLICOM_PCI2000PFB 0x0003
61#endif 61#endif
62 62
63static DEFINE_MUTEX(ac_mutex);
63static char *applicom_pci_devnames[] = { 64static char *applicom_pci_devnames[] = {
64 "PCI board", 65 "PCI board",
65 "PCI2000IBS / PCI2000CAN", 66 "PCI2000IBS / PCI2000CAN",
@@ -707,7 +708,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
707 if (IS_ERR(adgl)) 708 if (IS_ERR(adgl))
708 return PTR_ERR(adgl); 709 return PTR_ERR(adgl);
709 710
710 lock_kernel(); 711 mutex_lock(&ac_mutex);
711 IndexCard = adgl->num_card-1; 712 IndexCard = adgl->num_card-1;
712 713
713 if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) { 714 if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
@@ -717,7 +718,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
717 warncount--; 718 warncount--;
718 } 719 }
719 kfree(adgl); 720 kfree(adgl);
720 unlock_kernel(); 721 mutex_unlock(&ac_mutex);
721 return -EINVAL; 722 return -EINVAL;
722 } 723 }
723 724
@@ -835,7 +836,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
835 } 836 }
836 Dummy = readb(apbs[IndexCard].RamIO + VERS); 837 Dummy = readb(apbs[IndexCard].RamIO + VERS);
837 kfree(adgl); 838 kfree(adgl);
838 unlock_kernel(); 839 mutex_unlock(&ac_mutex);
839 return 0; 840 return 0;
840} 841}
841 842
diff --git a/drivers/char/ds1302.c b/drivers/char/ds1302.c
index 170693c93c73..e3d72aa3cbd2 100644
--- a/drivers/char/ds1302.c
+++ b/drivers/char/ds1302.c
@@ -20,7 +20,7 @@
20#include <linux/miscdevice.h> 20#include <linux/miscdevice.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/bcd.h> 22#include <linux/bcd.h>
23#include <linux/smp_lock.h> 23#include <linux/mutex.h>
24#include <linux/uaccess.h> 24#include <linux/uaccess.h>
25#include <linux/io.h> 25#include <linux/io.h>
26 26
@@ -32,6 +32,7 @@
32 32
33#define RTC_MAJOR_NR 121 /* local major, change later */ 33#define RTC_MAJOR_NR 121 /* local major, change later */
34 34
35static DEFINE_MUTEX(rtc_mutex);
35static const char ds1302_name[] = "ds1302"; 36static const char ds1302_name[] = "ds1302";
36 37
37/* Send 8 bits. */ 38/* Send 8 bits. */
@@ -164,9 +165,9 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
164 struct rtc_time rtc_tm; 165 struct rtc_time rtc_tm;
165 166
166 memset(&rtc_tm, 0, sizeof (struct rtc_time)); 167 memset(&rtc_tm, 0, sizeof (struct rtc_time));
167 lock_kernel(); 168 mutex_lock(&rtc_mutex);
168 get_rtc_time(&rtc_tm); 169 get_rtc_time(&rtc_tm);
169 unlock_kernel(); 170 mutex_unlock(&rtc_mutex);
170 if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time))) 171 if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time)))
171 return -EFAULT; 172 return -EFAULT;
172 return 0; 173 return 0;
@@ -218,7 +219,7 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
218 mon = bin2bcd(mon); 219 mon = bin2bcd(mon);
219 yrs = bin2bcd(yrs); 220 yrs = bin2bcd(yrs);
220 221
221 lock_kernel(); 222 mutex_lock(&rtc_mutex);
222 local_irq_save(flags); 223 local_irq_save(flags);
223 CMOS_WRITE(yrs, RTC_YEAR); 224 CMOS_WRITE(yrs, RTC_YEAR);
224 CMOS_WRITE(mon, RTC_MONTH); 225 CMOS_WRITE(mon, RTC_MONTH);
@@ -227,7 +228,7 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
227 CMOS_WRITE(min, RTC_MINUTES); 228 CMOS_WRITE(min, RTC_MINUTES);
228 CMOS_WRITE(sec, RTC_SECONDS); 229 CMOS_WRITE(sec, RTC_SECONDS);
229 local_irq_restore(flags); 230 local_irq_restore(flags);
230 unlock_kernel(); 231 mutex_unlock(&rtc_mutex);
231 232
232 /* Notice that at this point, the RTC is updated but 233 /* Notice that at this point, the RTC is updated but
233 * the kernel is still running with the old time. 234 * the kernel is still running with the old time.
@@ -247,10 +248,10 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
247 if(copy_from_user(&tcs_val, (int*)arg, sizeof(int))) 248 if(copy_from_user(&tcs_val, (int*)arg, sizeof(int)))
248 return -EFAULT; 249 return -EFAULT;
249 250
250 lock_kernel(); 251 mutex_lock(&rtc_mutex);
251 tcs_val = RTC_TCR_PATTERN | (tcs_val & 0x0F); 252 tcs_val = RTC_TCR_PATTERN | (tcs_val & 0x0F);
252 ds1302_writereg(RTC_TRICKLECHARGER, tcs_val); 253 ds1302_writereg(RTC_TRICKLECHARGER, tcs_val);
253 unlock_kernel(); 254 mutex_unlock(&rtc_mutex);
254 return 0; 255 return 0;
255 } 256 }
256 default: 257 default:
diff --git a/drivers/char/ds1620.c b/drivers/char/ds1620.c
index dbee8688f75c..9aa1fd059aea 100644
--- a/drivers/char/ds1620.c
+++ b/drivers/char/ds1620.c
@@ -8,7 +8,7 @@
8#include <linux/proc_fs.h> 8#include <linux/proc_fs.h>
9#include <linux/capability.h> 9#include <linux/capability.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/smp_lock.h> 11#include <linux/mutex.h>
12 12
13#include <mach/hardware.h> 13#include <mach/hardware.h>
14#include <asm/mach-types.h> 14#include <asm/mach-types.h>
@@ -34,6 +34,7 @@
34#define CFG_CPU 2 34#define CFG_CPU 2
35#define CFG_1SHOT 1 35#define CFG_1SHOT 1
36 36
37static DEFINE_MUTEX(ds1620_mutex);
37static const char *fan_state[] = { "off", "on", "on (hardwired)" }; 38static const char *fan_state[] = { "off", "on", "on (hardwired)" };
38 39
39/* 40/*
@@ -210,7 +211,6 @@ static void ds1620_read_state(struct therm *therm)
210 211
211static int ds1620_open(struct inode *inode, struct file *file) 212static int ds1620_open(struct inode *inode, struct file *file)
212{ 213{
213 cycle_kernel_lock();
214 return nonseekable_open(inode, file); 214 return nonseekable_open(inode, file);
215} 215}
216 216
@@ -321,9 +321,9 @@ ds1620_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
321{ 321{
322 int ret; 322 int ret;
323 323
324 lock_kernel(); 324 mutex_lock(&ds1620_mutex);
325 ret = ds1620_ioctl(file, cmd, arg); 325 ret = ds1620_ioctl(file, cmd, arg);
326 unlock_kernel(); 326 mutex_unlock(&ds1620_mutex);
327 327
328 return ret; 328 return ret;
329} 329}
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index 8a1b28a10ef0..b3c756227e39 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -32,7 +32,7 @@
32#include <linux/mm.h> 32#include <linux/mm.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/device.h> 34#include <linux/device.h>
35#include <linux/smp_lock.h> 35#include <linux/mutex.h>
36#include <linux/firmware.h> 36#include <linux/firmware.h>
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38#include <linux/uaccess.h> /* For put_user and get_user */ 38#include <linux/uaccess.h> /* For put_user and get_user */
@@ -94,6 +94,7 @@
94 } \ 94 } \
95} 95}
96 96
97static DEFINE_MUTEX(dsp56k_mutex);
97static struct dsp56k_device { 98static struct dsp56k_device {
98 unsigned long in_use; 99 unsigned long in_use;
99 long maxio, timeout; 100 long maxio, timeout;
@@ -330,9 +331,9 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,
330 if (len > DSP56K_MAX_BINARY_LENGTH) { 331 if (len > DSP56K_MAX_BINARY_LENGTH) {
331 return -EINVAL; 332 return -EINVAL;
332 } 333 }
333 lock_kernel(); 334 mutex_lock(&dsp56k_mutex);
334 r = dsp56k_upload(bin, len); 335 r = dsp56k_upload(bin, len);
335 unlock_kernel(); 336 mutex_unlock(&dsp56k_mutex);
336 if (r < 0) { 337 if (r < 0) {
337 return r; 338 return r;
338 } 339 }
@@ -342,16 +343,16 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,
342 case DSP56K_SET_TX_WSIZE: 343 case DSP56K_SET_TX_WSIZE:
343 if (arg > 4 || arg < 1) 344 if (arg > 4 || arg < 1)
344 return -EINVAL; 345 return -EINVAL;
345 lock_kernel(); 346 mutex_lock(&dsp56k_mutex);
346 dsp56k.tx_wsize = (int) arg; 347 dsp56k.tx_wsize = (int) arg;
347 unlock_kernel(); 348 mutex_unlock(&dsp56k_mutex);
348 break; 349 break;
349 case DSP56K_SET_RX_WSIZE: 350 case DSP56K_SET_RX_WSIZE:
350 if (arg > 4 || arg < 1) 351 if (arg > 4 || arg < 1)
351 return -EINVAL; 352 return -EINVAL;
352 lock_kernel(); 353 mutex_lock(&dsp56k_mutex);
353 dsp56k.rx_wsize = (int) arg; 354 dsp56k.rx_wsize = (int) arg;
354 unlock_kernel(); 355 mutex_unlock(&dsp56k_mutex);
355 break; 356 break;
356 case DSP56K_HOST_FLAGS: 357 case DSP56K_HOST_FLAGS:
357 { 358 {
@@ -363,7 +364,7 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,
363 if(get_user(out, &hf->out) < 0) 364 if(get_user(out, &hf->out) < 0)
364 return -EFAULT; 365 return -EFAULT;
365 366
366 lock_kernel(); 367 mutex_lock(&dsp56k_mutex);
367 if ((dir & 0x1) && (out & 0x1)) 368 if ((dir & 0x1) && (out & 0x1))
368 dsp56k_host_interface.icr |= DSP56K_ICR_HF0; 369 dsp56k_host_interface.icr |= DSP56K_ICR_HF0;
369 else if (dir & 0x1) 370 else if (dir & 0x1)
@@ -378,16 +379,16 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,
378 if (dsp56k_host_interface.icr & DSP56K_ICR_HF1) status |= 0x2; 379 if (dsp56k_host_interface.icr & DSP56K_ICR_HF1) status |= 0x2;
379 if (dsp56k_host_interface.isr & DSP56K_ISR_HF2) status |= 0x4; 380 if (dsp56k_host_interface.isr & DSP56K_ISR_HF2) status |= 0x4;
380 if (dsp56k_host_interface.isr & DSP56K_ISR_HF3) status |= 0x8; 381 if (dsp56k_host_interface.isr & DSP56K_ISR_HF3) status |= 0x8;
381 unlock_kernel(); 382 mutex_unlock(&dsp56k_mutex);
382 return put_user(status, &hf->status); 383 return put_user(status, &hf->status);
383 } 384 }
384 case DSP56K_HOST_CMD: 385 case DSP56K_HOST_CMD:
385 if (arg > 31 || arg < 0) 386 if (arg > 31 || arg < 0)
386 return -EINVAL; 387 return -EINVAL;
387 lock_kernel(); 388 mutex_lock(&dsp56k_mutex);
388 dsp56k_host_interface.cvr = (u_char)((arg & DSP56K_CVR_HV_MASK) | 389 dsp56k_host_interface.cvr = (u_char)((arg & DSP56K_CVR_HV_MASK) |
389 DSP56K_CVR_HC); 390 DSP56K_CVR_HC);
390 unlock_kernel(); 391 mutex_unlock(&dsp56k_mutex);
391 break; 392 break;
392 default: 393 default:
393 return -EINVAL; 394 return -EINVAL;
@@ -427,7 +428,7 @@ static int dsp56k_open(struct inode *inode, struct file *file)
427 int dev = iminor(inode) & 0x0f; 428 int dev = iminor(inode) & 0x0f;
428 int ret = 0; 429 int ret = 0;
429 430
430 lock_kernel(); 431 mutex_lock(&dsp56k_mutex);
431 switch(dev) 432 switch(dev)
432 { 433 {
433 case DSP56K_DEV_56001: 434 case DSP56K_DEV_56001:
@@ -454,7 +455,7 @@ static int dsp56k_open(struct inode *inode, struct file *file)
454 ret = -ENODEV; 455 ret = -ENODEV;
455 } 456 }
456out: 457out:
457 unlock_kernel(); 458 mutex_unlock(&dsp56k_mutex);
458 return ret; 459 return ret;
459} 460}
460 461
diff --git a/drivers/char/dtlk.c b/drivers/char/dtlk.c
index e3859d4eaead..8dd040a945d4 100644
--- a/drivers/char/dtlk.c
+++ b/drivers/char/dtlk.c
@@ -57,7 +57,7 @@
57#include <linux/ioport.h> /* for request_region */ 57#include <linux/ioport.h> /* for request_region */
58#include <linux/delay.h> /* for loops_per_jiffy */ 58#include <linux/delay.h> /* for loops_per_jiffy */
59#include <linux/sched.h> 59#include <linux/sched.h>
60#include <linux/smp_lock.h> /* cycle_kernel_lock() */ 60#include <linux/mutex.h>
61#include <asm/io.h> /* for inb_p, outb_p, inb, outb, etc. */ 61#include <asm/io.h> /* for inb_p, outb_p, inb, outb, etc. */
62#include <asm/uaccess.h> /* for get_user, etc. */ 62#include <asm/uaccess.h> /* for get_user, etc. */
63#include <linux/wait.h> /* for wait_queue */ 63#include <linux/wait.h> /* for wait_queue */
@@ -73,6 +73,7 @@
73#define TRACE_RET ((void) 0) 73#define TRACE_RET ((void) 0)
74#endif /* TRACING */ 74#endif /* TRACING */
75 75
76static DEFINE_MUTEX(dtlk_mutex);
76static void dtlk_timer_tick(unsigned long data); 77static void dtlk_timer_tick(unsigned long data);
77 78
78static int dtlk_major; 79static int dtlk_major;
@@ -275,9 +276,9 @@ static long dtlk_ioctl(struct file *file,
275 switch (cmd) { 276 switch (cmd) {
276 277
277 case DTLK_INTERROGATE: 278 case DTLK_INTERROGATE:
278 lock_kernel(); 279 mutex_lock(&dtlk_mutex);
279 sp = dtlk_interrogate(); 280 sp = dtlk_interrogate();
280 unlock_kernel(); 281 mutex_unlock(&dtlk_mutex);
281 if (copy_to_user(argp, sp, sizeof(struct dtlk_settings))) 282 if (copy_to_user(argp, sp, sizeof(struct dtlk_settings)))
282 return -EINVAL; 283 return -EINVAL;
283 return 0; 284 return 0;
@@ -296,7 +297,6 @@ static int dtlk_open(struct inode *inode, struct file *file)
296{ 297{
297 TRACE_TEXT("(dtlk_open"); 298 TRACE_TEXT("(dtlk_open");
298 299
299 cycle_kernel_lock();
300 nonseekable_open(inode, file); 300 nonseekable_open(inode, file);
301 switch (iminor(inode)) { 301 switch (iminor(inode)) {
302 case DTLK_MINOR: 302 case DTLK_MINOR:
diff --git a/drivers/char/generic_nvram.c b/drivers/char/generic_nvram.c
index 82b5a88a82d7..0e941b57482e 100644
--- a/drivers/char/generic_nvram.c
+++ b/drivers/char/generic_nvram.c
@@ -19,7 +19,7 @@
19#include <linux/miscdevice.h> 19#include <linux/miscdevice.h>
20#include <linux/fcntl.h> 20#include <linux/fcntl.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/smp_lock.h> 22#include <linux/mutex.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <asm/nvram.h> 24#include <asm/nvram.h>
25#ifdef CONFIG_PPC_PMAC 25#ifdef CONFIG_PPC_PMAC
@@ -28,6 +28,7 @@
28 28
29#define NVRAM_SIZE 8192 29#define NVRAM_SIZE 8192
30 30
31static DEFINE_MUTEX(nvram_mutex);
31static ssize_t nvram_len; 32static ssize_t nvram_len;
32 33
33static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) 34static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
@@ -120,9 +121,9 @@ static long nvram_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned l
120{ 121{
121 int ret; 122 int ret;
122 123
123 lock_kernel(); 124 mutex_lock(&nvram_mutex);
124 ret = nvram_ioctl(file, cmd, arg); 125 ret = nvram_ioctl(file, cmd, arg);
125 unlock_kernel(); 126 mutex_unlock(&nvram_mutex);
126 127
127 return ret; 128 return ret;
128} 129}
diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
index b6c2cc167c11..2aa69f97360d 100644
--- a/drivers/char/genrtc.c
+++ b/drivers/char/genrtc.c
@@ -52,7 +52,7 @@
52#include <linux/init.h> 52#include <linux/init.h>
53#include <linux/poll.h> 53#include <linux/poll.h>
54#include <linux/proc_fs.h> 54#include <linux/proc_fs.h>
55#include <linux/smp_lock.h> 55#include <linux/mutex.h>
56#include <linux/workqueue.h> 56#include <linux/workqueue.h>
57 57
58#include <asm/uaccess.h> 58#include <asm/uaccess.h>
@@ -66,6 +66,7 @@
66 * ioctls. 66 * ioctls.
67 */ 67 */
68 68
69static DEFINE_MUTEX(gen_rtc_mutex);
69static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); 70static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait);
70 71
71/* 72/*
@@ -337,9 +338,9 @@ static long gen_rtc_unlocked_ioctl(struct file *file, unsigned int cmd,
337{ 338{
338 int ret; 339 int ret;
339 340
340 lock_kernel(); 341 mutex_lock(&gen_rtc_mutex);
341 ret = gen_rtc_ioctl(file, cmd, arg); 342 ret = gen_rtc_ioctl(file, cmd, arg);
342 unlock_kernel(); 343 mutex_unlock(&gen_rtc_mutex);
343 344
344 return ret; 345 return ret;
345} 346}
@@ -352,16 +353,16 @@ static long gen_rtc_unlocked_ioctl(struct file *file, unsigned int cmd,
352 353
353static int gen_rtc_open(struct inode *inode, struct file *file) 354static int gen_rtc_open(struct inode *inode, struct file *file)
354{ 355{
355 lock_kernel(); 356 mutex_lock(&gen_rtc_mutex);
356 if (gen_rtc_status & RTC_IS_OPEN) { 357 if (gen_rtc_status & RTC_IS_OPEN) {
357 unlock_kernel(); 358 mutex_unlock(&gen_rtc_mutex);
358 return -EBUSY; 359 return -EBUSY;
359 } 360 }
360 361
361 gen_rtc_status |= RTC_IS_OPEN; 362 gen_rtc_status |= RTC_IS_OPEN;
362 gen_rtc_irq_data = 0; 363 gen_rtc_irq_data = 0;
363 irq_active = 0; 364 irq_active = 0;
364 unlock_kernel(); 365 mutex_unlock(&gen_rtc_mutex);
365 366
366 return 0; 367 return 0;
367} 368}
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index 4cd8b227c11f..3bc0eef88717 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -23,7 +23,7 @@
23#include <linux/seq_file.h> 23#include <linux/seq_file.h>
24#include <linux/dmi.h> 24#include <linux/dmi.h>
25#include <linux/capability.h> 25#include <linux/capability.h>
26#include <linux/smp_lock.h> 26#include <linux/mutex.h>
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <asm/io.h> 28#include <asm/io.h>
29 29
@@ -56,6 +56,7 @@
56 56
57#define I8K_TEMPERATURE_BUG 1 57#define I8K_TEMPERATURE_BUG 1
58 58
59static DEFINE_MUTEX(i8k_mutex);
59static char bios_version[4]; 60static char bios_version[4];
60 61
61MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); 62MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
@@ -399,9 +400,9 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
399{ 400{
400 long ret; 401 long ret;
401 402
402 lock_kernel(); 403 mutex_lock(&i8k_mutex);
403 ret = i8k_ioctl_unlocked(fp, cmd, arg); 404 ret = i8k_ioctl_unlocked(fp, cmd, arg);
404 unlock_kernel(); 405 mutex_unlock(&i8k_mutex);
405 406
406 return ret; 407 return ret;
407} 408}
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index d4b71e8d0d23..dfbdf49d1e80 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -98,7 +98,7 @@
98#include <linux/major.h> 98#include <linux/major.h>
99#include <linux/wait.h> 99#include <linux/wait.h>
100#include <linux/device.h> 100#include <linux/device.h>
101#include <linux/smp_lock.h> 101#include <linux/mutex.h>
102#include <linux/firmware.h> 102#include <linux/firmware.h>
103#include <linux/platform_device.h> 103#include <linux/platform_device.h>
104 104
@@ -138,6 +138,7 @@
138#include <linux/proc_fs.h> 138#include <linux/proc_fs.h>
139#include <linux/seq_file.h> 139#include <linux/seq_file.h>
140 140
141static DEFINE_MUTEX(ip2_mutex);
141static const struct file_operations ip2mem_proc_fops; 142static const struct file_operations ip2mem_proc_fops;
142static const struct file_operations ip2_proc_fops; 143static const struct file_operations ip2_proc_fops;
143 144
@@ -2897,7 +2898,7 @@ ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg )
2897 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg ); 2898 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
2898#endif 2899#endif
2899 2900
2900 lock_kernel(); 2901 mutex_lock(&ip2_mutex);
2901 2902
2902 switch ( iplminor ) { 2903 switch ( iplminor ) {
2903 case 0: // IPL device 2904 case 0: // IPL device
@@ -2961,7 +2962,7 @@ ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg )
2961 rc = -ENODEV; 2962 rc = -ENODEV;
2962 break; 2963 break;
2963 } 2964 }
2964 unlock_kernel(); 2965 mutex_unlock(&ip2_mutex);
2965 return rc; 2966 return rc;
2966} 2967}
2967 2968
@@ -2982,7 +2983,6 @@ ip2_ipl_open( struct inode *pInode, struct file *pFile )
2982#ifdef IP2DEBUG_IPL 2983#ifdef IP2DEBUG_IPL
2983 printk (KERN_DEBUG "IP2IPL: open\n" ); 2984 printk (KERN_DEBUG "IP2IPL: open\n" );
2984#endif 2985#endif
2985 cycle_kernel_lock();
2986 return 0; 2986 return 0;
2987} 2987}
2988 2988
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index d8ec92a38980..44833de47728 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -44,7 +44,6 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/device.h> 45#include <linux/device.h>
46#include <linux/compat.h> 46#include <linux/compat.h>
47#include <linux/smp_lock.h>
48 47
49struct ipmi_file_private 48struct ipmi_file_private
50{ 49{
@@ -59,6 +58,7 @@ struct ipmi_file_private
59 unsigned int default_retry_time_ms; 58 unsigned int default_retry_time_ms;
60}; 59};
61 60
61static DEFINE_MUTEX(ipmi_mutex);
62static void file_receive_handler(struct ipmi_recv_msg *msg, 62static void file_receive_handler(struct ipmi_recv_msg *msg,
63 void *handler_data) 63 void *handler_data)
64{ 64{
@@ -102,9 +102,9 @@ static int ipmi_fasync(int fd, struct file *file, int on)
102 struct ipmi_file_private *priv = file->private_data; 102 struct ipmi_file_private *priv = file->private_data;
103 int result; 103 int result;
104 104
105 lock_kernel(); /* could race against open() otherwise */ 105 mutex_lock(&ipmi_mutex); /* could race against open() otherwise */
106 result = fasync_helper(fd, file, on, &priv->fasync_queue); 106 result = fasync_helper(fd, file, on, &priv->fasync_queue);
107 unlock_kernel(); 107 mutex_unlock(&ipmi_mutex);
108 108
109 return (result); 109 return (result);
110} 110}
@@ -125,7 +125,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
125 if (!priv) 125 if (!priv)
126 return -ENOMEM; 126 return -ENOMEM;
127 127
128 lock_kernel(); 128 mutex_lock(&ipmi_mutex);
129 priv->file = file; 129 priv->file = file;
130 130
131 rv = ipmi_create_user(if_num, 131 rv = ipmi_create_user(if_num,
@@ -150,7 +150,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
150 priv->default_retry_time_ms = 0; 150 priv->default_retry_time_ms = 0;
151 151
152out: 152out:
153 unlock_kernel(); 153 mutex_unlock(&ipmi_mutex);
154 return rv; 154 return rv;
155} 155}
156 156
@@ -639,9 +639,9 @@ static long ipmi_unlocked_ioctl(struct file *file,
639{ 639{
640 int ret; 640 int ret;
641 641
642 lock_kernel(); 642 mutex_lock(&ipmi_mutex);
643 ret = ipmi_ioctl(file, cmd, data); 643 ret = ipmi_ioctl(file, cmd, data);
644 unlock_kernel(); 644 mutex_unlock(&ipmi_mutex);
645 645
646 return ret; 646 return ret;
647} 647}
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 654d566ca57c..ed10b741962d 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -35,7 +35,7 @@
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36#include <linux/ipmi.h> 36#include <linux/ipmi.h>
37#include <linux/ipmi_smi.h> 37#include <linux/ipmi_smi.h>
38#include <linux/smp_lock.h> 38#include <linux/mutex.h>
39#include <linux/watchdog.h> 39#include <linux/watchdog.h>
40#include <linux/miscdevice.h> 40#include <linux/miscdevice.h>
41#include <linux/init.h> 41#include <linux/init.h>
@@ -149,6 +149,7 @@
149#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int) 149#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int)
150#endif 150#endif
151 151
152static DEFINE_MUTEX(ipmi_watchdog_mutex);
152static int nowayout = WATCHDOG_NOWAYOUT; 153static int nowayout = WATCHDOG_NOWAYOUT;
153 154
154static ipmi_user_t watchdog_user; 155static ipmi_user_t watchdog_user;
@@ -748,9 +749,9 @@ static long ipmi_unlocked_ioctl(struct file *file,
748{ 749{
749 int ret; 750 int ret;
750 751
751 lock_kernel(); 752 mutex_lock(&ipmi_watchdog_mutex);
752 ret = ipmi_ioctl(file, cmd, arg); 753 ret = ipmi_ioctl(file, cmd, arg);
753 unlock_kernel(); 754 mutex_unlock(&ipmi_watchdog_mutex);
754 755
755 return ret; 756 return ret;
756} 757}
@@ -844,7 +845,6 @@ static int ipmi_open(struct inode *ino, struct file *filep)
844 if (test_and_set_bit(0, &ipmi_wdog_open)) 845 if (test_and_set_bit(0, &ipmi_wdog_open))
845 return -EBUSY; 846 return -EBUSY;
846 847
847 cycle_kernel_lock();
848 848
849 /* 849 /*
850 * Don't start the timer now, let it start on the 850 * Don't start the timer now, let it start on the
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 938a3a273886..598d278db058 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -126,7 +126,7 @@
126#include <linux/device.h> 126#include <linux/device.h>
127#include <linux/wait.h> 127#include <linux/wait.h>
128#include <linux/jiffies.h> 128#include <linux/jiffies.h>
129#include <linux/smp_lock.h> 129#include <linux/mutex.h>
130#include <linux/compat.h> 130#include <linux/compat.h>
131 131
132#include <linux/parport.h> 132#include <linux/parport.h>
@@ -140,6 +140,7 @@
140/* if you have more than 8 printers, remember to increase LP_NO */ 140/* if you have more than 8 printers, remember to increase LP_NO */
141#define LP_NO 8 141#define LP_NO 8
142 142
143static DEFINE_MUTEX(lp_mutex);
143static struct lp_struct lp_table[LP_NO]; 144static struct lp_struct lp_table[LP_NO];
144 145
145static unsigned int lp_count = 0; 146static unsigned int lp_count = 0;
@@ -493,7 +494,7 @@ static int lp_open(struct inode * inode, struct file * file)
493 unsigned int minor = iminor(inode); 494 unsigned int minor = iminor(inode);
494 int ret = 0; 495 int ret = 0;
495 496
496 lock_kernel(); 497 mutex_lock(&lp_mutex);
497 if (minor >= LP_NO) { 498 if (minor >= LP_NO) {
498 ret = -ENXIO; 499 ret = -ENXIO;
499 goto out; 500 goto out;
@@ -554,7 +555,7 @@ static int lp_open(struct inode * inode, struct file * file)
554 lp_release_parport (&lp_table[minor]); 555 lp_release_parport (&lp_table[minor]);
555 lp_table[minor].current_mode = IEEE1284_MODE_COMPAT; 556 lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
556out: 557out:
557 unlock_kernel(); 558 mutex_unlock(&lp_mutex);
558 return ret; 559 return ret;
559} 560}
560 561
@@ -680,7 +681,7 @@ static long lp_ioctl(struct file *file, unsigned int cmd,
680 int ret; 681 int ret;
681 682
682 minor = iminor(file->f_path.dentry->d_inode); 683 minor = iminor(file->f_path.dentry->d_inode);
683 lock_kernel(); 684 mutex_lock(&lp_mutex);
684 switch (cmd) { 685 switch (cmd) {
685 case LPSETTIMEOUT: 686 case LPSETTIMEOUT:
686 if (copy_from_user(&par_timeout, (void __user *)arg, 687 if (copy_from_user(&par_timeout, (void __user *)arg,
@@ -694,7 +695,7 @@ static long lp_ioctl(struct file *file, unsigned int cmd,
694 ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg); 695 ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg);
695 break; 696 break;
696 } 697 }
697 unlock_kernel(); 698 mutex_unlock(&lp_mutex);
698 699
699 return ret; 700 return ret;
700} 701}
@@ -709,7 +710,7 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd,
709 int ret; 710 int ret;
710 711
711 minor = iminor(file->f_path.dentry->d_inode); 712 minor = iminor(file->f_path.dentry->d_inode);
712 lock_kernel(); 713 mutex_lock(&lp_mutex);
713 switch (cmd) { 714 switch (cmd) {
714 case LPSETTIMEOUT: 715 case LPSETTIMEOUT:
715 tc = compat_ptr(arg); 716 tc = compat_ptr(arg);
@@ -730,7 +731,7 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd,
730 ret = lp_do_ioctl(minor, cmd, arg, compat_ptr(arg)); 731 ret = lp_do_ioctl(minor, cmd, arg, compat_ptr(arg));
731 break; 732 break;
732 } 733 }
733 unlock_kernel(); 734 mutex_unlock(&lp_mutex);
734 735
735 return ret; 736 return ret;
736} 737}
diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
index 83bef4efe376..1aeaaba680d2 100644
--- a/drivers/char/mbcs.c
+++ b/drivers/char/mbcs.c
@@ -25,7 +25,6 @@
25#include <linux/mm.h> 25#include <linux/mm.h>
26#include <linux/uio.h> 26#include <linux/uio.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/smp_lock.h>
29#include <linux/slab.h> 28#include <linux/slab.h>
30#include <asm/io.h> 29#include <asm/io.h>
31#include <asm/uaccess.h> 30#include <asm/uaccess.h>
@@ -42,6 +41,7 @@
42#else 41#else
43#define DBG(fmt...) 42#define DBG(fmt...)
44#endif 43#endif
44static DEFINE_MUTEX(mbcs_mutex);
45static int mbcs_major; 45static int mbcs_major;
46 46
47static LIST_HEAD(soft_list); 47static LIST_HEAD(soft_list);
@@ -385,19 +385,19 @@ static int mbcs_open(struct inode *ip, struct file *fp)
385 struct mbcs_soft *soft; 385 struct mbcs_soft *soft;
386 int minor; 386 int minor;
387 387
388 lock_kernel(); 388 mutex_lock(&mbcs_mutex);
389 minor = iminor(ip); 389 minor = iminor(ip);
390 390
391 /* Nothing protects access to this list... */ 391 /* Nothing protects access to this list... */
392 list_for_each_entry(soft, &soft_list, list) { 392 list_for_each_entry(soft, &soft_list, list) {
393 if (soft->nasid == minor) { 393 if (soft->nasid == minor) {
394 fp->private_data = soft->cxdev; 394 fp->private_data = soft->cxdev;
395 unlock_kernel(); 395 mutex_unlock(&mbcs_mutex);
396 return 0; 396 return 0;
397 } 397 }
398 } 398 }
399 399
400 unlock_kernel(); 400 mutex_unlock(&mbcs_mutex);
401 return -ENODEV; 401 return -ENODEV;
402} 402}
403 403
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index ea7c99fa978f..fe4697844ec1 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -32,7 +32,7 @@
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/time.h> 33#include <linux/time.h>
34#include <linux/math64.h> 34#include <linux/math64.h>
35#include <linux/smp_lock.h> 35#include <linux/mutex.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37 37
38#include <asm/uaccess.h> 38#include <asm/uaccess.h>
@@ -59,6 +59,7 @@ extern unsigned long sn_rtc_cycles_per_second;
59 59
60#define rtc_time() (*RTC_COUNTER_ADDR) 60#define rtc_time() (*RTC_COUNTER_ADDR)
61 61
62static DEFINE_MUTEX(mmtimer_mutex);
62static long mmtimer_ioctl(struct file *file, unsigned int cmd, 63static long mmtimer_ioctl(struct file *file, unsigned int cmd,
63 unsigned long arg); 64 unsigned long arg);
64static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma); 65static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma);
@@ -371,7 +372,7 @@ static long mmtimer_ioctl(struct file *file, unsigned int cmd,
371{ 372{
372 int ret = 0; 373 int ret = 0;
373 374
374 lock_kernel(); 375 mutex_lock(&mmtimer_mutex);
375 376
376 switch (cmd) { 377 switch (cmd) {
377 case MMTIMER_GETOFFSET: /* offset of the counter */ 378 case MMTIMER_GETOFFSET: /* offset of the counter */
@@ -414,7 +415,7 @@ static long mmtimer_ioctl(struct file *file, unsigned int cmd,
414 ret = -ENOTTY; 415 ret = -ENOTTY;
415 break; 416 break;
416 } 417 }
417 unlock_kernel(); 418 mutex_unlock(&mmtimer_mutex);
418 return ret; 419 return ret;
419} 420}
420 421
diff --git a/drivers/char/mwave/mwavedd.c b/drivers/char/mwave/mwavedd.c
index a4ec50c95072..e5df26b56d59 100644
--- a/drivers/char/mwave/mwavedd.c
+++ b/drivers/char/mwave/mwavedd.c
@@ -56,7 +56,7 @@
56#include <linux/serial.h> 56#include <linux/serial.h>
57#include <linux/sched.h> 57#include <linux/sched.h>
58#include <linux/spinlock.h> 58#include <linux/spinlock.h>
59#include <linux/smp_lock.h> 59#include <linux/mutex.h>
60#include <linux/delay.h> 60#include <linux/delay.h>
61#include <linux/serial_8250.h> 61#include <linux/serial_8250.h>
62#include "smapi.h" 62#include "smapi.h"
@@ -73,6 +73,7 @@ MODULE_LICENSE("GPL");
73* checks are made against other devices (ie. superio) for conflicts. 73* checks are made against other devices (ie. superio) for conflicts.
74* We'll depend on users using the tpctl utility to do that for now 74* We'll depend on users using the tpctl utility to do that for now
75*/ 75*/
76static DEFINE_MUTEX(mwave_mutex);
76int mwave_debug = 0; 77int mwave_debug = 0;
77int mwave_3780i_irq = 0; 78int mwave_3780i_irq = 0;
78int mwave_3780i_io = 0; 79int mwave_3780i_io = 0;
@@ -101,7 +102,6 @@ static int mwave_open(struct inode *inode, struct file *file)
101 PRINTK_2(TRACE_MWAVE, 102 PRINTK_2(TRACE_MWAVE,
102 "mwavedd::mwave_open, exit return retval %x\n", retval); 103 "mwavedd::mwave_open, exit return retval %x\n", retval);
103 104
104 cycle_kernel_lock();
105 return retval; 105 return retval;
106} 106}
107 107
@@ -136,9 +136,9 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
136 PRINTK_1(TRACE_MWAVE, 136 PRINTK_1(TRACE_MWAVE,
137 "mwavedd::mwave_ioctl, IOCTL_MW_RESET" 137 "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
138 " calling tp3780I_ResetDSP\n"); 138 " calling tp3780I_ResetDSP\n");
139 lock_kernel(); 139 mutex_lock(&mwave_mutex);
140 retval = tp3780I_ResetDSP(&pDrvData->rBDData); 140 retval = tp3780I_ResetDSP(&pDrvData->rBDData);
141 unlock_kernel(); 141 mutex_unlock(&mwave_mutex);
142 PRINTK_2(TRACE_MWAVE, 142 PRINTK_2(TRACE_MWAVE,
143 "mwavedd::mwave_ioctl, IOCTL_MW_RESET" 143 "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
144 " retval %x from tp3780I_ResetDSP\n", 144 " retval %x from tp3780I_ResetDSP\n",
@@ -149,9 +149,9 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
149 PRINTK_1(TRACE_MWAVE, 149 PRINTK_1(TRACE_MWAVE,
150 "mwavedd::mwave_ioctl, IOCTL_MW_RUN" 150 "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
151 " calling tp3780I_StartDSP\n"); 151 " calling tp3780I_StartDSP\n");
152 lock_kernel(); 152 mutex_lock(&mwave_mutex);
153 retval = tp3780I_StartDSP(&pDrvData->rBDData); 153 retval = tp3780I_StartDSP(&pDrvData->rBDData);
154 unlock_kernel(); 154 mutex_unlock(&mwave_mutex);
155 PRINTK_2(TRACE_MWAVE, 155 PRINTK_2(TRACE_MWAVE,
156 "mwavedd::mwave_ioctl, IOCTL_MW_RUN" 156 "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
157 " retval %x from tp3780I_StartDSP\n", 157 " retval %x from tp3780I_StartDSP\n",
@@ -165,10 +165,10 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
165 "mwavedd::mwave_ioctl," 165 "mwavedd::mwave_ioctl,"
166 " IOCTL_MW_DSP_ABILITIES calling" 166 " IOCTL_MW_DSP_ABILITIES calling"
167 " tp3780I_QueryAbilities\n"); 167 " tp3780I_QueryAbilities\n");
168 lock_kernel(); 168 mutex_lock(&mwave_mutex);
169 retval = tp3780I_QueryAbilities(&pDrvData->rBDData, 169 retval = tp3780I_QueryAbilities(&pDrvData->rBDData,
170 &rAbilities); 170 &rAbilities);
171 unlock_kernel(); 171 mutex_unlock(&mwave_mutex);
172 PRINTK_2(TRACE_MWAVE, 172 PRINTK_2(TRACE_MWAVE,
173 "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES" 173 "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES"
174 " retval %x from tp3780I_QueryAbilities\n", 174 " retval %x from tp3780I_QueryAbilities\n",
@@ -199,13 +199,13 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
199 "mwavedd::mwave_ioctl IOCTL_MW_READ_DATA," 199 "mwavedd::mwave_ioctl IOCTL_MW_READ_DATA,"
200 " size %lx, ioarg %lx pusBuffer %p\n", 200 " size %lx, ioarg %lx pusBuffer %p\n",
201 rReadData.ulDataLength, ioarg, pusBuffer); 201 rReadData.ulDataLength, ioarg, pusBuffer);
202 lock_kernel(); 202 mutex_lock(&mwave_mutex);
203 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 203 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
204 iocmd, 204 iocmd,
205 pusBuffer, 205 pusBuffer,
206 rReadData.ulDataLength, 206 rReadData.ulDataLength,
207 rReadData.usDspAddress); 207 rReadData.usDspAddress);
208 unlock_kernel(); 208 mutex_unlock(&mwave_mutex);
209 } 209 }
210 break; 210 break;
211 211
@@ -223,12 +223,12 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
223 " size %lx, ioarg %lx pusBuffer %p\n", 223 " size %lx, ioarg %lx pusBuffer %p\n",
224 rReadData.ulDataLength / 2, ioarg, 224 rReadData.ulDataLength / 2, ioarg,
225 pusBuffer); 225 pusBuffer);
226 lock_kernel(); 226 mutex_lock(&mwave_mutex);
227 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 227 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
228 iocmd, pusBuffer, 228 iocmd, pusBuffer,
229 rReadData.ulDataLength / 2, 229 rReadData.ulDataLength / 2,
230 rReadData.usDspAddress); 230 rReadData.usDspAddress);
231 unlock_kernel(); 231 mutex_unlock(&mwave_mutex);
232 } 232 }
233 break; 233 break;
234 234
@@ -246,12 +246,12 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
246 " size %lx, ioarg %lx pusBuffer %p\n", 246 " size %lx, ioarg %lx pusBuffer %p\n",
247 rWriteData.ulDataLength, ioarg, 247 rWriteData.ulDataLength, ioarg,
248 pusBuffer); 248 pusBuffer);
249 lock_kernel(); 249 mutex_lock(&mwave_mutex);
250 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 250 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
251 iocmd, pusBuffer, 251 iocmd, pusBuffer,
252 rWriteData.ulDataLength, 252 rWriteData.ulDataLength,
253 rWriteData.usDspAddress); 253 rWriteData.usDspAddress);
254 unlock_kernel(); 254 mutex_unlock(&mwave_mutex);
255 } 255 }
256 break; 256 break;
257 257
@@ -269,12 +269,12 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
269 " size %lx, ioarg %lx pusBuffer %p\n", 269 " size %lx, ioarg %lx pusBuffer %p\n",
270 rWriteData.ulDataLength, ioarg, 270 rWriteData.ulDataLength, ioarg,
271 pusBuffer); 271 pusBuffer);
272 lock_kernel(); 272 mutex_lock(&mwave_mutex);
273 retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData, 273 retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData,
274 iocmd, pusBuffer, 274 iocmd, pusBuffer,
275 rWriteData.ulDataLength, 275 rWriteData.ulDataLength,
276 rWriteData.usDspAddress); 276 rWriteData.usDspAddress);
277 unlock_kernel(); 277 mutex_unlock(&mwave_mutex);
278 } 278 }
279 break; 279 break;
280 280
@@ -295,10 +295,10 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
295 ipcnum, 295 ipcnum,
296 pDrvData->IPCs[ipcnum].usIntCount); 296 pDrvData->IPCs[ipcnum].usIntCount);
297 297
298 lock_kernel(); 298 mutex_lock(&mwave_mutex);
299 pDrvData->IPCs[ipcnum].bIsHere = FALSE; 299 pDrvData->IPCs[ipcnum].bIsHere = FALSE;
300 pDrvData->IPCs[ipcnum].bIsEnabled = TRUE; 300 pDrvData->IPCs[ipcnum].bIsEnabled = TRUE;
301 unlock_kernel(); 301 mutex_unlock(&mwave_mutex);
302 302
303 PRINTK_2(TRACE_MWAVE, 303 PRINTK_2(TRACE_MWAVE,
304 "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC" 304 "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC"
@@ -323,7 +323,7 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
323 ipcnum, 323 ipcnum,
324 pDrvData->IPCs[ipcnum].usIntCount); 324 pDrvData->IPCs[ipcnum].usIntCount);
325 325
326 lock_kernel(); 326 mutex_lock(&mwave_mutex);
327 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) { 327 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
328 DECLARE_WAITQUEUE(wait, current); 328 DECLARE_WAITQUEUE(wait, current);
329 329
@@ -364,7 +364,7 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
364 " processing\n", 364 " processing\n",
365 ipcnum); 365 ipcnum);
366 } 366 }
367 unlock_kernel(); 367 mutex_unlock(&mwave_mutex);
368 } 368 }
369 break; 369 break;
370 370
@@ -383,14 +383,14 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
383 ipcnum); 383 ipcnum);
384 return -EINVAL; 384 return -EINVAL;
385 } 385 }
386 lock_kernel(); 386 mutex_lock(&mwave_mutex);
387 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) { 387 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
388 pDrvData->IPCs[ipcnum].bIsEnabled = FALSE; 388 pDrvData->IPCs[ipcnum].bIsEnabled = FALSE;
389 if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) { 389 if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) {
390 wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue); 390 wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue);
391 } 391 }
392 } 392 }
393 unlock_kernel(); 393 mutex_unlock(&mwave_mutex);
394 } 394 }
395 break; 395 break;
396 396
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 66d2917b003f..166f1e7aaa7e 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -109,10 +109,11 @@
109#include <linux/spinlock.h> 109#include <linux/spinlock.h>
110#include <linux/io.h> 110#include <linux/io.h>
111#include <linux/uaccess.h> 111#include <linux/uaccess.h>
112#include <linux/smp_lock.h> 112#include <linux/mutex.h>
113 113
114#include <asm/system.h> 114#include <asm/system.h>
115 115
116static DEFINE_MUTEX(nvram_mutex);
116static DEFINE_SPINLOCK(nvram_state_lock); 117static DEFINE_SPINLOCK(nvram_state_lock);
117static int nvram_open_cnt; /* #times opened */ 118static int nvram_open_cnt; /* #times opened */
118static int nvram_open_mode; /* special open modes */ 119static int nvram_open_mode; /* special open modes */
@@ -308,7 +309,7 @@ static long nvram_ioctl(struct file *file, unsigned int cmd,
308 if (!capable(CAP_SYS_ADMIN)) 309 if (!capable(CAP_SYS_ADMIN))
309 return -EACCES; 310 return -EACCES;
310 311
311 lock_kernel(); 312 mutex_lock(&nvram_mutex);
312 spin_lock_irq(&rtc_lock); 313 spin_lock_irq(&rtc_lock);
313 314
314 for (i = 0; i < NVRAM_BYTES; ++i) 315 for (i = 0; i < NVRAM_BYTES; ++i)
@@ -316,7 +317,7 @@ static long nvram_ioctl(struct file *file, unsigned int cmd,
316 __nvram_set_checksum(); 317 __nvram_set_checksum();
317 318
318 spin_unlock_irq(&rtc_lock); 319 spin_unlock_irq(&rtc_lock);
319 unlock_kernel(); 320 mutex_unlock(&nvram_mutex);
320 return 0; 321 return 0;
321 322
322 case NVRAM_SETCKS: 323 case NVRAM_SETCKS:
@@ -325,11 +326,11 @@ static long nvram_ioctl(struct file *file, unsigned int cmd,
325 if (!capable(CAP_SYS_ADMIN)) 326 if (!capable(CAP_SYS_ADMIN))
326 return -EACCES; 327 return -EACCES;
327 328
328 lock_kernel(); 329 mutex_lock(&nvram_mutex);
329 spin_lock_irq(&rtc_lock); 330 spin_lock_irq(&rtc_lock);
330 __nvram_set_checksum(); 331 __nvram_set_checksum();
331 spin_unlock_irq(&rtc_lock); 332 spin_unlock_irq(&rtc_lock);
332 unlock_kernel(); 333 mutex_unlock(&nvram_mutex);
333 return 0; 334 return 0;
334 335
335 default: 336 default:
diff --git a/drivers/char/nwflash.c b/drivers/char/nwflash.c
index 043a1c7b86be..a12f52400dbc 100644
--- a/drivers/char/nwflash.c
+++ b/drivers/char/nwflash.c
@@ -25,7 +25,6 @@
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <linux/rwsem.h> 26#include <linux/rwsem.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/smp_lock.h>
29#include <linux/mutex.h> 28#include <linux/mutex.h>
30#include <linux/jiffies.h> 29#include <linux/jiffies.h>
31 30
@@ -41,6 +40,7 @@
41 40
42#define NWFLASH_VERSION "6.4" 41#define NWFLASH_VERSION "6.4"
43 42
43static DEFINE_MUTEX(flash_mutex);
44static void kick_open(void); 44static void kick_open(void);
45static int get_flash_id(void); 45static int get_flash_id(void);
46static int erase_block(int nBlock); 46static int erase_block(int nBlock);
@@ -96,7 +96,7 @@ static int get_flash_id(void)
96 96
97static long flash_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) 97static long flash_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
98{ 98{
99 lock_kernel(); 99 mutex_lock(&flash_mutex);
100 switch (cmd) { 100 switch (cmd) {
101 case CMD_WRITE_DISABLE: 101 case CMD_WRITE_DISABLE:
102 gbWriteBase64Enable = 0; 102 gbWriteBase64Enable = 0;
@@ -114,10 +114,10 @@ static long flash_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
114 default: 114 default:
115 gbWriteBase64Enable = 0; 115 gbWriteBase64Enable = 0;
116 gbWriteEnable = 0; 116 gbWriteEnable = 0;
117 unlock_kernel(); 117 mutex_unlock(&flash_mutex);
118 return -EINVAL; 118 return -EINVAL;
119 } 119 }
120 unlock_kernel(); 120 mutex_unlock(&flash_mutex);
121 return 0; 121 return 0;
122} 122}
123 123
@@ -282,7 +282,7 @@ static loff_t flash_llseek(struct file *file, loff_t offset, int orig)
282{ 282{
283 loff_t ret; 283 loff_t ret;
284 284
285 lock_kernel(); 285 mutex_lock(&flash_mutex);
286 if (flashdebug) 286 if (flashdebug)
287 printk(KERN_DEBUG "flash_llseek: offset=0x%X, orig=0x%X.\n", 287 printk(KERN_DEBUG "flash_llseek: offset=0x%X, orig=0x%X.\n",
288 (unsigned int) offset, orig); 288 (unsigned int) offset, orig);
@@ -317,7 +317,7 @@ static loff_t flash_llseek(struct file *file, loff_t offset, int orig)
317 default: 317 default:
318 ret = -EINVAL; 318 ret = -EINVAL;
319 } 319 }
320 unlock_kernel(); 320 mutex_unlock(&flash_mutex);
321 return ret; 321 return ret;
322} 322}
323 323
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index c7b482d15e2a..c4e52ec85c6e 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -30,7 +30,7 @@
30#include <linux/fs.h> 30#include <linux/fs.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/bitrev.h> 32#include <linux/bitrev.h>
33#include <linux/smp_lock.h> 33#include <linux/mutex.h>
34#include <linux/uaccess.h> 34#include <linux/uaccess.h>
35#include <linux/io.h> 35#include <linux/io.h>
36 36
@@ -54,6 +54,8 @@
54 __func__ , ## args); \ 54 __func__ , ## args); \
55 } while (0) 55 } while (0)
56 56
57static DEFINE_MUTEX(cmm_mutex);
58
57#define T_1SEC (HZ) 59#define T_1SEC (HZ)
58#define T_10MSEC msecs_to_jiffies(10) 60#define T_10MSEC msecs_to_jiffies(10)
59#define T_20MSEC msecs_to_jiffies(20) 61#define T_20MSEC msecs_to_jiffies(20)
@@ -1415,7 +1417,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1415 iminor(inode), ioctl_names[_IOC_NR(cmd)]); 1417 iminor(inode), ioctl_names[_IOC_NR(cmd)]);
1416#endif 1418#endif
1417 1419
1418 lock_kernel(); 1420 mutex_lock(&cmm_mutex);
1419 rc = -ENODEV; 1421 rc = -ENODEV;
1420 link = dev_table[iminor(inode)]; 1422 link = dev_table[iminor(inode)];
1421 if (!pcmcia_dev_present(link)) { 1423 if (!pcmcia_dev_present(link)) {
@@ -1623,7 +1625,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1623 rc = -ENOTTY; 1625 rc = -ENOTTY;
1624 } 1626 }
1625out: 1627out:
1626 unlock_kernel(); 1628 mutex_unlock(&cmm_mutex);
1627 return rc; 1629 return rc;
1628} 1630}
1629 1631
@@ -1637,7 +1639,7 @@ static int cmm_open(struct inode *inode, struct file *filp)
1637 if (minor >= CM4000_MAX_DEV) 1639 if (minor >= CM4000_MAX_DEV)
1638 return -ENODEV; 1640 return -ENODEV;
1639 1641
1640 lock_kernel(); 1642 mutex_lock(&cmm_mutex);
1641 link = dev_table[minor]; 1643 link = dev_table[minor];
1642 if (link == NULL || !pcmcia_dev_present(link)) { 1644 if (link == NULL || !pcmcia_dev_present(link)) {
1643 ret = -ENODEV; 1645 ret = -ENODEV;
@@ -1682,7 +1684,7 @@ static int cmm_open(struct inode *inode, struct file *filp)
1682 DEBUGP(2, dev, "<- cmm_open\n"); 1684 DEBUGP(2, dev, "<- cmm_open\n");
1683 ret = nonseekable_open(inode, filp); 1685 ret = nonseekable_open(inode, filp);
1684out: 1686out:
1685 unlock_kernel(); 1687 mutex_unlock(&cmm_mutex);
1686 return ret; 1688 return ret;
1687} 1689}
1688 1690
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index bf2f046fc2c1..d7c32cb40ca3 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -24,7 +24,7 @@
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/poll.h> 26#include <linux/poll.h>
27#include <linux/smp_lock.h> 27#include <linux/mutex.h>
28#include <linux/wait.h> 28#include <linux/wait.h>
29#include <asm/uaccess.h> 29#include <asm/uaccess.h>
30#include <asm/io.h> 30#include <asm/io.h>
@@ -48,6 +48,8 @@
48 __func__ , ## args); \ 48 __func__ , ## args); \
49 } while (0) 49 } while (0)
50 50
51static DEFINE_MUTEX(cm4040_mutex);
52
51#define CCID_DRIVER_BULK_DEFAULT_TIMEOUT (150*HZ) 53#define CCID_DRIVER_BULK_DEFAULT_TIMEOUT (150*HZ)
52#define CCID_DRIVER_ASYNC_POWERUP_TIMEOUT (35*HZ) 54#define CCID_DRIVER_ASYNC_POWERUP_TIMEOUT (35*HZ)
53#define CCID_DRIVER_MINIMUM_TIMEOUT (3*HZ) 55#define CCID_DRIVER_MINIMUM_TIMEOUT (3*HZ)
@@ -440,7 +442,7 @@ static int cm4040_open(struct inode *inode, struct file *filp)
440 if (minor >= CM_MAX_DEV) 442 if (minor >= CM_MAX_DEV)
441 return -ENODEV; 443 return -ENODEV;
442 444
443 lock_kernel(); 445 mutex_lock(&cm4040_mutex);
444 link = dev_table[minor]; 446 link = dev_table[minor];
445 if (link == NULL || !pcmcia_dev_present(link)) { 447 if (link == NULL || !pcmcia_dev_present(link)) {
446 ret = -ENODEV; 448 ret = -ENODEV;
@@ -469,7 +471,7 @@ static int cm4040_open(struct inode *inode, struct file *filp)
469 DEBUGP(2, dev, "<- cm4040_open (successfully)\n"); 471 DEBUGP(2, dev, "<- cm4040_open (successfully)\n");
470 ret = nonseekable_open(inode, filp); 472 ret = nonseekable_open(inode, filp);
471out: 473out:
472 unlock_kernel(); 474 mutex_unlock(&cm4040_mutex);
473 return ret; 475 return ret;
474} 476}
475 477
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 02abfddce45a..723152d978a9 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -67,7 +67,7 @@
67#include <linux/slab.h> 67#include <linux/slab.h>
68#include <linux/major.h> 68#include <linux/major.h>
69#include <linux/ppdev.h> 69#include <linux/ppdev.h>
70#include <linux/smp_lock.h> 70#include <linux/mutex.h>
71#include <linux/uaccess.h> 71#include <linux/uaccess.h>
72 72
73#define PP_VERSION "ppdev: user-space parallel port driver" 73#define PP_VERSION "ppdev: user-space parallel port driver"
@@ -97,6 +97,7 @@ struct pp_struct {
97/* ROUND_UP macro from fs/select.c */ 97/* ROUND_UP macro from fs/select.c */
98#define ROUND_UP(x,y) (((x)+(y)-1)/(y)) 98#define ROUND_UP(x,y) (((x)+(y)-1)/(y))
99 99
100static DEFINE_MUTEX(pp_do_mutex);
100static inline void pp_enable_irq (struct pp_struct *pp) 101static inline void pp_enable_irq (struct pp_struct *pp)
101{ 102{
102 struct parport *port = pp->pdev->port; 103 struct parport *port = pp->pdev->port;
@@ -630,9 +631,9 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
630static long pp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 631static long pp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
631{ 632{
632 long ret; 633 long ret;
633 lock_kernel(); 634 mutex_lock(&pp_do_mutex);
634 ret = pp_do_ioctl(file, cmd, arg); 635 ret = pp_do_ioctl(file, cmd, arg);
635 unlock_kernel(); 636 mutex_unlock(&pp_do_mutex);
636 return ret; 637 return ret;
637} 638}
638 639
@@ -641,7 +642,6 @@ static int pp_open (struct inode * inode, struct file * file)
641 unsigned int minor = iminor(inode); 642 unsigned int minor = iminor(inode);
642 struct pp_struct *pp; 643 struct pp_struct *pp;
643 644
644 cycle_kernel_lock();
645 if (minor >= PARPORT_MAX) 645 if (minor >= PARPORT_MAX)
646 return -ENXIO; 646 return -ENXIO;
647 647
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index d58c2eb07f07..e06a5977fdb2 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -44,7 +44,7 @@
44#include <linux/delay.h> 44#include <linux/delay.h>
45#include <linux/pci.h> 45#include <linux/pci.h>
46#include <linux/slab.h> 46#include <linux/slab.h>
47#include <linux/smp_lock.h> 47#include <linux/mutex.h>
48#include <linux/miscdevice.h> 48#include <linux/miscdevice.h>
49#include <linux/init.h> 49#include <linux/init.h>
50 50
@@ -122,6 +122,7 @@ more than 512 ports.... */
122 122
123 123
124/* These constants are derived from SCO Source */ 124/* These constants are derived from SCO Source */
125static DEFINE_MUTEX(rio_fw_mutex);
125static struct Conf 126static struct Conf
126 RIOConf = { 127 RIOConf = {
127 /* locator */ "RIO Config here", 128 /* locator */ "RIO Config here",
@@ -566,9 +567,9 @@ static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
566 func_enter(); 567 func_enter();
567 568
568 /* The "dev" argument isn't used. */ 569 /* The "dev" argument isn't used. */
569 lock_kernel(); 570 mutex_lock(&rio_fw_mutex);
570 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN)); 571 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
571 unlock_kernel(); 572 mutex_unlock(&rio_fw_mutex);
572 573
573 func_exit(); 574 func_exit();
574 return rc; 575 return rc;
diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index 32b74de18f5f..208e25731dfe 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -21,7 +21,7 @@
21#include <linux/poll.h> 21#include <linux/poll.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/smp_lock.h> 24#include <linux/mutex.h>
25#include <asm/sn/io.h> 25#include <asm/sn/io.h>
26#include <asm/sn/sn_sal.h> 26#include <asm/sn/sn_sal.h>
27#include <asm/sn/module.h> 27#include <asm/sn/module.h>
@@ -34,6 +34,7 @@
34#define SCDRV_BUFSZ 2048 34#define SCDRV_BUFSZ 2048
35#define SCDRV_TIMEOUT 1000 35#define SCDRV_TIMEOUT 1000
36 36
37static DEFINE_MUTEX(scdrv_mutex);
37static irqreturn_t 38static irqreturn_t
38scdrv_interrupt(int irq, void *subch_data) 39scdrv_interrupt(int irq, void *subch_data)
39{ 40{
@@ -105,7 +106,7 @@ scdrv_open(struct inode *inode, struct file *file)
105 file->private_data = sd; 106 file->private_data = sd;
106 107
107 /* hook this subchannel up to the system controller interrupt */ 108 /* hook this subchannel up to the system controller interrupt */
108 lock_kernel(); 109 mutex_lock(&scdrv_mutex);
109 rv = request_irq(SGI_UART_VECTOR, scdrv_interrupt, 110 rv = request_irq(SGI_UART_VECTOR, scdrv_interrupt,
110 IRQF_SHARED | IRQF_DISABLED, 111 IRQF_SHARED | IRQF_DISABLED,
111 SYSCTL_BASENAME, sd); 112 SYSCTL_BASENAME, sd);
@@ -113,10 +114,10 @@ scdrv_open(struct inode *inode, struct file *file)
113 ia64_sn_irtr_close(sd->sd_nasid, sd->sd_subch); 114 ia64_sn_irtr_close(sd->sd_nasid, sd->sd_subch);
114 kfree(sd); 115 kfree(sd);
115 printk("%s: irq request failed (%d)\n", __func__, rv); 116 printk("%s: irq request failed (%d)\n", __func__, rv);
116 unlock_kernel(); 117 mutex_unlock(&scdrv_mutex);
117 return -EBUSY; 118 return -EBUSY;
118 } 119 }
119 unlock_kernel(); 120 mutex_unlock(&scdrv_mutex);
120 return 0; 121 return 0;
121} 122}
122 123
diff --git a/drivers/char/toshiba.c b/drivers/char/toshiba.c
index f8bc79f6de34..f8f09ab0b170 100644
--- a/drivers/char/toshiba.c
+++ b/drivers/char/toshiba.c
@@ -68,7 +68,7 @@
68#include <linux/stat.h> 68#include <linux/stat.h>
69#include <linux/proc_fs.h> 69#include <linux/proc_fs.h>
70#include <linux/seq_file.h> 70#include <linux/seq_file.h>
71#include <linux/smp_lock.h> 71#include <linux/mutex.h>
72#include <linux/toshiba.h> 72#include <linux/toshiba.h>
73 73
74#define TOSH_MINOR_DEV 181 74#define TOSH_MINOR_DEV 181
@@ -78,6 +78,7 @@ MODULE_AUTHOR("Jonathan Buzzard <jonathan@buzzard.org.uk>");
78MODULE_DESCRIPTION("Toshiba laptop SMM driver"); 78MODULE_DESCRIPTION("Toshiba laptop SMM driver");
79MODULE_SUPPORTED_DEVICE("toshiba"); 79MODULE_SUPPORTED_DEVICE("toshiba");
80 80
81static DEFINE_MUTEX(tosh_mutex);
81static int tosh_fn; 82static int tosh_fn;
82module_param_named(fn, tosh_fn, int, 0); 83module_param_named(fn, tosh_fn, int, 0);
83MODULE_PARM_DESC(fn, "User specified Fn key detection port"); 84MODULE_PARM_DESC(fn, "User specified Fn key detection port");
@@ -274,16 +275,16 @@ static long tosh_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
274 return -EINVAL; 275 return -EINVAL;
275 276
276 /* do we need to emulate the fan ? */ 277 /* do we need to emulate the fan ? */
277 lock_kernel(); 278 mutex_lock(&tosh_mutex);
278 if (tosh_fan==1) { 279 if (tosh_fan==1) {
279 if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) { 280 if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) {
280 err = tosh_emulate_fan(&regs); 281 err = tosh_emulate_fan(&regs);
281 unlock_kernel(); 282 mutex_unlock(&tosh_mutex);
282 break; 283 break;
283 } 284 }
284 } 285 }
285 err = tosh_smm(&regs); 286 err = tosh_smm(&regs);
286 unlock_kernel(); 287 mutex_unlock(&tosh_mutex);
287 break; 288 break;
288 default: 289 default:
289 return -EINVAL; 290 return -EINVAL;
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 42f7fa442ff8..6f954a808b65 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -46,7 +46,7 @@
46#include <linux/completion.h> 46#include <linux/completion.h>
47#include <linux/proc_fs.h> 47#include <linux/proc_fs.h>
48#include <linux/seq_file.h> 48#include <linux/seq_file.h>
49#include <linux/smp_lock.h> 49#include <linux/mutex.h>
50#include <linux/slab.h> 50#include <linux/slab.h>
51 51
52#include <asm/uaccess.h> 52#include <asm/uaccess.h>
@@ -64,6 +64,7 @@
64#define VIOTAPE_KERN_WARN KERN_WARNING "viotape: " 64#define VIOTAPE_KERN_WARN KERN_WARNING "viotape: "
65#define VIOTAPE_KERN_INFO KERN_INFO "viotape: " 65#define VIOTAPE_KERN_INFO KERN_INFO "viotape: "
66 66
67static DEFINE_MUTEX(proc_viotape_mutex);
67static int viotape_numdev; 68static int viotape_numdev;
68 69
69/* 70/*
@@ -684,9 +685,9 @@ static long viotap_unlocked_ioctl(struct file *file,
684{ 685{
685 long rc; 686 long rc;
686 687
687 lock_kernel(); 688 mutex_lock(&proc_viotape_mutex);
688 rc = viotap_ioctl(file->f_path.dentry->d_inode, file, cmd, arg); 689 rc = viotap_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
689 unlock_kernel(); 690 mutex_unlock(&proc_viotape_mutex);
690 return rc; 691 return rc;
691} 692}
692 693
@@ -700,7 +701,7 @@ static int viotap_open(struct inode *inode, struct file *file)
700 if (op == NULL) 701 if (op == NULL)
701 return -ENOMEM; 702 return -ENOMEM;
702 703
703 lock_kernel(); 704 mutex_lock(&proc_viotape_mutex);
704 get_dev_info(file->f_path.dentry->d_inode, &devi); 705 get_dev_info(file->f_path.dentry->d_inode, &devi);
705 706
706 /* Note: We currently only support one mode! */ 707 /* Note: We currently only support one mode! */
@@ -731,7 +732,7 @@ static int viotap_open(struct inode *inode, struct file *file)
731 732
732free_op: 733free_op:
733 free_op_struct(op); 734 free_op_struct(op);
734 unlock_kernel(); 735 mutex_unlock(&proc_viotape_mutex);
735 return ret; 736 return ret;
736} 737}
737 738
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index b663d573aad9..d985204d76fe 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -81,7 +81,6 @@
81#include <linux/poll.h> 81#include <linux/poll.h>
82#include <linux/proc_fs.h> 82#include <linux/proc_fs.h>
83#include <linux/mutex.h> 83#include <linux/mutex.h>
84#include <linux/smp_lock.h>
85#include <linux/sysctl.h> 84#include <linux/sysctl.h>
86#include <linux/fs.h> 85#include <linux/fs.h>
87#include <linux/cdev.h> 86#include <linux/cdev.h>
@@ -112,6 +111,7 @@
112#define HWICAP_DEVICES 1 111#define HWICAP_DEVICES 1
113 112
114/* An array, which is set to true when the device is registered. */ 113/* An array, which is set to true when the device is registered. */
114static DEFINE_MUTEX(hwicap_mutex);
115static bool probed_devices[HWICAP_DEVICES]; 115static bool probed_devices[HWICAP_DEVICES];
116static struct mutex icap_sem; 116static struct mutex icap_sem;
117 117
@@ -502,7 +502,7 @@ static int hwicap_open(struct inode *inode, struct file *file)
502 struct hwicap_drvdata *drvdata; 502 struct hwicap_drvdata *drvdata;
503 int status; 503 int status;
504 504
505 lock_kernel(); 505 mutex_lock(&hwicap_mutex);
506 drvdata = container_of(inode->i_cdev, struct hwicap_drvdata, cdev); 506 drvdata = container_of(inode->i_cdev, struct hwicap_drvdata, cdev);
507 507
508 status = mutex_lock_interruptible(&drvdata->sem); 508 status = mutex_lock_interruptible(&drvdata->sem);
@@ -528,7 +528,7 @@ static int hwicap_open(struct inode *inode, struct file *file)
528 error: 528 error:
529 mutex_unlock(&drvdata->sem); 529 mutex_unlock(&drvdata->sem);
530 out: 530 out:
531 unlock_kernel(); 531 mutex_unlock(&hwicap_mutex);
532 return status; 532 return status;
533} 533}
534 534
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index b7ca2a9676cf..d4d4ca65d371 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -38,7 +38,6 @@
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39#include <linux/hwmon.h> 39#include <linux/hwmon.h>
40#include <linux/hwmon-sysfs.h> 40#include <linux/hwmon-sysfs.h>
41#include <linux/smp_lock.h>
42#include <linux/err.h> 41#include <linux/err.h>
43#include <linux/mutex.h> 42#include <linux/mutex.h>
44#include <linux/sysfs.h> 43#include <linux/sysfs.h>
@@ -50,6 +49,7 @@
50#include <linux/kref.h> 49#include <linux/kref.h>
51 50
52/* Addresses to scan */ 51/* Addresses to scan */
52static DEFINE_MUTEX(watchdog_mutex);
53static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; 53static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
54 54
55/* Insmod parameters */ 55/* Insmod parameters */
@@ -858,7 +858,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long ar
858 int i, ret = 0; 858 int i, ret = 0;
859 struct fschmd_data *data = filp->private_data; 859 struct fschmd_data *data = filp->private_data;
860 860
861 lock_kernel(); 861 mutex_lock(&watchdog_mutex);
862 switch (cmd) { 862 switch (cmd) {
863 case WDIOC_GETSUPPORT: 863 case WDIOC_GETSUPPORT:
864 ident.firmware_version = data->revision; 864 ident.firmware_version = data->revision;
@@ -915,7 +915,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long ar
915 default: 915 default:
916 ret = -ENOTTY; 916 ret = -ENOTTY;
917 } 917 }
918 unlock_kernel(); 918 mutex_unlock(&watchdog_mutex);
919 return ret; 919 return ret;
920} 920}
921 921
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 697202e27891..8e540ada47d2 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -35,7 +35,6 @@
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/hwmon.h> 37#include <linux/hwmon.h>
38#include <linux/smp_lock.h>
39#include <linux/hwmon-vid.h> 38#include <linux/hwmon-vid.h>
40#include <linux/hwmon-sysfs.h> 39#include <linux/hwmon-sysfs.h>
41#include <linux/err.h> 40#include <linux/err.h>
@@ -52,6 +51,7 @@
52#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */ 51#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */
53 52
54/* Addresses to scan */ 53/* Addresses to scan */
54static DEFINE_MUTEX(watchdog_mutex);
55static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 55static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
56 I2C_CLIENT_END }; 56 I2C_CLIENT_END };
57 57
@@ -1333,7 +1333,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1333 int val, ret = 0; 1333 int val, ret = 0;
1334 struct w83793_data *data = filp->private_data; 1334 struct w83793_data *data = filp->private_data;
1335 1335
1336 lock_kernel(); 1336 mutex_lock(&watchdog_mutex);
1337 switch (cmd) { 1337 switch (cmd) {
1338 case WDIOC_GETSUPPORT: 1338 case WDIOC_GETSUPPORT:
1339 if (!nowayout) 1339 if (!nowayout)
@@ -1387,7 +1387,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1387 default: 1387 default:
1388 ret = -ENOTTY; 1388 ret = -ENOTTY;
1389 } 1389 }
1390 unlock_kernel(); 1390 mutex_unlock(&watchdog_mutex);
1391 return ret; 1391 return ret;
1392} 1392}
1393 1393
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 31fc76960a8f..0c73fe39a236 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -31,7 +31,6 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/timer.h> 32#include <linux/timer.h>
33#include <linux/seq_file.h> 33#include <linux/seq_file.h>
34#include <linux/smp_lock.h>
35#include <linux/slab.h> 34#include <linux/slab.h>
36#include <linux/interrupt.h> 35#include <linux/interrupt.h>
37#include <linux/errno.h> 36#include <linux/errno.h>
@@ -52,6 +51,7 @@
52 51
53#include "ide-cd.h" 52#include "ide-cd.h"
54 53
54static DEFINE_MUTEX(ide_cd_mutex);
55static DEFINE_MUTEX(idecd_ref_mutex); 55static DEFINE_MUTEX(idecd_ref_mutex);
56 56
57static void ide_cd_release(struct device *); 57static void ide_cd_release(struct device *);
@@ -1602,7 +1602,7 @@ static int idecd_open(struct block_device *bdev, fmode_t mode)
1602 struct cdrom_info *info; 1602 struct cdrom_info *info;
1603 int rc = -ENXIO; 1603 int rc = -ENXIO;
1604 1604
1605 lock_kernel(); 1605 mutex_lock(&ide_cd_mutex);
1606 info = ide_cd_get(bdev->bd_disk); 1606 info = ide_cd_get(bdev->bd_disk);
1607 if (!info) 1607 if (!info)
1608 goto out; 1608 goto out;
@@ -1611,7 +1611,7 @@ static int idecd_open(struct block_device *bdev, fmode_t mode)
1611 if (rc < 0) 1611 if (rc < 0)
1612 ide_cd_put(info); 1612 ide_cd_put(info);
1613out: 1613out:
1614 unlock_kernel(); 1614 mutex_unlock(&ide_cd_mutex);
1615 return rc; 1615 return rc;
1616} 1616}
1617 1617
@@ -1619,11 +1619,11 @@ static int idecd_release(struct gendisk *disk, fmode_t mode)
1619{ 1619{
1620 struct cdrom_info *info = ide_drv_g(disk, cdrom_info); 1620 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
1621 1621
1622 lock_kernel(); 1622 mutex_lock(&ide_cd_mutex);
1623 cdrom_release(&info->devinfo, mode); 1623 cdrom_release(&info->devinfo, mode);
1624 1624
1625 ide_cd_put(info); 1625 ide_cd_put(info);
1626 unlock_kernel(); 1626 mutex_unlock(&ide_cd_mutex);
1627 1627
1628 return 0; 1628 return 0;
1629} 1629}
@@ -1694,9 +1694,9 @@ static int idecd_ioctl(struct block_device *bdev, fmode_t mode,
1694{ 1694{
1695 int ret; 1695 int ret;
1696 1696
1697 lock_kernel(); 1697 mutex_lock(&ide_cd_mutex);
1698 ret = idecd_locked_ioctl(bdev, mode, cmd, arg); 1698 ret = idecd_locked_ioctl(bdev, mode, cmd, arg);
1699 unlock_kernel(); 1699 mutex_unlock(&ide_cd_mutex);
1700 1700
1701 return ret; 1701 return ret;
1702} 1702}
diff --git a/drivers/ide/ide-disk_ioctl.c b/drivers/ide/ide-disk_ioctl.c
index ec94c66918f6..da36f729ff32 100644
--- a/drivers/ide/ide-disk_ioctl.c
+++ b/drivers/ide/ide-disk_ioctl.c
@@ -1,10 +1,11 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/ide.h> 2#include <linux/ide.h>
3#include <linux/hdreg.h> 3#include <linux/hdreg.h>
4#include <linux/smp_lock.h> 4#include <linux/mutex.h>
5 5
6#include "ide-disk.h" 6#include "ide-disk.h"
7 7
8static DEFINE_MUTEX(ide_disk_ioctl_mutex);
8static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = { 9static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
9{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address }, 10{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address },
10{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount }, 11{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount },
@@ -19,13 +20,13 @@ int ide_disk_ioctl(ide_drive_t *drive, struct block_device *bdev, fmode_t mode,
19{ 20{
20 int err; 21 int err;
21 22
22 lock_kernel(); 23 mutex_lock(&ide_disk_ioctl_mutex);
23 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings); 24 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
24 if (err != -EOPNOTSUPP) 25 if (err != -EOPNOTSUPP)
25 goto out; 26 goto out;
26 27
27 err = generic_ide_ioctl(drive, bdev, cmd, arg); 28 err = generic_ide_ioctl(drive, bdev, cmd, arg);
28out: 29out:
29 unlock_kernel(); 30 mutex_unlock(&ide_disk_ioctl_mutex);
30 return err; 31 return err;
31} 32}
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
index fd3d05ab3417..d267b7affad6 100644
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -5,7 +5,7 @@
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/ide.h> 6#include <linux/ide.h>
7#include <linux/cdrom.h> 7#include <linux/cdrom.h>
8#include <linux/smp_lock.h> 8#include <linux/mutex.h>
9 9
10#include <asm/unaligned.h> 10#include <asm/unaligned.h>
11 11
@@ -32,6 +32,7 @@
32 * On exit we set nformats to the number of records we've actually initialized. 32 * On exit we set nformats to the number of records we've actually initialized.
33 */ 33 */
34 34
35static DEFINE_MUTEX(ide_floppy_ioctl_mutex);
35static int ide_floppy_get_format_capacities(ide_drive_t *drive, 36static int ide_floppy_get_format_capacities(ide_drive_t *drive,
36 struct ide_atapi_pc *pc, 37 struct ide_atapi_pc *pc,
37 int __user *arg) 38 int __user *arg)
@@ -276,7 +277,7 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
276 void __user *argp = (void __user *)arg; 277 void __user *argp = (void __user *)arg;
277 int err; 278 int err;
278 279
279 lock_kernel(); 280 mutex_lock(&ide_floppy_ioctl_mutex);
280 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) { 281 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) {
281 err = ide_floppy_lockdoor(drive, &pc, arg, cmd); 282 err = ide_floppy_lockdoor(drive, &pc, arg, cmd);
282 goto out; 283 goto out;
@@ -298,6 +299,6 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
298 err = generic_ide_ioctl(drive, bdev, cmd, arg); 299 err = generic_ide_ioctl(drive, bdev, cmd, arg);
299 300
300out: 301out:
301 unlock_kernel(); 302 mutex_unlock(&ide_floppy_ioctl_mutex);
302 return err; 303 return err;
303} 304}
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
index 70aeeb18833e..35c4b43585e3 100644
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -1,4 +1,3 @@
1#include <linux/smp_lock.h>
2#include <linux/module.h> 1#include <linux/module.h>
3#include <linux/types.h> 2#include <linux/types.h>
4#include <linux/string.h> 3#include <linux/string.h>
@@ -23,6 +22,7 @@
23#define IDE_GD_VERSION "1.18" 22#define IDE_GD_VERSION "1.18"
24 23
25/* module parameters */ 24/* module parameters */
25static DEFINE_MUTEX(ide_gd_mutex);
26static unsigned long debug_mask; 26static unsigned long debug_mask;
27module_param(debug_mask, ulong, 0644); 27module_param(debug_mask, ulong, 0644);
28 28
@@ -242,9 +242,9 @@ static int ide_gd_unlocked_open(struct block_device *bdev, fmode_t mode)
242{ 242{
243 int ret; 243 int ret;
244 244
245 lock_kernel(); 245 mutex_lock(&ide_gd_mutex);
246 ret = ide_gd_open(bdev, mode); 246 ret = ide_gd_open(bdev, mode);
247 unlock_kernel(); 247 mutex_unlock(&ide_gd_mutex);
248 248
249 return ret; 249 return ret;
250} 250}
@@ -257,7 +257,7 @@ static int ide_gd_release(struct gendisk *disk, fmode_t mode)
257 257
258 ide_debug_log(IDE_DBG_FUNC, "enter"); 258 ide_debug_log(IDE_DBG_FUNC, "enter");
259 259
260 lock_kernel(); 260 mutex_lock(&ide_gd_mutex);
261 if (idkp->openers == 1) 261 if (idkp->openers == 1)
262 drive->disk_ops->flush(drive); 262 drive->disk_ops->flush(drive);
263 263
@@ -269,7 +269,7 @@ static int ide_gd_release(struct gendisk *disk, fmode_t mode)
269 idkp->openers--; 269 idkp->openers--;
270 270
271 ide_disk_put(idkp); 271 ide_disk_put(idkp);
272 unlock_kernel(); 272 mutex_unlock(&ide_gd_mutex);
273 273
274 return 0; 274 return 0;
275} 275}
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 6d622cb5ac81..65f0bcfb42ca 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -32,11 +32,9 @@
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/genhd.h> 33#include <linux/genhd.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/smp_lock.h>
36#include <linux/slab.h> 35#include <linux/slab.h>
37#include <linux/pci.h> 36#include <linux/pci.h>
38#include <linux/ide.h> 37#include <linux/ide.h>
39#include <linux/smp_lock.h>
40#include <linux/completion.h> 38#include <linux/completion.h>
41#include <linux/bitops.h> 39#include <linux/bitops.h>
42#include <linux/mutex.h> 40#include <linux/mutex.h>
@@ -220,6 +218,7 @@ typedef struct ide_tape_obj {
220 char write_prot; 218 char write_prot;
221} idetape_tape_t; 219} idetape_tape_t;
222 220
221static DEFINE_MUTEX(ide_tape_mutex);
223static DEFINE_MUTEX(idetape_ref_mutex); 222static DEFINE_MUTEX(idetape_ref_mutex);
224 223
225static DEFINE_MUTEX(idetape_chrdev_mutex); 224static DEFINE_MUTEX(idetape_chrdev_mutex);
@@ -1426,9 +1425,9 @@ static long idetape_chrdev_ioctl(struct file *file,
1426 unsigned int cmd, unsigned long arg) 1425 unsigned int cmd, unsigned long arg)
1427{ 1426{
1428 long ret; 1427 long ret;
1429 lock_kernel(); 1428 mutex_lock(&ide_tape_mutex);
1430 ret = do_idetape_chrdev_ioctl(file, cmd, arg); 1429 ret = do_idetape_chrdev_ioctl(file, cmd, arg);
1431 unlock_kernel(); 1430 mutex_unlock(&ide_tape_mutex);
1432 return ret; 1431 return ret;
1433} 1432}
1434 1433
@@ -1909,9 +1908,9 @@ static int idetape_open(struct block_device *bdev, fmode_t mode)
1909{ 1908{
1910 struct ide_tape_obj *tape; 1909 struct ide_tape_obj *tape;
1911 1910
1912 lock_kernel(); 1911 mutex_lock(&ide_tape_mutex);
1913 tape = ide_tape_get(bdev->bd_disk, false, 0); 1912 tape = ide_tape_get(bdev->bd_disk, false, 0);
1914 unlock_kernel(); 1913 mutex_unlock(&ide_tape_mutex);
1915 1914
1916 if (!tape) 1915 if (!tape)
1917 return -ENXIO; 1916 return -ENXIO;
@@ -1923,9 +1922,9 @@ static int idetape_release(struct gendisk *disk, fmode_t mode)
1923{ 1922{
1924 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj); 1923 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
1925 1924
1926 lock_kernel(); 1925 mutex_lock(&ide_tape_mutex);
1927 ide_tape_put(tape); 1926 ide_tape_put(tape);
1928 unlock_kernel(); 1927 mutex_unlock(&ide_tape_mutex);
1929 1928
1930 return 0; 1929 return 0;
1931} 1930}
@@ -1937,11 +1936,11 @@ static int idetape_ioctl(struct block_device *bdev, fmode_t mode,
1937 ide_drive_t *drive = tape->drive; 1936 ide_drive_t *drive = tape->drive;
1938 int err; 1937 int err;
1939 1938
1940 lock_kernel(); 1939 mutex_lock(&ide_tape_mutex);
1941 err = generic_ide_ioctl(drive, bdev, cmd, arg); 1940 err = generic_ide_ioctl(drive, bdev, cmd, arg);
1942 if (err == -EINVAL) 1941 if (err == -EINVAL)
1943 err = idetape_blkdev_ioctl(drive, cmd, arg); 1942 err = idetape_blkdev_ioctl(drive, cmd, arg);
1944 unlock_kernel(); 1943 mutex_unlock(&ide_tape_mutex);
1945 1944
1946 return err; 1945 return err;
1947} 1946}
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c
index 7e2c12a5b839..0b4f54265f62 100644
--- a/drivers/input/misc/hp_sdc_rtc.c
+++ b/drivers/input/misc/hp_sdc_rtc.c
@@ -43,7 +43,7 @@
43#include <linux/proc_fs.h> 43#include <linux/proc_fs.h>
44#include <linux/poll.h> 44#include <linux/poll.h>
45#include <linux/rtc.h> 45#include <linux/rtc.h>
46#include <linux/smp_lock.h> 46#include <linux/mutex.h>
47#include <linux/semaphore.h> 47#include <linux/semaphore.h>
48 48
49MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>"); 49MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
@@ -52,6 +52,7 @@ MODULE_LICENSE("Dual BSD/GPL");
52 52
53#define RTC_VERSION "1.10d" 53#define RTC_VERSION "1.10d"
54 54
55static DEFINE_MUTEX(hp_sdc_rtc_mutex);
55static unsigned long epoch = 2000; 56static unsigned long epoch = 2000;
56 57
57static struct semaphore i8042tregs; 58static struct semaphore i8042tregs;
@@ -665,9 +666,9 @@ static long hp_sdc_rtc_unlocked_ioctl(struct file *file,
665{ 666{
666 int ret; 667 int ret;
667 668
668 lock_kernel(); 669 mutex_lock(&hp_sdc_rtc_mutex);
669 ret = hp_sdc_rtc_ioctl(file, cmd, arg); 670 ret = hp_sdc_rtc_ioctl(file, cmd, arg);
670 unlock_kernel(); 671 mutex_unlock(&hp_sdc_rtc_mutex);
671 672
672 return ret; 673 return ret;
673} 674}
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index bf64e49d996a..75049e765191 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -24,7 +24,6 @@
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/mm.h> 25#include <linux/mm.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/smp_lock.h>
28#include <linux/adb.h> 27#include <linux/adb.h>
29#include <linux/cuda.h> 28#include <linux/cuda.h>
30#include <linux/pmu.h> 29#include <linux/pmu.h>
@@ -55,6 +54,7 @@ extern struct adb_driver adb_iop_driver;
55extern struct adb_driver via_pmu_driver; 54extern struct adb_driver via_pmu_driver;
56extern struct adb_driver macio_adb_driver; 55extern struct adb_driver macio_adb_driver;
57 56
57static DEFINE_MUTEX(adb_mutex);
58static struct adb_driver *adb_driver_list[] = { 58static struct adb_driver *adb_driver_list[] = {
59#ifdef CONFIG_ADB_MACII 59#ifdef CONFIG_ADB_MACII
60 &via_macii_driver, 60 &via_macii_driver,
@@ -647,7 +647,7 @@ static int adb_open(struct inode *inode, struct file *file)
647 struct adbdev_state *state; 647 struct adbdev_state *state;
648 int ret = 0; 648 int ret = 0;
649 649
650 lock_kernel(); 650 mutex_lock(&adb_mutex);
651 if (iminor(inode) > 0 || adb_controller == NULL) { 651 if (iminor(inode) > 0 || adb_controller == NULL) {
652 ret = -ENXIO; 652 ret = -ENXIO;
653 goto out; 653 goto out;
@@ -665,7 +665,7 @@ static int adb_open(struct inode *inode, struct file *file)
665 state->inuse = 1; 665 state->inuse = 1;
666 666
667out: 667out:
668 unlock_kernel(); 668 mutex_unlock(&adb_mutex);
669 return ret; 669 return ret;
670} 670}
671 671
@@ -674,7 +674,7 @@ static int adb_release(struct inode *inode, struct file *file)
674 struct adbdev_state *state = file->private_data; 674 struct adbdev_state *state = file->private_data;
675 unsigned long flags; 675 unsigned long flags;
676 676
677 lock_kernel(); 677 mutex_lock(&adb_mutex);
678 if (state) { 678 if (state) {
679 file->private_data = NULL; 679 file->private_data = NULL;
680 spin_lock_irqsave(&state->lock, flags); 680 spin_lock_irqsave(&state->lock, flags);
@@ -687,7 +687,7 @@ static int adb_release(struct inode *inode, struct file *file)
687 spin_unlock_irqrestore(&state->lock, flags); 687 spin_unlock_irqrestore(&state->lock, flags);
688 } 688 }
689 } 689 }
690 unlock_kernel(); 690 mutex_unlock(&adb_mutex);
691 return 0; 691 return 0;
692} 692}
693 693
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index e58c3d33e035..290cb325a94c 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -19,7 +19,6 @@
19 * the userland interface 19 * the userland interface
20 */ 20 */
21 21
22#include <linux/smp_lock.h>
23#include <linux/types.h> 22#include <linux/types.h>
24#include <linux/kernel.h> 23#include <linux/kernel.h>
25#include <linux/device.h> 24#include <linux/device.h>
@@ -97,6 +96,7 @@ struct smu_device {
97 * I don't think there will ever be more than one SMU, so 96 * I don't think there will ever be more than one SMU, so
98 * for now, just hard code that 97 * for now, just hard code that
99 */ 98 */
99static DEFINE_MUTEX(smu_mutex);
100static struct smu_device *smu; 100static struct smu_device *smu;
101static DEFINE_MUTEX(smu_part_access); 101static DEFINE_MUTEX(smu_part_access);
102static int smu_irq_inited; 102static int smu_irq_inited;
@@ -1095,12 +1095,12 @@ static int smu_open(struct inode *inode, struct file *file)
1095 pp->mode = smu_file_commands; 1095 pp->mode = smu_file_commands;
1096 init_waitqueue_head(&pp->wait); 1096 init_waitqueue_head(&pp->wait);
1097 1097
1098 lock_kernel(); 1098 mutex_lock(&smu_mutex);
1099 spin_lock_irqsave(&smu_clist_lock, flags); 1099 spin_lock_irqsave(&smu_clist_lock, flags);
1100 list_add(&pp->list, &smu_clist); 1100 list_add(&pp->list, &smu_clist);
1101 spin_unlock_irqrestore(&smu_clist_lock, flags); 1101 spin_unlock_irqrestore(&smu_clist_lock, flags);
1102 file->private_data = pp; 1102 file->private_data = pp;
1103 unlock_kernel(); 1103 mutex_unlock(&smu_mutex);
1104 1104
1105 return 0; 1105 return 0;
1106} 1106}
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 2d17e76066bd..7b8b1de03db4 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -18,7 +18,7 @@
18 * 18 *
19 */ 19 */
20#include <stdarg.h> 20#include <stdarg.h>
21#include <linux/smp_lock.h> 21#include <linux/mutex.h>
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/errno.h> 23#include <linux/errno.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
@@ -73,6 +73,7 @@
73/* How many iterations between battery polls */ 73/* How many iterations between battery polls */
74#define BATTERY_POLLING_COUNT 2 74#define BATTERY_POLLING_COUNT 2
75 75
76static DEFINE_MUTEX(pmu_info_proc_mutex);
76static volatile unsigned char __iomem *via; 77static volatile unsigned char __iomem *via;
77 78
78/* VIA registers - spaced 0x200 bytes apart */ 79/* VIA registers - spaced 0x200 bytes apart */
@@ -2078,7 +2079,7 @@ pmu_open(struct inode *inode, struct file *file)
2078 pp->rb_get = pp->rb_put = 0; 2079 pp->rb_get = pp->rb_put = 0;
2079 spin_lock_init(&pp->lock); 2080 spin_lock_init(&pp->lock);
2080 init_waitqueue_head(&pp->wait); 2081 init_waitqueue_head(&pp->wait);
2081 lock_kernel(); 2082 mutex_lock(&pmu_info_proc_mutex);
2082 spin_lock_irqsave(&all_pvt_lock, flags); 2083 spin_lock_irqsave(&all_pvt_lock, flags);
2083#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 2084#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2084 pp->backlight_locker = 0; 2085 pp->backlight_locker = 0;
@@ -2086,7 +2087,7 @@ pmu_open(struct inode *inode, struct file *file)
2086 list_add(&pp->list, &all_pmu_pvt); 2087 list_add(&pp->list, &all_pmu_pvt);
2087 spin_unlock_irqrestore(&all_pvt_lock, flags); 2088 spin_unlock_irqrestore(&all_pvt_lock, flags);
2088 file->private_data = pp; 2089 file->private_data = pp;
2089 unlock_kernel(); 2090 mutex_unlock(&pmu_info_proc_mutex);
2090 return 0; 2091 return 0;
2091} 2092}
2092 2093
@@ -2343,9 +2344,9 @@ static long pmu_unlocked_ioctl(struct file *filp,
2343{ 2344{
2344 int ret; 2345 int ret;
2345 2346
2346 lock_kernel(); 2347 mutex_lock(&pmu_info_proc_mutex);
2347 ret = pmu_ioctl(filp, cmd, arg); 2348 ret = pmu_ioctl(filp, cmd, arg);
2348 unlock_kernel(); 2349 mutex_unlock(&pmu_info_proc_mutex);
2349 2350
2350 return ret; 2351 return ret;
2351} 2352}
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index ac384b2a6a33..7967eca5a2d5 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -15,7 +15,6 @@
15#include <linux/blkpg.h> 15#include <linux/blkpg.h>
16#include <linux/bio.h> 16#include <linux/bio.h>
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/smp_lock.h>
19#include <linux/mempool.h> 18#include <linux/mempool.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21#include <linux/idr.h> 20#include <linux/idr.h>
@@ -33,6 +32,7 @@
33#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE" 32#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE"
34#define DM_COOKIE_LENGTH 24 33#define DM_COOKIE_LENGTH 24
35 34
35static DEFINE_MUTEX(dm_mutex);
36static const char *_name = DM_NAME; 36static const char *_name = DM_NAME;
37 37
38static unsigned int major = 0; 38static unsigned int major = 0;
@@ -344,7 +344,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode)
344{ 344{
345 struct mapped_device *md; 345 struct mapped_device *md;
346 346
347 lock_kernel(); 347 mutex_lock(&dm_mutex);
348 spin_lock(&_minor_lock); 348 spin_lock(&_minor_lock);
349 349
350 md = bdev->bd_disk->private_data; 350 md = bdev->bd_disk->private_data;
@@ -362,7 +362,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode)
362 362
363out: 363out:
364 spin_unlock(&_minor_lock); 364 spin_unlock(&_minor_lock);
365 unlock_kernel(); 365 mutex_unlock(&dm_mutex);
366 366
367 return md ? 0 : -ENXIO; 367 return md ? 0 : -ENXIO;
368} 368}
@@ -371,10 +371,10 @@ static int dm_blk_close(struct gendisk *disk, fmode_t mode)
371{ 371{
372 struct mapped_device *md = disk->private_data; 372 struct mapped_device *md = disk->private_data;
373 373
374 lock_kernel(); 374 mutex_lock(&dm_mutex);
375 atomic_dec(&md->open_count); 375 atomic_dec(&md->open_count);
376 dm_put(md); 376 dm_put(md);
377 unlock_kernel(); 377 mutex_unlock(&dm_mutex);
378 378
379 return 0; 379 return 0;
380} 380}
diff --git a/drivers/md/md.c b/drivers/md/md.c
index f20d13e717d5..dbf822df942a 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -36,7 +36,7 @@
36#include <linux/blkdev.h> 36#include <linux/blkdev.h>
37#include <linux/sysctl.h> 37#include <linux/sysctl.h>
38#include <linux/seq_file.h> 38#include <linux/seq_file.h>
39#include <linux/smp_lock.h> 39#include <linux/mutex.h>
40#include <linux/buffer_head.h> /* for invalidate_bdev */ 40#include <linux/buffer_head.h> /* for invalidate_bdev */
41#include <linux/poll.h> 41#include <linux/poll.h>
42#include <linux/ctype.h> 42#include <linux/ctype.h>
@@ -57,6 +57,7 @@
57#define DEBUG 0 57#define DEBUG 0
58#define dprintk(x...) ((void)(DEBUG && printk(x))) 58#define dprintk(x...) ((void)(DEBUG && printk(x)))
59 59
60static DEFINE_MUTEX(md_mutex);
60 61
61#ifndef MODULE 62#ifndef MODULE
62static void autostart_arrays(int part); 63static void autostart_arrays(int part);
@@ -5951,7 +5952,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5951 mddev_t *mddev = mddev_find(bdev->bd_dev); 5952 mddev_t *mddev = mddev_find(bdev->bd_dev);
5952 int err; 5953 int err;
5953 5954
5954 lock_kernel(); 5955 mutex_lock(&md_mutex);
5955 if (mddev->gendisk != bdev->bd_disk) { 5956 if (mddev->gendisk != bdev->bd_disk) {
5956 /* we are racing with mddev_put which is discarding this 5957 /* we are racing with mddev_put which is discarding this
5957 * bd_disk. 5958 * bd_disk.
@@ -5960,7 +5961,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5960 /* Wait until bdev->bd_disk is definitely gone */ 5961 /* Wait until bdev->bd_disk is definitely gone */
5961 flush_scheduled_work(); 5962 flush_scheduled_work();
5962 /* Then retry the open from the top */ 5963 /* Then retry the open from the top */
5963 unlock_kernel(); 5964 mutex_unlock(&md_mutex);
5964 return -ERESTARTSYS; 5965 return -ERESTARTSYS;
5965 } 5966 }
5966 BUG_ON(mddev != bdev->bd_disk->private_data); 5967 BUG_ON(mddev != bdev->bd_disk->private_data);
@@ -5974,7 +5975,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5974 5975
5975 check_disk_size_change(mddev->gendisk, bdev); 5976 check_disk_size_change(mddev->gendisk, bdev);
5976 out: 5977 out:
5977 unlock_kernel(); 5978 mutex_unlock(&md_mutex);
5978 return err; 5979 return err;
5979} 5980}
5980 5981
@@ -5983,10 +5984,10 @@ static int md_release(struct gendisk *disk, fmode_t mode)
5983 mddev_t *mddev = disk->private_data; 5984 mddev_t *mddev = disk->private_data;
5984 5985
5985 BUG_ON(!mddev); 5986 BUG_ON(!mddev);
5986 lock_kernel(); 5987 mutex_lock(&md_mutex);
5987 atomic_dec(&mddev->openers); 5988 atomic_dec(&mddev->openers);
5988 mddev_put(mddev); 5989 mddev_put(mddev);
5989 unlock_kernel(); 5990 mutex_unlock(&md_mutex);
5990 5991
5991 return 0; 5992 return 0;
5992} 5993}
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index d3f1a087eced..02362eccc588 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -18,11 +18,12 @@
18#include <linux/kthread.h> 18#include <linux/kthread.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/smp_lock.h> 21#include <linux/mutex.h>
22#include <linux/memstick.h> 22#include <linux/memstick.h>
23 23
24#define DRIVER_NAME "mspro_block" 24#define DRIVER_NAME "mspro_block"
25 25
26static DEFINE_MUTEX(mspro_block_mutex);
26static int major; 27static int major;
27module_param(major, int, 0644); 28module_param(major, int, 0644);
28 29
@@ -180,7 +181,7 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
180 struct mspro_block_data *msb = disk->private_data; 181 struct mspro_block_data *msb = disk->private_data;
181 int rc = -ENXIO; 182 int rc = -ENXIO;
182 183
183 lock_kernel(); 184 mutex_lock(&mspro_block_mutex);
184 mutex_lock(&mspro_block_disk_lock); 185 mutex_lock(&mspro_block_disk_lock);
185 186
186 if (msb && msb->card) { 187 if (msb && msb->card) {
@@ -192,7 +193,7 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
192 } 193 }
193 194
194 mutex_unlock(&mspro_block_disk_lock); 195 mutex_unlock(&mspro_block_disk_lock);
195 unlock_kernel(); 196 mutex_unlock(&mspro_block_mutex);
196 197
197 return rc; 198 return rc;
198} 199}
@@ -225,9 +226,9 @@ static int mspro_block_disk_release(struct gendisk *disk)
225static int mspro_block_bd_release(struct gendisk *disk, fmode_t mode) 226static int mspro_block_bd_release(struct gendisk *disk, fmode_t mode)
226{ 227{
227 int ret; 228 int ret;
228 lock_kernel(); 229 mutex_lock(&mspro_block_mutex);
229 ret = mspro_block_disk_release(disk); 230 ret = mspro_block_disk_release(disk);
230 unlock_kernel(); 231 mutex_unlock(&mspro_block_mutex);
231 return ret; 232 return ret;
232} 233}
233 234
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index d8ddfdf8be14..a3856ed90aef 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -54,7 +54,7 @@
54#include <linux/pci.h> 54#include <linux/pci.h>
55#include <linux/delay.h> /* for mdelay */ 55#include <linux/delay.h> /* for mdelay */
56#include <linux/miscdevice.h> 56#include <linux/miscdevice.h>
57#include <linux/smp_lock.h> 57#include <linux/mutex.h>
58#include <linux/compat.h> 58#include <linux/compat.h>
59 59
60#include <asm/io.h> 60#include <asm/io.h>
@@ -83,6 +83,7 @@ MODULE_VERSION(my_VERSION);
83 83
84/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 84/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
85 85
86static DEFINE_MUTEX(mpctl_mutex);
86static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS; 87static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS;
87static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS; 88static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS;
88 89
@@ -601,12 +602,12 @@ mptctl_fasync(int fd, struct file *filep, int mode)
601 MPT_ADAPTER *ioc; 602 MPT_ADAPTER *ioc;
602 int ret; 603 int ret;
603 604
604 lock_kernel(); 605 mutex_lock(&mpctl_mutex);
605 list_for_each_entry(ioc, &ioc_list, list) 606 list_for_each_entry(ioc, &ioc_list, list)
606 ioc->aen_event_read_flag=0; 607 ioc->aen_event_read_flag=0;
607 608
608 ret = fasync_helper(fd, filep, mode, &async_queue); 609 ret = fasync_helper(fd, filep, mode, &async_queue);
609 unlock_kernel(); 610 mutex_unlock(&mpctl_mutex);
610 return ret; 611 return ret;
611} 612}
612 613
@@ -698,9 +699,9 @@ static long
698mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 699mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
699{ 700{
700 long ret; 701 long ret;
701 lock_kernel(); 702 mutex_lock(&mpctl_mutex);
702 ret = __mptctl_ioctl(file, cmd, arg); 703 ret = __mptctl_ioctl(file, cmd, arg);
703 unlock_kernel(); 704 mutex_unlock(&mpctl_mutex);
704 return ret; 705 return ret;
705} 706}
706 707
@@ -2926,7 +2927,7 @@ compat_mpt_command(struct file *filp, unsigned int cmd,
2926static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg) 2927static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
2927{ 2928{
2928 long ret; 2929 long ret;
2929 lock_kernel(); 2930 mutex_lock(&mpctl_mutex);
2930 switch (cmd) { 2931 switch (cmd) {
2931 case MPTIOCINFO: 2932 case MPTIOCINFO:
2932 case MPTIOCINFO1: 2933 case MPTIOCINFO1:
@@ -2951,7 +2952,7 @@ static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long a
2951 ret = -ENOIOCTLCMD; 2952 ret = -ENOIOCTLCMD;
2952 break; 2953 break;
2953 } 2954 }
2954 unlock_kernel(); 2955 mutex_unlock(&mpctl_mutex);
2955 return ret; 2956 return ret;
2956} 2957}
2957 2958
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index f0f1e667000f..f87a9d405a5e 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -53,7 +53,7 @@
53#include <linux/module.h> 53#include <linux/module.h>
54#include <linux/slab.h> 54#include <linux/slab.h>
55#include <linux/i2o.h> 55#include <linux/i2o.h>
56#include <linux/smp_lock.h> 56#include <linux/mutex.h>
57 57
58#include <linux/mempool.h> 58#include <linux/mempool.h>
59 59
@@ -69,6 +69,7 @@
69#define OSM_VERSION "1.325" 69#define OSM_VERSION "1.325"
70#define OSM_DESCRIPTION "I2O Block Device OSM" 70#define OSM_DESCRIPTION "I2O Block Device OSM"
71 71
72static DEFINE_MUTEX(i2o_block_mutex);
72static struct i2o_driver i2o_block_driver; 73static struct i2o_driver i2o_block_driver;
73 74
74/* global Block OSM request mempool */ 75/* global Block OSM request mempool */
@@ -578,7 +579,7 @@ static int i2o_block_open(struct block_device *bdev, fmode_t mode)
578 if (!dev->i2o_dev) 579 if (!dev->i2o_dev)
579 return -ENODEV; 580 return -ENODEV;
580 581
581 lock_kernel(); 582 mutex_lock(&i2o_block_mutex);
582 if (dev->power > 0x1f) 583 if (dev->power > 0x1f)
583 i2o_block_device_power(dev, 0x02); 584 i2o_block_device_power(dev, 0x02);
584 585
@@ -587,7 +588,7 @@ static int i2o_block_open(struct block_device *bdev, fmode_t mode)
587 i2o_block_device_lock(dev->i2o_dev, -1); 588 i2o_block_device_lock(dev->i2o_dev, -1);
588 589
589 osm_debug("Ready.\n"); 590 osm_debug("Ready.\n");
590 unlock_kernel(); 591 mutex_unlock(&i2o_block_mutex);
591 592
592 return 0; 593 return 0;
593}; 594};
@@ -618,7 +619,7 @@ static int i2o_block_release(struct gendisk *disk, fmode_t mode)
618 if (!dev->i2o_dev) 619 if (!dev->i2o_dev)
619 return 0; 620 return 0;
620 621
621 lock_kernel(); 622 mutex_lock(&i2o_block_mutex);
622 i2o_block_device_flush(dev->i2o_dev); 623 i2o_block_device_flush(dev->i2o_dev);
623 624
624 i2o_block_device_unlock(dev->i2o_dev, -1); 625 i2o_block_device_unlock(dev->i2o_dev, -1);
@@ -629,7 +630,7 @@ static int i2o_block_release(struct gendisk *disk, fmode_t mode)
629 operation = 0x24; 630 operation = 0x24;
630 631
631 i2o_block_device_power(dev, operation); 632 i2o_block_device_power(dev, operation);
632 unlock_kernel(); 633 mutex_unlock(&i2o_block_mutex);
633 634
634 return 0; 635 return 0;
635} 636}
@@ -664,7 +665,7 @@ static int i2o_block_ioctl(struct block_device *bdev, fmode_t mode,
664 if (!capable(CAP_SYS_ADMIN)) 665 if (!capable(CAP_SYS_ADMIN))
665 return -EPERM; 666 return -EPERM;
666 667
667 lock_kernel(); 668 mutex_lock(&i2o_block_mutex);
668 switch (cmd) { 669 switch (cmd) {
669 case BLKI2OGRSTRAT: 670 case BLKI2OGRSTRAT:
670 ret = put_user(dev->rcache, (int __user *)arg); 671 ret = put_user(dev->rcache, (int __user *)arg);
@@ -688,7 +689,7 @@ static int i2o_block_ioctl(struct block_device *bdev, fmode_t mode,
688 ret = 0; 689 ret = 0;
689 break; 690 break;
690 } 691 }
691 unlock_kernel(); 692 mutex_unlock(&i2o_block_mutex);
692 693
693 return ret; 694 return ret;
694}; 695};
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index 068ba0785bb4..7d3cc575c361 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -31,7 +31,7 @@
31 */ 31 */
32 32
33#include <linux/miscdevice.h> 33#include <linux/miscdevice.h>
34#include <linux/smp_lock.h> 34#include <linux/mutex.h>
35#include <linux/compat.h> 35#include <linux/compat.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37 37
@@ -41,6 +41,7 @@
41 41
42#define SG_TABLESIZE 30 42#define SG_TABLESIZE 30
43 43
44static DEFINE_MUTEX(i2o_cfg_mutex);
44static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long); 45static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long);
45 46
46static spinlock_t i2o_config_lock; 47static spinlock_t i2o_config_lock;
@@ -741,7 +742,7 @@ static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
741 unsigned long arg) 742 unsigned long arg)
742{ 743{
743 int ret; 744 int ret;
744 lock_kernel(); 745 mutex_lock(&i2o_cfg_mutex);
745 switch (cmd) { 746 switch (cmd) {
746 case I2OGETIOPS: 747 case I2OGETIOPS:
747 ret = i2o_cfg_ioctl(file, cmd, arg); 748 ret = i2o_cfg_ioctl(file, cmd, arg);
@@ -753,7 +754,7 @@ static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
753 ret = -ENOIOCTLCMD; 754 ret = -ENOIOCTLCMD;
754 break; 755 break;
755 } 756 }
756 unlock_kernel(); 757 mutex_unlock(&i2o_cfg_mutex);
757 return ret; 758 return ret;
758} 759}
759 760
@@ -981,7 +982,7 @@ static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
981{ 982{
982 int ret; 983 int ret;
983 984
984 lock_kernel(); 985 mutex_lock(&i2o_cfg_mutex);
985 switch (cmd) { 986 switch (cmd) {
986 case I2OGETIOPS: 987 case I2OGETIOPS:
987 ret = i2o_cfg_getiops(arg); 988 ret = i2o_cfg_getiops(arg);
@@ -1037,7 +1038,7 @@ static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
1037 osm_debug("unknown ioctl called!\n"); 1038 osm_debug("unknown ioctl called!\n");
1038 ret = -EINVAL; 1039 ret = -EINVAL;
1039 } 1040 }
1040 unlock_kernel(); 1041 mutex_unlock(&i2o_cfg_mutex);
1041 return ret; 1042 return ret;
1042} 1043}
1043 1044
@@ -1051,7 +1052,7 @@ static int cfg_open(struct inode *inode, struct file *file)
1051 if (!tmp) 1052 if (!tmp)
1052 return -ENOMEM; 1053 return -ENOMEM;
1053 1054
1054 lock_kernel(); 1055 mutex_lock(&i2o_cfg_mutex);
1055 file->private_data = (void *)(i2o_cfg_info_id++); 1056 file->private_data = (void *)(i2o_cfg_info_id++);
1056 tmp->fp = file; 1057 tmp->fp = file;
1057 tmp->fasync = NULL; 1058 tmp->fasync = NULL;
@@ -1065,7 +1066,7 @@ static int cfg_open(struct inode *inode, struct file *file)
1065 spin_lock_irqsave(&i2o_config_lock, flags); 1066 spin_lock_irqsave(&i2o_config_lock, flags);
1066 open_files = tmp; 1067 open_files = tmp;
1067 spin_unlock_irqrestore(&i2o_config_lock, flags); 1068 spin_unlock_irqrestore(&i2o_config_lock, flags);
1068 unlock_kernel(); 1069 mutex_unlock(&i2o_cfg_mutex);
1069 1070
1070 return 0; 1071 return 0;
1071} 1072}
@@ -1076,14 +1077,14 @@ static int cfg_fasync(int fd, struct file *fp, int on)
1076 struct i2o_cfg_info *p; 1077 struct i2o_cfg_info *p;
1077 int ret = -EBADF; 1078 int ret = -EBADF;
1078 1079
1079 lock_kernel(); 1080 mutex_lock(&i2o_cfg_mutex);
1080 for (p = open_files; p; p = p->next) 1081 for (p = open_files; p; p = p->next)
1081 if (p->q_id == id) 1082 if (p->q_id == id)
1082 break; 1083 break;
1083 1084
1084 if (p) 1085 if (p)
1085 ret = fasync_helper(fd, fp, on, &p->fasync); 1086 ret = fasync_helper(fd, fp, on, &p->fasync);
1086 unlock_kernel(); 1087 mutex_unlock(&i2o_cfg_mutex);
1087 return ret; 1088 return ret;
1088} 1089}
1089 1090
@@ -1093,7 +1094,7 @@ static int cfg_release(struct inode *inode, struct file *file)
1093 struct i2o_cfg_info *p, **q; 1094 struct i2o_cfg_info *p, **q;
1094 unsigned long flags; 1095 unsigned long flags;
1095 1096
1096 lock_kernel(); 1097 mutex_lock(&i2o_cfg_mutex);
1097 spin_lock_irqsave(&i2o_config_lock, flags); 1098 spin_lock_irqsave(&i2o_config_lock, flags);
1098 for (q = &open_files; (p = *q) != NULL; q = &p->next) { 1099 for (q = &open_files; (p = *q) != NULL; q = &p->next) {
1099 if (p->q_id == id) { 1100 if (p->q_id == id) {
@@ -1103,7 +1104,7 @@ static int cfg_release(struct inode *inode, struct file *file)
1103 } 1104 }
1104 } 1105 }
1105 spin_unlock_irqrestore(&i2o_config_lock, flags); 1106 spin_unlock_irqrestore(&i2o_config_lock, flags);
1106 unlock_kernel(); 1107 mutex_unlock(&i2o_cfg_mutex);
1107 1108
1108 return 0; 1109 return 0;
1109} 1110}
diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index 75ee0d3f6f45..3712e5077e25 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -24,7 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/phantom.h> 25#include <linux/phantom.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/smp_lock.h> 27#include <linux/mutex.h>
28 28
29#include <asm/atomic.h> 29#include <asm/atomic.h>
30#include <asm/io.h> 30#include <asm/io.h>
@@ -38,6 +38,7 @@
38#define PHB_RUNNING 1 38#define PHB_RUNNING 1
39#define PHB_NOT_OH 2 39#define PHB_NOT_OH 2
40 40
41static DEFINE_MUTEX(phantom_mutex);
41static struct class *phantom_class; 42static struct class *phantom_class;
42static int phantom_major; 43static int phantom_major;
43 44
@@ -215,17 +216,17 @@ static int phantom_open(struct inode *inode, struct file *file)
215 struct phantom_device *dev = container_of(inode->i_cdev, 216 struct phantom_device *dev = container_of(inode->i_cdev,
216 struct phantom_device, cdev); 217 struct phantom_device, cdev);
217 218
218 lock_kernel(); 219 mutex_lock(&phantom_mutex);
219 nonseekable_open(inode, file); 220 nonseekable_open(inode, file);
220 221
221 if (mutex_lock_interruptible(&dev->open_lock)) { 222 if (mutex_lock_interruptible(&dev->open_lock)) {
222 unlock_kernel(); 223 mutex_unlock(&phantom_mutex);
223 return -ERESTARTSYS; 224 return -ERESTARTSYS;
224 } 225 }
225 226
226 if (dev->opened) { 227 if (dev->opened) {
227 mutex_unlock(&dev->open_lock); 228 mutex_unlock(&dev->open_lock);
228 unlock_kernel(); 229 mutex_unlock(&phantom_mutex);
229 return -EINVAL; 230 return -EINVAL;
230 } 231 }
231 232
@@ -236,7 +237,7 @@ static int phantom_open(struct inode *inode, struct file *file)
236 atomic_set(&dev->counter, 0); 237 atomic_set(&dev->counter, 0);
237 dev->opened++; 238 dev->opened++;
238 mutex_unlock(&dev->open_lock); 239 mutex_unlock(&dev->open_lock);
239 unlock_kernel(); 240 mutex_unlock(&phantom_mutex);
240 return 0; 241 return 0;
241} 242}
242 243
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index d545f79f6000..00073b7c0368 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -29,7 +29,6 @@
29#include <linux/kdev_t.h> 29#include <linux/kdev_t.h>
30#include <linux/blkdev.h> 30#include <linux/blkdev.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/smp_lock.h>
33#include <linux/scatterlist.h> 32#include <linux/scatterlist.h>
34#include <linux/string_helpers.h> 33#include <linux/string_helpers.h>
35 34
@@ -51,6 +50,7 @@ MODULE_ALIAS("mmc:block");
51#define MMC_SHIFT 3 50#define MMC_SHIFT 3
52#define MMC_NUM_MINORS (256 >> MMC_SHIFT) 51#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
53 52
53static DEFINE_MUTEX(block_mutex);
54static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS); 54static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS);
55 55
56/* 56/*
@@ -108,7 +108,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
108 struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk); 108 struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
109 int ret = -ENXIO; 109 int ret = -ENXIO;
110 110
111 lock_kernel(); 111 mutex_lock(&block_mutex);
112 if (md) { 112 if (md) {
113 if (md->usage == 2) 113 if (md->usage == 2)
114 check_disk_change(bdev); 114 check_disk_change(bdev);
@@ -119,7 +119,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
119 ret = -EROFS; 119 ret = -EROFS;
120 } 120 }
121 } 121 }
122 unlock_kernel(); 122 mutex_unlock(&block_mutex);
123 123
124 return ret; 124 return ret;
125} 125}
@@ -128,9 +128,9 @@ static int mmc_blk_release(struct gendisk *disk, fmode_t mode)
128{ 128{
129 struct mmc_blk_data *md = disk->private_data; 129 struct mmc_blk_data *md = disk->private_data;
130 130
131 lock_kernel(); 131 mutex_lock(&block_mutex);
132 mmc_blk_put(md); 132 mmc_blk_put(md);
133 unlock_kernel(); 133 mutex_unlock(&block_mutex);
134 return 0; 134 return 0;
135} 135}
136 136
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 62e68707b07f..50ab431b24eb 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -29,7 +29,6 @@
29#include <linux/blkdev.h> 29#include <linux/blkdev.h>
30#include <linux/blkpg.h> 30#include <linux/blkpg.h>
31#include <linux/spinlock.h> 31#include <linux/spinlock.h>
32#include <linux/smp_lock.h>
33#include <linux/hdreg.h> 32#include <linux/hdreg.h>
34#include <linux/init.h> 33#include <linux/init.h>
35#include <linux/mutex.h> 34#include <linux/mutex.h>
@@ -38,6 +37,7 @@
38 37
39#include "mtdcore.h" 38#include "mtdcore.h"
40 39
40static DEFINE_MUTEX(mtd_blkdevs_mutex);
41static LIST_HEAD(blktrans_majors); 41static LIST_HEAD(blktrans_majors);
42static DEFINE_MUTEX(blktrans_ref_mutex); 42static DEFINE_MUTEX(blktrans_ref_mutex);
43 43
@@ -181,7 +181,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
181 if (!dev) 181 if (!dev)
182 return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ 182 return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/
183 183
184 lock_kernel(); 184 mutex_lock(&mtd_blkdevs_mutex);
185 mutex_lock(&dev->lock); 185 mutex_lock(&dev->lock);
186 186
187 if (!dev->mtd) { 187 if (!dev->mtd) {
@@ -198,7 +198,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
198unlock: 198unlock:
199 mutex_unlock(&dev->lock); 199 mutex_unlock(&dev->lock);
200 blktrans_dev_put(dev); 200 blktrans_dev_put(dev);
201 unlock_kernel(); 201 mutex_unlock(&mtd_blkdevs_mutex);
202 return ret; 202 return ret;
203} 203}
204 204
@@ -210,7 +210,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)
210 if (!dev) 210 if (!dev)
211 return ret; 211 return ret;
212 212
213 lock_kernel(); 213 mutex_lock(&mtd_blkdevs_mutex);
214 mutex_lock(&dev->lock); 214 mutex_lock(&dev->lock);
215 215
216 /* Release one reference, we sure its not the last one here*/ 216 /* Release one reference, we sure its not the last one here*/
@@ -223,7 +223,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)
223unlock: 223unlock:
224 mutex_unlock(&dev->lock); 224 mutex_unlock(&dev->lock);
225 blktrans_dev_put(dev); 225 blktrans_dev_put(dev);
226 unlock_kernel(); 226 mutex_unlock(&mtd_blkdevs_mutex);
227 return ret; 227 return ret;
228} 228}
229 229
@@ -256,7 +256,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
256 if (!dev) 256 if (!dev)
257 return ret; 257 return ret;
258 258
259 lock_kernel(); 259 mutex_lock(&mtd_blkdevs_mutex);
260 mutex_lock(&dev->lock); 260 mutex_lock(&dev->lock);
261 261
262 if (!dev->mtd) 262 if (!dev->mtd)
@@ -271,7 +271,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
271 } 271 }
272unlock: 272unlock:
273 mutex_unlock(&dev->lock); 273 mutex_unlock(&dev->lock);
274 unlock_kernel(); 274 mutex_unlock(&mtd_blkdevs_mutex);
275 blktrans_dev_put(dev); 275 blktrans_dev_put(dev);
276 return ret; 276 return ret;
277} 277}
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}
diff --git a/drivers/pci/hotplug/cpqphp_sysfs.c b/drivers/pci/hotplug/cpqphp_sysfs.c
index 56215322930a..4cb30447a486 100644
--- a/drivers/pci/hotplug/cpqphp_sysfs.c
+++ b/drivers/pci/hotplug/cpqphp_sysfs.c
@@ -34,10 +34,11 @@
34#include <linux/workqueue.h> 34#include <linux/workqueue.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/pci_hotplug.h> 36#include <linux/pci_hotplug.h>
37#include <linux/smp_lock.h> 37#include <linux/mutex.h>
38#include <linux/debugfs.h> 38#include <linux/debugfs.h>
39#include "cpqphp.h" 39#include "cpqphp.h"
40 40
41static DEFINE_MUTEX(cpqphp_mutex);
41static int show_ctrl (struct controller *ctrl, char *buf) 42static int show_ctrl (struct controller *ctrl, char *buf)
42{ 43{
43 char *out = buf; 44 char *out = buf;
@@ -147,7 +148,7 @@ static int open(struct inode *inode, struct file *file)
147 struct ctrl_dbg *dbg; 148 struct ctrl_dbg *dbg;
148 int retval = -ENOMEM; 149 int retval = -ENOMEM;
149 150
150 lock_kernel(); 151 mutex_lock(&cpqphp_mutex);
151 dbg = kmalloc(sizeof(*dbg), GFP_KERNEL); 152 dbg = kmalloc(sizeof(*dbg), GFP_KERNEL);
152 if (!dbg) 153 if (!dbg)
153 goto exit; 154 goto exit;
@@ -160,7 +161,7 @@ static int open(struct inode *inode, struct file *file)
160 file->private_data = dbg; 161 file->private_data = dbg;
161 retval = 0; 162 retval = 0;
162exit: 163exit:
163 unlock_kernel(); 164 mutex_unlock(&cpqphp_mutex);
164 return retval; 165 return retval;
165} 166}
166 167
@@ -169,7 +170,7 @@ static loff_t lseek(struct file *file, loff_t off, int whence)
169 struct ctrl_dbg *dbg; 170 struct ctrl_dbg *dbg;
170 loff_t new = -1; 171 loff_t new = -1;
171 172
172 lock_kernel(); 173 mutex_lock(&cpqphp_mutex);
173 dbg = file->private_data; 174 dbg = file->private_data;
174 175
175 switch (whence) { 176 switch (whence) {
@@ -181,10 +182,10 @@ static loff_t lseek(struct file *file, loff_t off, int whence)
181 break; 182 break;
182 } 183 }
183 if (new < 0 || new > dbg->size) { 184 if (new < 0 || new > dbg->size) {
184 unlock_kernel(); 185 mutex_unlock(&cpqphp_mutex);
185 return -EINVAL; 186 return -EINVAL;
186 } 187 }
187 unlock_kernel(); 188 mutex_unlock(&cpqphp_mutex);
188 return (file->f_pos = new); 189 return (file->f_pos = new);
189} 190}
190 191
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index d60557cae8ef..512dca16a42c 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -20,7 +20,7 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/rtc.h> 21#include <linux/rtc.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/smp_lock.h> 23#include <linux/mutex.h>
24#include <linux/string.h> 24#include <linux/string.h>
25#ifdef CONFIG_RTC_DRV_M41T80_WDT 25#ifdef CONFIG_RTC_DRV_M41T80_WDT
26#include <linux/fs.h> 26#include <linux/fs.h>
@@ -68,6 +68,7 @@
68 68
69#define DRV_VERSION "0.05" 69#define DRV_VERSION "0.05"
70 70
71static DEFINE_MUTEX(m41t80_rtc_mutex);
71static const struct i2c_device_id m41t80_id[] = { 72static const struct i2c_device_id m41t80_id[] = {
72 { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT }, 73 { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT },
73 { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD }, 74 { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD },
@@ -677,9 +678,9 @@ static long wdt_unlocked_ioctl(struct file *file, unsigned int cmd,
677{ 678{
678 int ret; 679 int ret;
679 680
680 lock_kernel(); 681 mutex_lock(&m41t80_rtc_mutex);
681 ret = wdt_ioctl(file, cmd, arg); 682 ret = wdt_ioctl(file, cmd, arg);
682 unlock_kernel(); 683 mutex_unlock(&m41t80_rtc_mutex);
683 684
684 return ret; 685 return ret;
685} 686}
@@ -693,16 +694,16 @@ static long wdt_unlocked_ioctl(struct file *file, unsigned int cmd,
693static int wdt_open(struct inode *inode, struct file *file) 694static int wdt_open(struct inode *inode, struct file *file)
694{ 695{
695 if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) { 696 if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) {
696 lock_kernel(); 697 mutex_lock(&m41t80_rtc_mutex);
697 if (test_and_set_bit(0, &wdt_is_open)) { 698 if (test_and_set_bit(0, &wdt_is_open)) {
698 unlock_kernel(); 699 mutex_unlock(&m41t80_rtc_mutex);
699 return -EBUSY; 700 return -EBUSY;
700 } 701 }
701 /* 702 /*
702 * Activate 703 * Activate
703 */ 704 */
704 wdt_is_open = 1; 705 wdt_is_open = 1;
705 unlock_kernel(); 706 mutex_unlock(&m41t80_rtc_mutex);
706 return nonseekable_open(inode, file); 707 return nonseekable_open(inode, file);
707 } 708 }
708 return -ENODEV; 709 return -ENODEV;
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c
index 85cf607fc78f..f0fa9ca5cb2c 100644
--- a/drivers/s390/char/tape_block.c
+++ b/drivers/s390/char/tape_block.c
@@ -16,7 +16,7 @@
16#include <linux/fs.h> 16#include <linux/fs.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/blkdev.h> 18#include <linux/blkdev.h>
19#include <linux/smp_lock.h> 19#include <linux/mutex.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/buffer_head.h> 21#include <linux/buffer_head.h>
22#include <linux/kernel.h> 22#include <linux/kernel.h>
@@ -45,6 +45,7 @@
45/* 45/*
46 * file operation structure for tape block frontend 46 * file operation structure for tape block frontend
47 */ 47 */
48static DEFINE_MUTEX(tape_block_mutex);
48static int tapeblock_open(struct block_device *, fmode_t); 49static int tapeblock_open(struct block_device *, fmode_t);
49static int tapeblock_release(struct gendisk *, fmode_t); 50static int tapeblock_release(struct gendisk *, fmode_t);
50static int tapeblock_medium_changed(struct gendisk *); 51static int tapeblock_medium_changed(struct gendisk *);
@@ -361,7 +362,7 @@ tapeblock_open(struct block_device *bdev, fmode_t mode)
361 struct tape_device * device; 362 struct tape_device * device;
362 int rc; 363 int rc;
363 364
364 lock_kernel(); 365 mutex_lock(&tape_block_mutex);
365 device = tape_get_device(disk->private_data); 366 device = tape_get_device(disk->private_data);
366 367
367 if (device->required_tapemarks) { 368 if (device->required_tapemarks) {
@@ -385,14 +386,14 @@ tapeblock_open(struct block_device *bdev, fmode_t mode)
385 * is called. 386 * is called.
386 */ 387 */
387 tape_state_set(device, TS_BLKUSE); 388 tape_state_set(device, TS_BLKUSE);
388 unlock_kernel(); 389 mutex_unlock(&tape_block_mutex);
389 return 0; 390 return 0;
390 391
391release: 392release:
392 tape_release(device); 393 tape_release(device);
393 put_device: 394 put_device:
394 tape_put_device(device); 395 tape_put_device(device);
395 unlock_kernel(); 396 mutex_unlock(&tape_block_mutex);
396 return rc; 397 return rc;
397} 398}
398 399
@@ -407,11 +408,11 @@ tapeblock_release(struct gendisk *disk, fmode_t mode)
407{ 408{
408 struct tape_device *device = disk->private_data; 409 struct tape_device *device = disk->private_data;
409 410
410 lock_kernel(); 411 mutex_lock(&tape_block_mutex);
411 tape_state_set(device, TS_IN_USE); 412 tape_state_set(device, TS_IN_USE);
412 tape_release(device); 413 tape_release(device);
413 tape_put_device(device); 414 tape_put_device(device);
414 unlock_kernel(); 415 mutex_unlock(&tape_block_mutex);
415 416
416 return 0; 417 return 0;
417} 418}
diff --git a/drivers/sbus/char/jsflash.c b/drivers/sbus/char/jsflash.c
index 4942050dc5b6..13f48e28a1e1 100644
--- a/drivers/sbus/char/jsflash.c
+++ b/drivers/sbus/char/jsflash.c
@@ -27,7 +27,7 @@
27 */ 27 */
28 28
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/smp_lock.h> 30#include <linux/mutex.h>
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/miscdevice.h> 33#include <linux/miscdevice.h>
@@ -68,6 +68,8 @@
68#define JSF_PART_BITS 2 /* 2 bits of minors to cover JSF_NPART */ 68#define JSF_PART_BITS 2 /* 2 bits of minors to cover JSF_NPART */
69#define JSF_PART_MASK 0x3 /* 2 bits mask */ 69#define JSF_PART_MASK 0x3 /* 2 bits mask */
70 70
71static DEFINE_MUTEX(jsf_mutex);
72
71/* 73/*
72 * Access functions. 74 * Access functions.
73 * We could ioremap(), but it's easier this way. 75 * We could ioremap(), but it's easier this way.
@@ -225,7 +227,7 @@ static loff_t jsf_lseek(struct file * file, loff_t offset, int orig)
225{ 227{
226 loff_t ret; 228 loff_t ret;
227 229
228 lock_kernel(); 230 mutex_lock(&jsf_mutex);
229 switch (orig) { 231 switch (orig) {
230 case 0: 232 case 0:
231 file->f_pos = offset; 233 file->f_pos = offset;
@@ -238,7 +240,7 @@ static loff_t jsf_lseek(struct file * file, loff_t offset, int orig)
238 default: 240 default:
239 ret = -EINVAL; 241 ret = -EINVAL;
240 } 242 }
241 unlock_kernel(); 243 mutex_unlock(&jsf_mutex);
242 return ret; 244 return ret;
243} 245}
244 246
@@ -384,18 +386,18 @@ static int jsf_ioctl_program(void __user *arg)
384 386
385static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg) 387static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
386{ 388{
387 lock_kernel(); 389 mutex_lock(&jsf_mutex);
388 int error = -ENOTTY; 390 int error = -ENOTTY;
389 void __user *argp = (void __user *)arg; 391 void __user *argp = (void __user *)arg;
390 392
391 if (!capable(CAP_SYS_ADMIN)) { 393 if (!capable(CAP_SYS_ADMIN)) {
392 unlock_kernel(); 394 mutex_unlock(&jsf_mutex);
393 return -EPERM; 395 return -EPERM;
394 } 396 }
395 switch (cmd) { 397 switch (cmd) {
396 case JSFLASH_IDENT: 398 case JSFLASH_IDENT:
397 if (copy_to_user(argp, &jsf0.id, JSFIDSZ)) { 399 if (copy_to_user(argp, &jsf0.id, JSFIDSZ)) {
398 unlock_kernel(); 400 mutex_unlock(&jsf_mutex);
399 return -EFAULT; 401 return -EFAULT;
400 } 402 }
401 break; 403 break;
@@ -407,7 +409,7 @@ static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
407 break; 409 break;
408 } 410 }
409 411
410 unlock_kernel(); 412 mutex_unlock(&jsf_mutex);
411 return error; 413 return error;
412} 414}
413 415
@@ -418,17 +420,17 @@ static int jsf_mmap(struct file * file, struct vm_area_struct * vma)
418 420
419static int jsf_open(struct inode * inode, struct file * filp) 421static int jsf_open(struct inode * inode, struct file * filp)
420{ 422{
421 lock_kernel(); 423 mutex_lock(&jsf_mutex);
422 if (jsf0.base == 0) { 424 if (jsf0.base == 0) {
423 unlock_kernel(); 425 mutex_unlock(&jsf_mutex);
424 return -ENXIO; 426 return -ENXIO;
425 } 427 }
426 if (test_and_set_bit(0, (void *)&jsf0.busy) != 0) { 428 if (test_and_set_bit(0, (void *)&jsf0.busy) != 0) {
427 unlock_kernel(); 429 mutex_unlock(&jsf_mutex);
428 return -EBUSY; 430 return -EBUSY;
429 } 431 }
430 432
431 unlock_kernel(); 433 mutex_unlock(&jsf_mutex);
432 return 0; /* XXX What security? */ 434 return 0; /* XXX What security? */
433} 435}
434 436
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index e20b7bdd4c78..09a139f61ca4 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -92,7 +92,6 @@
92#include <linux/pci.h> 92#include <linux/pci.h>
93#include <linux/time.h> 93#include <linux/time.h>
94#include <linux/mutex.h> 94#include <linux/mutex.h>
95#include <linux/smp_lock.h>
96#include <linux/slab.h> 95#include <linux/slab.h>
97#include <asm/io.h> 96#include <asm/io.h>
98#include <asm/irq.h> 97#include <asm/irq.h>
@@ -105,6 +104,7 @@
105 104
106/* Globals */ 105/* Globals */
107#define TW_DRIVER_VERSION "2.26.02.014" 106#define TW_DRIVER_VERSION "2.26.02.014"
107static DEFINE_MUTEX(twa_chrdev_mutex);
108static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT]; 108static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT];
109static unsigned int twa_device_extension_count; 109static unsigned int twa_device_extension_count;
110static int twa_major = -1; 110static int twa_major = -1;
@@ -658,7 +658,7 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
658 int retval = TW_IOCTL_ERROR_OS_EFAULT; 658 int retval = TW_IOCTL_ERROR_OS_EFAULT;
659 void __user *argp = (void __user *)arg; 659 void __user *argp = (void __user *)arg;
660 660
661 lock_kernel(); 661 mutex_lock(&twa_chrdev_mutex);
662 662
663 /* Only let one of these through at a time */ 663 /* Only let one of these through at a time */
664 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { 664 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
@@ -879,7 +879,7 @@ out3:
879out2: 879out2:
880 mutex_unlock(&tw_dev->ioctl_lock); 880 mutex_unlock(&tw_dev->ioctl_lock);
881out: 881out:
882 unlock_kernel(); 882 mutex_unlock(&twa_chrdev_mutex);
883 return retval; 883 return retval;
884} /* End twa_chrdev_ioctl() */ 884} /* End twa_chrdev_ioctl() */
885 885
@@ -890,7 +890,6 @@ static int twa_chrdev_open(struct inode *inode, struct file *file)
890 unsigned int minor_number; 890 unsigned int minor_number;
891 int retval = TW_IOCTL_ERROR_OS_ENODEV; 891 int retval = TW_IOCTL_ERROR_OS_ENODEV;
892 892
893 cycle_kernel_lock();
894 minor_number = iminor(inode); 893 minor_number = iminor(inode);
895 if (minor_number >= twa_device_extension_count) 894 if (minor_number >= twa_device_extension_count)
896 goto out; 895 goto out;
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index f481e734aad4..7e5f2385e3e6 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -64,7 +64,6 @@
64#include <linux/pci.h> 64#include <linux/pci.h>
65#include <linux/time.h> 65#include <linux/time.h>
66#include <linux/mutex.h> 66#include <linux/mutex.h>
67#include <linux/smp_lock.h>
68#include <linux/slab.h> 67#include <linux/slab.h>
69#include <asm/io.h> 68#include <asm/io.h>
70#include <asm/irq.h> 69#include <asm/irq.h>
@@ -77,6 +76,7 @@
77 76
78/* Globals */ 77/* Globals */
79#define TW_DRIVER_VERSION "3.26.02.000" 78#define TW_DRIVER_VERSION "3.26.02.000"
79static DEFINE_MUTEX(twl_chrdev_mutex);
80static TW_Device_Extension *twl_device_extension_list[TW_MAX_SLOT]; 80static TW_Device_Extension *twl_device_extension_list[TW_MAX_SLOT];
81static unsigned int twl_device_extension_count; 81static unsigned int twl_device_extension_count;
82static int twl_major = -1; 82static int twl_major = -1;
@@ -764,7 +764,7 @@ static long twl_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
764 int retval = -EFAULT; 764 int retval = -EFAULT;
765 void __user *argp = (void __user *)arg; 765 void __user *argp = (void __user *)arg;
766 766
767 lock_kernel(); 767 mutex_lock(&twl_chrdev_mutex);
768 768
769 /* Only let one of these through at a time */ 769 /* Only let one of these through at a time */
770 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { 770 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
@@ -861,7 +861,7 @@ out3:
861out2: 861out2:
862 mutex_unlock(&tw_dev->ioctl_lock); 862 mutex_unlock(&tw_dev->ioctl_lock);
863out: 863out:
864 unlock_kernel(); 864 mutex_unlock(&twl_chrdev_mutex);
865 return retval; 865 return retval;
866} /* End twl_chrdev_ioctl() */ 866} /* End twl_chrdev_ioctl() */
867 867
@@ -876,7 +876,6 @@ static int twl_chrdev_open(struct inode *inode, struct file *file)
876 goto out; 876 goto out;
877 } 877 }
878 878
879 cycle_kernel_lock();
880 minor_number = iminor(inode); 879 minor_number = iminor(inode);
881 if (minor_number >= twl_device_extension_count) 880 if (minor_number >= twl_device_extension_count)
882 goto out; 881 goto out;
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 30d735ad35b5..081c864c11d2 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -199,7 +199,6 @@
199 199
200#include <linux/module.h> 200#include <linux/module.h>
201#include <linux/reboot.h> 201#include <linux/reboot.h>
202#include <linux/smp_lock.h>
203#include <linux/spinlock.h> 202#include <linux/spinlock.h>
204#include <linux/interrupt.h> 203#include <linux/interrupt.h>
205#include <linux/moduleparam.h> 204#include <linux/moduleparam.h>
@@ -221,6 +220,7 @@
221 220
222/* Globals */ 221/* Globals */
223#define TW_DRIVER_VERSION "1.26.02.003" 222#define TW_DRIVER_VERSION "1.26.02.003"
223static DEFINE_MUTEX(tw_mutex);
224static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT]; 224static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT];
225static int tw_device_extension_count = 0; 225static int tw_device_extension_count = 0;
226static int twe_major = -1; 226static int twe_major = -1;
@@ -900,10 +900,10 @@ static long tw_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long a
900 900
901 dprintk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl()\n"); 901 dprintk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl()\n");
902 902
903 lock_kernel(); 903 mutex_lock(&tw_mutex);
904 /* Only let one of these through at a time */ 904 /* Only let one of these through at a time */
905 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { 905 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
906 unlock_kernel(); 906 mutex_unlock(&tw_mutex);
907 return -EINTR; 907 return -EINTR;
908 } 908 }
909 909
@@ -1034,7 +1034,7 @@ out2:
1034 dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, cpu_addr, dma_handle); 1034 dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, cpu_addr, dma_handle);
1035out: 1035out:
1036 mutex_unlock(&tw_dev->ioctl_lock); 1036 mutex_unlock(&tw_dev->ioctl_lock);
1037 unlock_kernel(); 1037 mutex_unlock(&tw_mutex);
1038 return retval; 1038 return retval;
1039} /* End tw_chrdev_ioctl() */ 1039} /* End tw_chrdev_ioctl() */
1040 1040
@@ -1044,7 +1044,6 @@ static int tw_chrdev_open(struct inode *inode, struct file *file)
1044{ 1044{
1045 unsigned int minor_number; 1045 unsigned int minor_number;
1046 1046
1047 cycle_kernel_lock();
1048 dprintk(KERN_WARNING "3w-xxxx: tw_ioctl_open()\n"); 1047 dprintk(KERN_WARNING "3w-xxxx: tw_ioctl_open()\n");
1049 1048
1050 minor_number = iminor(inode); 1049 minor_number = iminor(inode);
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index cad6f9abaeb9..6e233362dd7b 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -38,7 +38,7 @@
38#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/smp_lock.h> 41#include <linux/mutex.h>
42#include <linux/spinlock.h> 42#include <linux/spinlock.h>
43#include <linux/syscalls.h> 43#include <linux/syscalls.h>
44#include <linux/delay.h> 44#include <linux/delay.h>
@@ -76,6 +76,7 @@ MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, "
76MODULE_LICENSE("GPL"); 76MODULE_LICENSE("GPL");
77MODULE_VERSION(AAC_DRIVER_FULL_VERSION); 77MODULE_VERSION(AAC_DRIVER_FULL_VERSION);
78 78
79static DEFINE_MUTEX(aac_mutex);
79static LIST_HEAD(aac_devices); 80static LIST_HEAD(aac_devices);
80static int aac_cfg_major = -1; 81static int aac_cfg_major = -1;
81char aac_driver_version[] = AAC_DRIVER_FULL_VERSION; 82char aac_driver_version[] = AAC_DRIVER_FULL_VERSION;
@@ -678,7 +679,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)
678 unsigned minor_number = iminor(inode); 679 unsigned minor_number = iminor(inode);
679 int err = -ENODEV; 680 int err = -ENODEV;
680 681
681 lock_kernel(); /* BKL pushdown: nothing else protects this list */ 682 mutex_lock(&aac_mutex); /* BKL pushdown: nothing else protects this list */
682 list_for_each_entry(aac, &aac_devices, entry) { 683 list_for_each_entry(aac, &aac_devices, entry) {
683 if (aac->id == minor_number) { 684 if (aac->id == minor_number) {
684 file->private_data = aac; 685 file->private_data = aac;
@@ -686,7 +687,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)
686 break; 687 break;
687 } 688 }
688 } 689 }
689 unlock_kernel(); 690 mutex_unlock(&aac_mutex);
690 691
691 return err; 692 return err;
692} 693}
@@ -711,9 +712,9 @@ static long aac_cfg_ioctl(struct file *file,
711 int ret; 712 int ret;
712 if (!capable(CAP_SYS_RAWIO)) 713 if (!capable(CAP_SYS_RAWIO))
713 return -EPERM; 714 return -EPERM;
714 lock_kernel(); 715 mutex_lock(&aac_mutex);
715 ret = aac_do_ioctl(file->private_data, cmd, (void __user *)arg); 716 ret = aac_do_ioctl(file->private_data, cmd, (void __user *)arg);
716 unlock_kernel(); 717 mutex_unlock(&aac_mutex);
717 718
718 return ret; 719 return ret;
719} 720}
@@ -722,7 +723,7 @@ static long aac_cfg_ioctl(struct file *file,
722static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long arg) 723static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long arg)
723{ 724{
724 long ret; 725 long ret;
725 lock_kernel(); 726 mutex_lock(&aac_mutex);
726 switch (cmd) { 727 switch (cmd) {
727 case FSACTL_MINIPORT_REV_CHECK: 728 case FSACTL_MINIPORT_REV_CHECK:
728 case FSACTL_SENDFIB: 729 case FSACTL_SENDFIB:
@@ -756,7 +757,7 @@ static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long
756 ret = -ENOIOCTLCMD; 757 ret = -ENOIOCTLCMD;
757 break; 758 break;
758 } 759 }
759 unlock_kernel(); 760 mutex_unlock(&aac_mutex);
760 return ret; 761 return ret;
761} 762}
762 763
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
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index ffc1edf5e80d..410ac1def8a6 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -49,7 +49,6 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
49#include <linux/kernel.h> /* for printk */ 49#include <linux/kernel.h> /* for printk */
50#include <linux/sched.h> 50#include <linux/sched.h>
51#include <linux/reboot.h> 51#include <linux/reboot.h>
52#include <linux/smp_lock.h>
53#include <linux/spinlock.h> 52#include <linux/spinlock.h>
54#include <linux/dma-mapping.h> 53#include <linux/dma-mapping.h>
55 54
@@ -76,6 +75,7 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
76 * Needed for our management apps 75 * Needed for our management apps
77 *============================================================================ 76 *============================================================================
78 */ 77 */
78static DEFINE_MUTEX(adpt_mutex);
79static dpt_sig_S DPTI_sig = { 79static dpt_sig_S DPTI_sig = {
80 {'d', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION, 80 {'d', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION,
81#ifdef __i386__ 81#ifdef __i386__
@@ -1732,12 +1732,12 @@ static int adpt_open(struct inode *inode, struct file *file)
1732 int minor; 1732 int minor;
1733 adpt_hba* pHba; 1733 adpt_hba* pHba;
1734 1734
1735 lock_kernel(); 1735 mutex_lock(&adpt_mutex);
1736 //TODO check for root access 1736 //TODO check for root access
1737 // 1737 //
1738 minor = iminor(inode); 1738 minor = iminor(inode);
1739 if (minor >= hba_count) { 1739 if (minor >= hba_count) {
1740 unlock_kernel(); 1740 mutex_unlock(&adpt_mutex);
1741 return -ENXIO; 1741 return -ENXIO;
1742 } 1742 }
1743 mutex_lock(&adpt_configuration_lock); 1743 mutex_lock(&adpt_configuration_lock);
@@ -1748,7 +1748,7 @@ static int adpt_open(struct inode *inode, struct file *file)
1748 } 1748 }
1749 if (pHba == NULL) { 1749 if (pHba == NULL) {
1750 mutex_unlock(&adpt_configuration_lock); 1750 mutex_unlock(&adpt_configuration_lock);
1751 unlock_kernel(); 1751 mutex_unlock(&adpt_mutex);
1752 return -ENXIO; 1752 return -ENXIO;
1753 } 1753 }
1754 1754
@@ -1759,7 +1759,7 @@ static int adpt_open(struct inode *inode, struct file *file)
1759 1759
1760 pHba->in_use = 1; 1760 pHba->in_use = 1;
1761 mutex_unlock(&adpt_configuration_lock); 1761 mutex_unlock(&adpt_configuration_lock);
1762 unlock_kernel(); 1762 mutex_unlock(&adpt_mutex);
1763 1763
1764 return 0; 1764 return 0;
1765} 1765}
@@ -2160,9 +2160,9 @@ static long adpt_unlocked_ioctl(struct file *file, uint cmd, ulong arg)
2160 2160
2161 inode = file->f_dentry->d_inode; 2161 inode = file->f_dentry->d_inode;
2162 2162
2163 lock_kernel(); 2163 mutex_lock(&adpt_mutex);
2164 ret = adpt_ioctl(inode, file, cmd, arg); 2164 ret = adpt_ioctl(inode, file, cmd, arg);
2165 unlock_kernel(); 2165 mutex_unlock(&adpt_mutex);
2166 2166
2167 return ret; 2167 return ret;
2168} 2168}
@@ -2176,7 +2176,7 @@ static long compat_adpt_ioctl(struct file *file,
2176 2176
2177 inode = file->f_dentry->d_inode; 2177 inode = file->f_dentry->d_inode;
2178 2178
2179 lock_kernel(); 2179 mutex_lock(&adpt_mutex);
2180 2180
2181 switch(cmd) { 2181 switch(cmd) {
2182 case DPT_SIGNATURE: 2182 case DPT_SIGNATURE:
@@ -2194,7 +2194,7 @@ static long compat_adpt_ioctl(struct file *file,
2194 ret = -ENOIOCTLCMD; 2194 ret = -ENOIOCTLCMD;
2195 } 2195 }
2196 2196
2197 unlock_kernel(); 2197 mutex_unlock(&adpt_mutex);
2198 2198
2199 return ret; 2199 return ret;
2200} 2200}
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index b860d650a563..e927607bbf89 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -120,7 +120,7 @@
120#include <linux/timer.h> 120#include <linux/timer.h>
121#include <linux/dma-mapping.h> 121#include <linux/dma-mapping.h>
122#include <linux/list.h> 122#include <linux/list.h>
123#include <linux/smp_lock.h> 123#include <linux/mutex.h>
124#include <linux/slab.h> 124#include <linux/slab.h>
125 125
126#ifdef GDTH_RTC 126#ifdef GDTH_RTC
@@ -140,6 +140,7 @@
140#include <scsi/scsi_host.h> 140#include <scsi/scsi_host.h>
141#include "gdth.h" 141#include "gdth.h"
142 142
143static DEFINE_MUTEX(gdth_mutex);
143static void gdth_delay(int milliseconds); 144static void gdth_delay(int milliseconds);
144static void gdth_eval_mapping(u32 size, u32 *cyls, int *heads, int *secs); 145static void gdth_eval_mapping(u32 size, u32 *cyls, int *heads, int *secs);
145static irqreturn_t gdth_interrupt(int irq, void *dev_id); 146static irqreturn_t gdth_interrupt(int irq, void *dev_id);
@@ -4042,12 +4043,12 @@ static int gdth_open(struct inode *inode, struct file *filep)
4042{ 4043{
4043 gdth_ha_str *ha; 4044 gdth_ha_str *ha;
4044 4045
4045 lock_kernel(); 4046 mutex_lock(&gdth_mutex);
4046 list_for_each_entry(ha, &gdth_instances, list) { 4047 list_for_each_entry(ha, &gdth_instances, list) {
4047 if (!ha->sdev) 4048 if (!ha->sdev)
4048 ha->sdev = scsi_get_host_dev(ha->shost); 4049 ha->sdev = scsi_get_host_dev(ha->shost);
4049 } 4050 }
4050 unlock_kernel(); 4051 mutex_unlock(&gdth_mutex);
4051 4052
4052 TRACE(("gdth_open()\n")); 4053 TRACE(("gdth_open()\n"));
4053 return 0; 4054 return 0;
@@ -4615,9 +4616,9 @@ static long gdth_unlocked_ioctl(struct file *file, unsigned int cmd,
4615{ 4616{
4616 int ret; 4617 int ret;
4617 4618
4618 lock_kernel(); 4619 mutex_lock(&gdth_mutex);
4619 ret = gdth_ioctl(file, cmd, arg); 4620 ret = gdth_ioctl(file, cmd, arg);
4620 unlock_kernel(); 4621 mutex_unlock(&gdth_mutex);
4621 4622
4622 return ret; 4623 return ret;
4623} 4624}
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 0b6e3228610a..4d0cf5cd82cc 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -46,7 +46,7 @@
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/init.h> 47#include <linux/init.h>
48#include <linux/dma-mapping.h> 48#include <linux/dma-mapping.h>
49#include <linux/smp_lock.h> 49#include <linux/mutex.h>
50#include <linux/slab.h> 50#include <linux/slab.h>
51#include <scsi/scsicam.h> 51#include <scsi/scsicam.h>
52 52
@@ -62,6 +62,7 @@ MODULE_DESCRIPTION ("LSI Logic MegaRAID legacy driver");
62MODULE_LICENSE ("GPL"); 62MODULE_LICENSE ("GPL");
63MODULE_VERSION(MEGARAID_MODULE_VERSION); 63MODULE_VERSION(MEGARAID_MODULE_VERSION);
64 64
65static DEFINE_MUTEX(megadev_mutex);
65static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN; 66static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN;
66module_param(max_cmd_per_lun, uint, 0); 67module_param(max_cmd_per_lun, uint, 0);
67MODULE_PARM_DESC(max_cmd_per_lun, "Maximum number of commands which can be issued to a single LUN (default=DEF_CMD_PER_LUN=63)"); 68MODULE_PARM_DESC(max_cmd_per_lun, "Maximum number of commands which can be issued to a single LUN (default=DEF_CMD_PER_LUN=63)");
@@ -3282,7 +3283,6 @@ mega_init_scb(adapter_t *adapter)
3282static int 3283static int
3283megadev_open (struct inode *inode, struct file *filep) 3284megadev_open (struct inode *inode, struct file *filep)
3284{ 3285{
3285 cycle_kernel_lock();
3286 /* 3286 /*
3287 * Only allow superuser to access private ioctl interface 3287 * Only allow superuser to access private ioctl interface
3288 */ 3288 */
@@ -3701,9 +3701,9 @@ megadev_unlocked_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
3701{ 3701{
3702 int ret; 3702 int ret;
3703 3703
3704 lock_kernel(); 3704 mutex_lock(&megadev_mutex);
3705 ret = megadev_ioctl(filep, cmd, arg); 3705 ret = megadev_ioctl(filep, cmd, arg);
3706 unlock_kernel(); 3706 mutex_unlock(&megadev_mutex);
3707 3707
3708 return ret; 3708 return ret;
3709} 3709}
diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index 41f82f76d884..42770a1e7b8a 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -16,11 +16,12 @@
16 */ 16 */
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/smp_lock.h> 19#include <linux/mutex.h>
20#include "megaraid_mm.h" 20#include "megaraid_mm.h"
21 21
22 22
23// Entry points for char node driver 23// Entry points for char node driver
24static DEFINE_MUTEX(mraid_mm_mutex);
24static int mraid_mm_open(struct inode *, struct file *); 25static int mraid_mm_open(struct inode *, struct file *);
25static long mraid_mm_unlocked_ioctl(struct file *, uint, unsigned long); 26static long mraid_mm_unlocked_ioctl(struct file *, uint, unsigned long);
26 27
@@ -98,7 +99,6 @@ mraid_mm_open(struct inode *inode, struct file *filep)
98 */ 99 */
99 if (!capable(CAP_SYS_ADMIN)) return (-EACCES); 100 if (!capable(CAP_SYS_ADMIN)) return (-EACCES);
100 101
101 cycle_kernel_lock();
102 return 0; 102 return 0;
103} 103}
104 104
@@ -224,9 +224,9 @@ mraid_mm_unlocked_ioctl(struct file *filep, unsigned int cmd,
224 int err; 224 int err;
225 225
226 /* inconsistant: mraid_mm_compat_ioctl doesn't take the BKL */ 226 /* inconsistant: mraid_mm_compat_ioctl doesn't take the BKL */
227 lock_kernel(); 227 mutex_lock(&mraid_mm_mutex);
228 err = mraid_mm_ioctl(filep, cmd, arg); 228 err = mraid_mm_ioctl(filep, cmd, arg);
229 unlock_kernel(); 229 mutex_unlock(&mraid_mm_mutex);
230 230
231 return err; 231 return err;
232} 232}
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index 99e4478c3f3e..c4a595d8d23a 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -33,7 +33,6 @@
33#include <linux/spinlock.h> 33#include <linux/spinlock.h>
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/smp_lock.h>
37#include <linux/uio.h> 36#include <linux/uio.h>
38#include <linux/slab.h> 37#include <linux/slab.h>
39#include <asm/uaccess.h> 38#include <asm/uaccess.h>
@@ -3557,7 +3556,6 @@ static void megasas_shutdown(struct pci_dev *pdev)
3557 */ 3556 */
3558static int megasas_mgmt_open(struct inode *inode, struct file *filep) 3557static int megasas_mgmt_open(struct inode *inode, struct file *filep)
3559{ 3558{
3560 cycle_kernel_lock();
3561 /* 3559 /*
3562 * Allow only those users with admin rights 3560 * Allow only those users with admin rights
3563 */ 3561 */
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index b774973f0765..31cf126ed440 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -51,7 +51,7 @@
51#include <linux/types.h> 51#include <linux/types.h>
52#include <linux/pci.h> 52#include <linux/pci.h>
53#include <linux/delay.h> 53#include <linux/delay.h>
54#include <linux/smp_lock.h> 54#include <linux/mutex.h>
55#include <linux/compat.h> 55#include <linux/compat.h>
56#include <linux/poll.h> 56#include <linux/poll.h>
57 57
@@ -61,6 +61,7 @@
61#include "mpt2sas_base.h" 61#include "mpt2sas_base.h"
62#include "mpt2sas_ctl.h" 62#include "mpt2sas_ctl.h"
63 63
64static DEFINE_MUTEX(_ctl_mutex);
64static struct fasync_struct *async_queue; 65static struct fasync_struct *async_queue;
65static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait); 66static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait);
66 67
@@ -2238,9 +2239,9 @@ _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2238{ 2239{
2239 long ret; 2240 long ret;
2240 2241
2241 lock_kernel(); 2242 mutex_lock(&_ctl_mutex);
2242 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); 2243 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
2243 unlock_kernel(); 2244 mutex_unlock(&_ctl_mutex);
2244 return ret; 2245 return ret;
2245} 2246}
2246 2247
@@ -2309,12 +2310,12 @@ _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2309{ 2310{
2310 long ret; 2311 long ret;
2311 2312
2312 lock_kernel(); 2313 mutex_lock(&_ctl_mutex);
2313 if (cmd == MPT2COMMAND32) 2314 if (cmd == MPT2COMMAND32)
2314 ret = _ctl_compat_mpt_command(file, cmd, arg); 2315 ret = _ctl_compat_mpt_command(file, cmd, arg);
2315 else 2316 else
2316 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); 2317 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
2317 unlock_kernel(); 2318 mutex_unlock(&_ctl_mutex);
2318 return ret; 2319 return ret;
2319} 2320}
2320#endif 2321#endif
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 278b352ae78d..54de1d1af1a7 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -51,7 +51,7 @@ static const char * osst_version = "0.99.4";
51#include <linux/moduleparam.h> 51#include <linux/moduleparam.h>
52#include <linux/delay.h> 52#include <linux/delay.h>
53#include <linux/jiffies.h> 53#include <linux/jiffies.h>
54#include <linux/smp_lock.h> 54#include <linux/mutex.h>
55#include <asm/uaccess.h> 55#include <asm/uaccess.h>
56#include <asm/dma.h> 56#include <asm/dma.h>
57#include <asm/system.h> 57#include <asm/system.h>
@@ -80,6 +80,7 @@ static const char * osst_version = "0.99.4";
80#include "osst_options.h" 80#include "osst_options.h"
81#include "osst_detect.h" 81#include "osst_detect.h"
82 82
83static DEFINE_MUTEX(osst_int_mutex);
83static int max_dev = 0; 84static int max_dev = 0;
84static int write_threshold_kbs = 0; 85static int write_threshold_kbs = 0;
85static int max_sg_segs = 0; 86static int max_sg_segs = 0;
@@ -4807,9 +4808,9 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
4807{ 4808{
4808 int ret; 4809 int ret;
4809 4810
4810 lock_kernel(); 4811 mutex_lock(&osst_int_mutex);
4811 ret = __os_scsi_tape_open(inode, filp); 4812 ret = __os_scsi_tape_open(inode, filp);
4812 unlock_kernel(); 4813 mutex_unlock(&osst_int_mutex);
4813 return ret; 4814 return ret;
4814} 4815}
4815 4816
@@ -4943,9 +4944,9 @@ static long osst_ioctl(struct file * file,
4943 char * name = tape_name(STp); 4944 char * name = tape_name(STp);
4944 void __user * p = (void __user *)arg; 4945 void __user * p = (void __user *)arg;
4945 4946
4946 lock_kernel(); 4947 mutex_lock(&osst_int_mutex);
4947 if (mutex_lock_interruptible(&STp->lock)) { 4948 if (mutex_lock_interruptible(&STp->lock)) {
4948 unlock_kernel(); 4949 mutex_unlock(&osst_int_mutex);
4949 return -ERESTARTSYS; 4950 return -ERESTARTSYS;
4950 } 4951 }
4951 4952
@@ -5260,14 +5261,14 @@ static long osst_ioctl(struct file * file,
5260 mutex_unlock(&STp->lock); 5261 mutex_unlock(&STp->lock);
5261 5262
5262 retval = scsi_ioctl(STp->device, cmd_in, p); 5263 retval = scsi_ioctl(STp->device, cmd_in, p);
5263 unlock_kernel(); 5264 mutex_unlock(&osst_int_mutex);
5264 return retval; 5265 return retval;
5265 5266
5266out: 5267out:
5267 if (SRpnt) osst_release_request(SRpnt); 5268 if (SRpnt) osst_release_request(SRpnt);
5268 5269
5269 mutex_unlock(&STp->lock); 5270 mutex_unlock(&STp->lock);
5270 unlock_kernel(); 5271 mutex_unlock(&osst_int_mutex);
5271 5272
5272 return retval; 5273 return retval;
5273} 5274}
diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index a87e21c35ef2..02034460babb 100644
--- a/drivers/scsi/scsi_tgt_if.c
+++ b/drivers/scsi/scsi_tgt_if.c
@@ -22,7 +22,6 @@
22#include <linux/miscdevice.h> 22#include <linux/miscdevice.h>
23#include <linux/gfp.h> 23#include <linux/gfp.h>
24#include <linux/file.h> 24#include <linux/file.h>
25#include <linux/smp_lock.h>
26#include <net/tcp.h> 25#include <net/tcp.h>
27#include <scsi/scsi.h> 26#include <scsi/scsi.h>
28#include <scsi/scsi_cmnd.h> 27#include <scsi/scsi_cmnd.h>
@@ -323,7 +322,6 @@ static int tgt_open(struct inode *inode, struct file *file)
323{ 322{
324 tx_ring.tr_idx = rx_ring.tr_idx = 0; 323 tx_ring.tr_idx = rx_ring.tr_idx = 0;
325 324
326 cycle_kernel_lock();
327 return 0; 325 return 0;
328} 326}
329 327
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 78d616315d8e..b5507d59b5a6 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -49,7 +49,7 @@ static int sg_version_num = 30534; /* 2 digits for each component */
49#include <linux/blkdev.h> 49#include <linux/blkdev.h>
50#include <linux/delay.h> 50#include <linux/delay.h>
51#include <linux/blktrace_api.h> 51#include <linux/blktrace_api.h>
52#include <linux/smp_lock.h> 52#include <linux/mutex.h>
53 53
54#include "scsi.h" 54#include "scsi.h"
55#include <scsi/scsi_dbg.h> 55#include <scsi/scsi_dbg.h>
@@ -103,6 +103,8 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ;
103static int sg_add(struct device *, struct class_interface *); 103static int sg_add(struct device *, struct class_interface *);
104static void sg_remove(struct device *, struct class_interface *); 104static void sg_remove(struct device *, struct class_interface *);
105 105
106static DEFINE_MUTEX(sg_mutex);
107
106static DEFINE_IDR(sg_index_idr); 108static DEFINE_IDR(sg_index_idr);
107static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock 109static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock
108 file descriptor list for device */ 110 file descriptor list for device */
@@ -229,7 +231,7 @@ sg_open(struct inode *inode, struct file *filp)
229 int res; 231 int res;
230 int retval; 232 int retval;
231 233
232 lock_kernel(); 234 mutex_lock(&sg_mutex);
233 nonseekable_open(inode, filp); 235 nonseekable_open(inode, filp);
234 SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev, flags)); 236 SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev, flags));
235 sdp = sg_get_dev(dev); 237 sdp = sg_get_dev(dev);
@@ -314,7 +316,7 @@ sdp_put:
314sg_put: 316sg_put:
315 if (sdp) 317 if (sdp)
316 sg_put_dev(sdp); 318 sg_put_dev(sdp);
317 unlock_kernel(); 319 mutex_unlock(&sg_mutex);
318 return retval; 320 return retval;
319} 321}
320 322
@@ -1092,9 +1094,9 @@ sg_unlocked_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
1092{ 1094{
1093 int ret; 1095 int ret;
1094 1096
1095 lock_kernel(); 1097 mutex_lock(&sg_mutex);
1096 ret = sg_ioctl(filp, cmd_in, arg); 1098 ret = sg_ioctl(filp, cmd_in, arg);
1097 unlock_kernel(); 1099 mutex_unlock(&sg_mutex);
1098 1100
1099 return ret; 1101 return ret;
1100} 1102}
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index ba9c3e0387ce..e148341079b5 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -44,7 +44,6 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/blkdev.h> 45#include <linux/blkdev.h>
46#include <linux/mutex.h> 46#include <linux/mutex.h>
47#include <linux/smp_lock.h>
48#include <linux/slab.h> 47#include <linux/slab.h>
49#include <asm/uaccess.h> 48#include <asm/uaccess.h>
50 49
@@ -76,6 +75,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM);
76 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \ 75 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
77 CDC_MRW|CDC_MRW_W|CDC_RAM) 76 CDC_MRW|CDC_MRW_W|CDC_RAM)
78 77
78static DEFINE_MUTEX(sr_mutex);
79static int sr_probe(struct device *); 79static int sr_probe(struct device *);
80static int sr_remove(struct device *); 80static int sr_remove(struct device *);
81static int sr_done(struct scsi_cmnd *); 81static int sr_done(struct scsi_cmnd *);
@@ -470,24 +470,24 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode)
470 struct scsi_cd *cd; 470 struct scsi_cd *cd;
471 int ret = -ENXIO; 471 int ret = -ENXIO;
472 472
473 lock_kernel(); 473 mutex_lock(&sr_mutex);
474 cd = scsi_cd_get(bdev->bd_disk); 474 cd = scsi_cd_get(bdev->bd_disk);
475 if (cd) { 475 if (cd) {
476 ret = cdrom_open(&cd->cdi, bdev, mode); 476 ret = cdrom_open(&cd->cdi, bdev, mode);
477 if (ret) 477 if (ret)
478 scsi_cd_put(cd); 478 scsi_cd_put(cd);
479 } 479 }
480 unlock_kernel(); 480 mutex_unlock(&sr_mutex);
481 return ret; 481 return ret;
482} 482}
483 483
484static int sr_block_release(struct gendisk *disk, fmode_t mode) 484static int sr_block_release(struct gendisk *disk, fmode_t mode)
485{ 485{
486 struct scsi_cd *cd = scsi_cd(disk); 486 struct scsi_cd *cd = scsi_cd(disk);
487 lock_kernel(); 487 mutex_lock(&sr_mutex);
488 cdrom_release(&cd->cdi, mode); 488 cdrom_release(&cd->cdi, mode);
489 scsi_cd_put(cd); 489 scsi_cd_put(cd);
490 unlock_kernel(); 490 mutex_unlock(&sr_mutex);
491 return 0; 491 return 0;
492} 492}
493 493
@@ -499,7 +499,7 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
499 void __user *argp = (void __user *)arg; 499 void __user *argp = (void __user *)arg;
500 int ret; 500 int ret;
501 501
502 lock_kernel(); 502 mutex_lock(&sr_mutex);
503 503
504 /* 504 /*
505 * Send SCSI addressing ioctls directly to mid level, send other 505 * Send SCSI addressing ioctls directly to mid level, send other
@@ -529,7 +529,7 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
529 ret = scsi_ioctl(sdev, cmd, argp); 529 ret = scsi_ioctl(sdev, cmd, argp);
530 530
531out: 531out:
532 unlock_kernel(); 532 mutex_unlock(&sr_mutex);
533 return ret; 533 return ret;
534} 534}
535 535
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 24211d0efa6d..afdc3f5d915c 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -39,7 +39,6 @@ static const char *verstr = "20081215";
39#include <linux/cdev.h> 39#include <linux/cdev.h>
40#include <linux/delay.h> 40#include <linux/delay.h>
41#include <linux/mutex.h> 41#include <linux/mutex.h>
42#include <linux/smp_lock.h>
43 42
44#include <asm/uaccess.h> 43#include <asm/uaccess.h>
45#include <asm/dma.h> 44#include <asm/dma.h>
@@ -76,6 +75,7 @@ static const char *verstr = "20081215";
76#include "st_options.h" 75#include "st_options.h"
77#include "st.h" 76#include "st.h"
78 77
78static DEFINE_MUTEX(st_mutex);
79static int buffer_kbs; 79static int buffer_kbs;
80static int max_sg_segs; 80static int max_sg_segs;
81static int try_direct_io = TRY_DIRECT_IO; 81static int try_direct_io = TRY_DIRECT_IO;
@@ -1180,7 +1180,7 @@ static int st_open(struct inode *inode, struct file *filp)
1180 int dev = TAPE_NR(inode); 1180 int dev = TAPE_NR(inode);
1181 char *name; 1181 char *name;
1182 1182
1183 lock_kernel(); 1183 mutex_lock(&st_mutex);
1184 /* 1184 /*
1185 * We really want to do nonseekable_open(inode, filp); here, but some 1185 * We really want to do nonseekable_open(inode, filp); here, but some
1186 * versions of tar incorrectly call lseek on tapes and bail out if that 1186 * versions of tar incorrectly call lseek on tapes and bail out if that
@@ -1189,7 +1189,7 @@ static int st_open(struct inode *inode, struct file *filp)
1189 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); 1189 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
1190 1190
1191 if (!(STp = scsi_tape_get(dev))) { 1191 if (!(STp = scsi_tape_get(dev))) {
1192 unlock_kernel(); 1192 mutex_unlock(&st_mutex);
1193 return -ENXIO; 1193 return -ENXIO;
1194 } 1194 }
1195 1195
@@ -1200,7 +1200,7 @@ static int st_open(struct inode *inode, struct file *filp)
1200 if (STp->in_use) { 1200 if (STp->in_use) {
1201 write_unlock(&st_dev_arr_lock); 1201 write_unlock(&st_dev_arr_lock);
1202 scsi_tape_put(STp); 1202 scsi_tape_put(STp);
1203 unlock_kernel(); 1203 mutex_unlock(&st_mutex);
1204 DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); ) 1204 DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); )
1205 return (-EBUSY); 1205 return (-EBUSY);
1206 } 1206 }
@@ -1249,14 +1249,14 @@ static int st_open(struct inode *inode, struct file *filp)
1249 retval = (-EIO); 1249 retval = (-EIO);
1250 goto err_out; 1250 goto err_out;
1251 } 1251 }
1252 unlock_kernel(); 1252 mutex_unlock(&st_mutex);
1253 return 0; 1253 return 0;
1254 1254
1255 err_out: 1255 err_out:
1256 normalize_buffer(STp->buffer); 1256 normalize_buffer(STp->buffer);
1257 STp->in_use = 0; 1257 STp->in_use = 0;
1258 scsi_tape_put(STp); 1258 scsi_tape_put(STp);
1259 unlock_kernel(); 1259 mutex_unlock(&st_mutex);
1260 return retval; 1260 return retval;
1261 1261
1262} 1262}
diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index ff1d24720f11..8284297b30e9 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -25,7 +25,7 @@
25#include <linux/major.h> 25#include <linux/major.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/hdreg.h> 27#include <linux/hdreg.h>
28#include <linux/smp_lock.h> 28#include <linux/mutex.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <scsi/scsi.h> 30#include <scsi/scsi.h>
31#include <scsi/scsi_cmnd.h> 31#include <scsi/scsi_cmnd.h>
@@ -124,6 +124,7 @@ struct blkvsc_driver_context {
124}; 124};
125 125
126/* Static decl */ 126/* Static decl */
127static DEFINE_MUTEX(blkvsc_mutex);
127static int blkvsc_probe(struct device *dev); 128static int blkvsc_probe(struct device *dev);
128static int blkvsc_remove(struct device *device); 129static int blkvsc_remove(struct device *device);
129static void blkvsc_shutdown(struct device *device); 130static void blkvsc_shutdown(struct device *device);
@@ -1309,7 +1310,7 @@ static int blkvsc_open(struct block_device *bdev, fmode_t mode)
1309 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, 1310 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users,
1310 blkdev->gd->disk_name); 1311 blkdev->gd->disk_name);
1311 1312
1312 lock_kernel(); 1313 mutex_lock(&blkvsc_mutex);
1313 spin_lock(&blkdev->lock); 1314 spin_lock(&blkdev->lock);
1314 1315
1315 if (!blkdev->users && blkdev->device_type == DVD_TYPE) { 1316 if (!blkdev->users && blkdev->device_type == DVD_TYPE) {
@@ -1321,7 +1322,7 @@ static int blkvsc_open(struct block_device *bdev, fmode_t mode)
1321 blkdev->users++; 1322 blkdev->users++;
1322 1323
1323 spin_unlock(&blkdev->lock); 1324 spin_unlock(&blkdev->lock);
1324 unlock_kernel(); 1325 mutex_unlock(&blkvsc_mutex);
1325 return 0; 1326 return 0;
1326} 1327}
1327 1328
@@ -1332,7 +1333,7 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode)
1332 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, 1333 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users,
1333 blkdev->gd->disk_name); 1334 blkdev->gd->disk_name);
1334 1335
1335 lock_kernel(); 1336 mutex_lock(&blkvsc_mutex);
1336 spin_lock(&blkdev->lock); 1337 spin_lock(&blkdev->lock);
1337 if (blkdev->users == 1) { 1338 if (blkdev->users == 1) {
1338 spin_unlock(&blkdev->lock); 1339 spin_unlock(&blkdev->lock);
@@ -1343,7 +1344,7 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode)
1343 blkdev->users--; 1344 blkdev->users--;
1344 1345
1345 spin_unlock(&blkdev->lock); 1346 spin_unlock(&blkdev->lock);
1346 unlock_kernel(); 1347 mutex_unlock(&blkvsc_mutex);
1347 return 0; 1348 return 0;
1348} 1349}
1349 1350
diff --git a/drivers/staging/spectra/ffsport.c b/drivers/staging/spectra/ffsport.c
index fa21a0fd8e84..c7932da03c56 100644
--- a/drivers/staging/spectra/ffsport.c
+++ b/drivers/staging/spectra/ffsport.c
@@ -27,7 +27,6 @@
27#include <linux/kthread.h> 27#include <linux/kthread.h>
28#include <linux/log2.h> 28#include <linux/log2.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/smp_lock.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
32 31
33/**** Helper functions used for Div, Remainder operation on u64 ****/ 32/**** Helper functions used for Div, Remainder operation on u64 ****/
@@ -590,14 +589,16 @@ int GLOB_SBD_ioctl(struct block_device *bdev, fmode_t mode,
590 return -ENOTTY; 589 return -ENOTTY;
591} 590}
592 591
592static DEFINE_MUTEX(ffsport_mutex);
593
593int GLOB_SBD_unlocked_ioctl(struct block_device *bdev, fmode_t mode, 594int GLOB_SBD_unlocked_ioctl(struct block_device *bdev, fmode_t mode,
594 unsigned int cmd, unsigned long arg) 595 unsigned int cmd, unsigned long arg)
595{ 596{
596 int ret; 597 int ret;
597 598
598 lock_kernel(); 599 mutex_lock(&ffsport_mutex);
599 ret = GLOB_SBD_ioctl(bdev, mode, cmd, arg); 600 ret = GLOB_SBD_ioctl(bdev, mode, cmd, arg);
600 unlock_kernel(); 601 mutex_unlock(&ffsport_mutex);
601 602
602 return ret; 603 return ret;
603} 604}
diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
index b53deee25d74..b1e469983b1d 100644
--- a/drivers/telephony/ixj.c
+++ b/drivers/telephony/ixj.c
@@ -257,7 +257,7 @@
257#include <linux/fs.h> /* everything... */ 257#include <linux/fs.h> /* everything... */
258#include <linux/errno.h> /* error codes */ 258#include <linux/errno.h> /* error codes */
259#include <linux/slab.h> 259#include <linux/slab.h>
260#include <linux/smp_lock.h> 260#include <linux/mutex.h>
261#include <linux/mm.h> 261#include <linux/mm.h>
262#include <linux/ioport.h> 262#include <linux/ioport.h>
263#include <linux/interrupt.h> 263#include <linux/interrupt.h>
@@ -277,6 +277,7 @@
277#define TYPE(inode) (iminor(inode) >> 4) 277#define TYPE(inode) (iminor(inode) >> 4)
278#define NUM(inode) (iminor(inode) & 0xf) 278#define NUM(inode) (iminor(inode) & 0xf)
279 279
280static DEFINE_MUTEX(ixj_mutex);
280static int ixjdebug; 281static int ixjdebug;
281static int hertz = HZ; 282static int hertz = HZ;
282static int samplerate = 100; 283static int samplerate = 100;
@@ -6655,9 +6656,9 @@ static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long ar
6655static long ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg) 6656static long ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg)
6656{ 6657{
6657 long ret; 6658 long ret;
6658 lock_kernel(); 6659 mutex_lock(&ixj_mutex);
6659 ret = do_ixj_ioctl(file_p, cmd, arg); 6660 ret = do_ixj_ioctl(file_p, cmd, arg);
6660 unlock_kernel(); 6661 mutex_unlock(&ixj_mutex);
6661 return ret; 6662 return ret;
6662} 6663}
6663 6664
diff --git a/drivers/watchdog/cpwd.c b/drivers/watchdog/cpwd.c
index 566343b3c131..b7d96e6236a1 100644
--- a/drivers/watchdog/cpwd.c
+++ b/drivers/watchdog/cpwd.c
@@ -25,7 +25,7 @@
25#include <linux/ioport.h> 25#include <linux/ioport.h>
26#include <linux/timer.h> 26#include <linux/timer.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/smp_lock.h> 28#include <linux/mutex.h>
29#include <linux/io.h> 29#include <linux/io.h>
30#include <linux/of.h> 30#include <linux/of.h>
31#include <linux/of_device.h> 31#include <linux/of_device.h>
@@ -89,6 +89,7 @@ struct cpwd {
89 } devs[WD_NUMDEVS]; 89 } devs[WD_NUMDEVS];
90}; 90};
91 91
92static DEFINE_MUTEX(cpwd_mutex);
92static struct cpwd *cpwd_device; 93static struct cpwd *cpwd_device;
93 94
94/* Sun uses Altera PLD EPF8820ATC144-4 95/* Sun uses Altera PLD EPF8820ATC144-4
@@ -368,7 +369,7 @@ static int cpwd_open(struct inode *inode, struct file *f)
368{ 369{
369 struct cpwd *p = cpwd_device; 370 struct cpwd *p = cpwd_device;
370 371
371 lock_kernel(); 372 mutex_lock(&cpwd_mutex);
372 switch (iminor(inode)) { 373 switch (iminor(inode)) {
373 case WD0_MINOR: 374 case WD0_MINOR:
374 case WD1_MINOR: 375 case WD1_MINOR:
@@ -376,7 +377,7 @@ static int cpwd_open(struct inode *inode, struct file *f)
376 break; 377 break;
377 378
378 default: 379 default:
379 unlock_kernel(); 380 mutex_unlock(&cpwd_mutex);
380 return -ENODEV; 381 return -ENODEV;
381 } 382 }
382 383
@@ -386,13 +387,13 @@ static int cpwd_open(struct inode *inode, struct file *f)
386 IRQF_SHARED, DRIVER_NAME, p)) { 387 IRQF_SHARED, DRIVER_NAME, p)) {
387 printk(KERN_ERR PFX "Cannot register IRQ %d\n", 388 printk(KERN_ERR PFX "Cannot register IRQ %d\n",
388 p->irq); 389 p->irq);
389 unlock_kernel(); 390 mutex_unlock(&cpwd_mutex);
390 return -EBUSY; 391 return -EBUSY;
391 } 392 }
392 p->initialized = true; 393 p->initialized = true;
393 } 394 }
394 395
395 unlock_kernel(); 396 mutex_unlock(&cpwd_mutex);
396 397
397 return nonseekable_open(inode, f); 398 return nonseekable_open(inode, f);
398} 399}
@@ -482,9 +483,9 @@ static long cpwd_compat_ioctl(struct file *file, unsigned int cmd,
482 case WIOCSTART: 483 case WIOCSTART:
483 case WIOCSTOP: 484 case WIOCSTOP:
484 case WIOCGSTAT: 485 case WIOCGSTAT:
485 lock_kernel(); 486 mutex_lock(&cpwd_mutex);
486 rval = cpwd_ioctl(file, cmd, arg); 487 rval = cpwd_ioctl(file, cmd, arg);
487 unlock_kernel(); 488 mutex_unlock(&cpwd_mutex);
488 break; 489 break;
489 490
490 /* everything else is handled by the generic compat layer */ 491 /* everything else is handled by the generic compat layer */