Skip to content

Commit 2a48fc0

Browse files
committed
block: autoconvert trivial BKL users to private mutex
The block device drivers have all gained new lock_kernel calls from a recent pushdown, and some of the drivers were already using the BKL before. This turns the BKL into a set of per-driver mutexes. Still need to check whether this is safe to do. file=$1 name=$2 if grep -q lock_kernel ${file} ; then if grep -q 'include.*linux.mutex.h' ${file} ; then sed -i '/include.*<linux\/smp_lock.h>/d' ${file} else sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file} fi sed -i ${file} \ -e "/^#include.*linux.mutex.h/,$ { 1,/^\(static\|int\|long\)/ { /^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex); } }" \ -e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \ -e '/[ ]*cycle_kernel_lock();/d' else sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \ -e '/cycle_kernel_lock()/d' fi Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent 613655f commit 2a48fc0

43 files changed

Lines changed: 277 additions & 250 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎block/bsg.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <linux/uio.h>
2121
#include <linux/idr.h>
2222
#include <linux/bsg.h>
23-
#include <linux/smp_lock.h>
2423
#include <linux/slab.h>
2524

2625
#include <scsi/scsi.h>
@@ -843,9 +842,7 @@ static int bsg_open(struct inode *inode, struct file *file)
843842
{
844843
struct bsg_device *bd;
845844

846-
lock_kernel();
847845
bd = bsg_get_device(inode, file);
848-
unlock_kernel();
849846

850847
if (IS_ERR(bd))
851848
return PTR_ERR(bd);

‎drivers/block/DAC960.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <linux/ioport.h>
3737
#include <linux/mm.h>
3838
#include <linux/slab.h>
39-
#include <linux/smp_lock.h>
39+
#include <linux/mutex.h>
4040
#include <linux/proc_fs.h>
4141
#include <linux/seq_file.h>
4242
#include <linux/reboot.h>
@@ -54,6 +54,7 @@
5454
#define DAC960_GAM_MINOR 252
5555

5656

57+
static DEFINE_MUTEX(DAC960_mutex);
5758
static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];
5859
static int DAC960_ControllerCount;
5960
static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
@@ -81,7 +82,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
8182
int drive_nr = (long)disk->private_data;
8283
int ret = -ENXIO;
8384

84-
lock_kernel();
85+
mutex_lock(&DAC960_mutex);
8586
if (p->FirmwareType == DAC960_V1_Controller) {
8687
if (p->V1.LogicalDriveInformation[drive_nr].
8788
LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
@@ -99,7 +100,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
99100
goto out;
100101
ret = 0;
101102
out:
102-
unlock_kernel();
103+
mutex_unlock(&DAC960_mutex);
103104
return ret;
104105
}
105106

@@ -6625,7 +6626,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
66256626
long ErrorCode = 0;
66266627
if (!capable(CAP_SYS_ADMIN)) return -EACCES;
66276628

6628-
lock_kernel();
6629+
mutex_lock(&DAC960_mutex);
66296630
switch (Request)
66306631
{
66316632
case DAC960_IOCTL_GET_CONTROLLER_COUNT:
@@ -7056,7 +7057,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
70567057
default:
70577058
ErrorCode = -ENOTTY;
70587059
}
7059-
unlock_kernel();
7060+
mutex_unlock(&DAC960_mutex);
70607061
return ErrorCode;
70617062
}
70627063

‎drivers/block/amiflop.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#include <linux/hdreg.h>
6161
#include <linux/delay.h>
6262
#include <linux/init.h>
63-
#include <linux/smp_lock.h>
63+
#include <linux/mutex.h>
6464
#include <linux/amifdreg.h>
6565
#include <linux/amifd.h>
6666
#include <linux/buffer_head.h>
@@ -109,6 +109,7 @@
109109
#define FD_HD_3 0x55555555 /* high-density 3.5" (1760K) drive */
110110
#define FD_DD_5 0xaaaaaaaa /* double-density 5.25" (440K) drive */
111111

112+
static DEFINE_MUTEX(amiflop_mutex);
112113
static unsigned long int fd_def_df0 = FD_DD_3; /* default for df0 if it doesn't identify */
113114

114115
module_param(fd_def_df0, ulong, 0);
@@ -1506,9 +1507,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
15061507
{
15071508
int ret;
15081509

1509-
lock_kernel();
1510+
mutex_lock(&amiflop_mutex);
15101511
ret = fd_locked_ioctl(bdev, mode, cmd, param);
1511-
unlock_kernel();
1512+
mutex_unlock(&amiflop_mutex);
15121513

15131514
return ret;
15141515
}
@@ -1555,11 +1556,11 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
15551556
int old_dev;
15561557
unsigned long flags;
15571558

1558-
lock_kernel();
1559+
mutex_lock(&amiflop_mutex);
15591560
old_dev = fd_device[drive];
15601561

15611562
if (fd_ref[drive] && old_dev != system) {
1562-
unlock_kernel();
1563+
mutex_unlock(&amiflop_mutex);
15631564
return -EBUSY;
15641565
}
15651566

@@ -1575,7 +1576,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
15751576
rel_fdc();
15761577

15771578
if (wrprot) {
1578-
unlock_kernel();
1579+
mutex_unlock(&amiflop_mutex);
15791580
return -EROFS;
15801581
}
15811582
}
@@ -1594,7 +1595,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
15941595
printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive,
15951596
unit[drive].type->name, data_types[system].name);
15961597

1597-
unlock_kernel();
1598+
mutex_unlock(&amiflop_mutex);
15981599
return 0;
15991600
}
16001601

@@ -1603,7 +1604,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
16031604
struct amiga_floppy_struct *p = disk->private_data;
16041605
int drive = p - unit;
16051606

1606-
lock_kernel();
1607+
mutex_lock(&amiflop_mutex);
16071608
if (unit[drive].dirty == 1) {
16081609
del_timer (flush_track_timer + drive);
16091610
non_int_flush_track (drive);
@@ -1617,7 +1618,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
16171618
/* the mod_use counter is handled this way */
16181619
floppy_off (drive | 0x40000000);
16191620
#endif
1620-
unlock_kernel();
1621+
mutex_unlock(&amiflop_mutex);
16211622
return 0;
16221623
}
16231624

‎drivers/block/aoe/aoeblk.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
#include <linux/slab.h>
1313
#include <linux/genhd.h>
1414
#include <linux/netdevice.h>
15-
#include <linux/smp_lock.h>
15+
#include <linux/mutex.h>
1616
#include "aoe.h"
1717

18+
static DEFINE_MUTEX(aoeblk_mutex);
1819
static struct kmem_cache *buf_pool_cache;
1920

2021
static ssize_t aoedisk_show_state(struct device *dev,
@@ -125,16 +126,16 @@ aoeblk_open(struct block_device *bdev, fmode_t mode)
125126
struct aoedev *d = bdev->bd_disk->private_data;
126127
ulong flags;
127128

128-
lock_kernel();
129+
mutex_lock(&aoeblk_mutex);
129130
spin_lock_irqsave(&d->lock, flags);
130131
if (d->flags & DEVFL_UP) {
131132
d->nopen++;
132133
spin_unlock_irqrestore(&d->lock, flags);
133-
unlock_kernel();
134+
mutex_unlock(&aoeblk_mutex);
134135
return 0;
135136
}
136137
spin_unlock_irqrestore(&d->lock, flags);
137-
unlock_kernel();
138+
mutex_unlock(&aoeblk_mutex);
138139
return -ENODEV;
139140
}
140141

‎drivers/block/aoe/aoechr.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <linux/completion.h>
1010
#include <linux/delay.h>
1111
#include <linux/slab.h>
12-
#include <linux/smp_lock.h>
12+
#include <linux/mutex.h>
1313
#include <linux/skbuff.h>
1414
#include "aoe.h"
1515

@@ -37,6 +37,7 @@ struct ErrMsg {
3737
char *msg;
3838
};
3939

40+
static DEFINE_MUTEX(aoechr_mutex);
4041
static struct ErrMsg emsgs[NMSG];
4142
static int emsgs_head_idx, emsgs_tail_idx;
4243
static struct completion emsgs_comp;
@@ -183,16 +184,16 @@ aoechr_open(struct inode *inode, struct file *filp)
183184
{
184185
int n, i;
185186

186-
lock_kernel();
187+
mutex_lock(&aoechr_mutex);
187188
n = iminor(inode);
188189
filp->private_data = (void *) (unsigned long) n;
189190

190191
for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
191192
if (chardevs[i].minor == n) {
192-
unlock_kernel();
193+
mutex_unlock(&aoechr_mutex);
193194
return 0;
194195
}
195-
unlock_kernel();
196+
mutex_unlock(&aoechr_mutex);
196197
return -EINVAL;
197198
}
198199

‎drivers/block/ataflop.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#include <linux/delay.h>
6868
#include <linux/init.h>
6969
#include <linux/blkdev.h>
70-
#include <linux/smp_lock.h>
70+
#include <linux/mutex.h>
7171

7272
#include <asm/atafd.h>
7373
#include <asm/atafdreg.h>
@@ -79,6 +79,7 @@
7979

8080
#undef DEBUG
8181

82+
static DEFINE_MUTEX(ataflop_mutex);
8283
static struct request_queue *floppy_queue;
8384
static struct request *fd_request;
8485

@@ -1671,9 +1672,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
16711672
{
16721673
int ret;
16731674

1674-
lock_kernel();
1675+
mutex_lock(&ataflop_mutex);
16751676
ret = fd_locked_ioctl(bdev, mode, cmd, arg);
1676-
unlock_kernel();
1677+
mutex_unlock(&ataflop_mutex);
16771678

16781679
return ret;
16791680
}
@@ -1854,24 +1855,24 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
18541855
{
18551856
int ret;
18561857

1857-
lock_kernel();
1858+
mutex_lock(&ataflop_mutex);
18581859
ret = floppy_open(bdev, mode);
1859-
unlock_kernel();
1860+
mutex_unlock(&ataflop_mutex);
18601861

18611862
return ret;
18621863
}
18631864

18641865
static int floppy_release(struct gendisk *disk, fmode_t mode)
18651866
{
18661867
struct atari_floppy_struct *p = disk->private_data;
1867-
lock_kernel();
1868+
mutex_lock(&ataflop_mutex);
18681869
if (p->ref < 0)
18691870
p->ref = 0;
18701871
else if (!p->ref--) {
18711872
printk(KERN_ERR "floppy_release with fd_ref == 0");
18721873
p->ref = 0;
18731874
}
1874-
unlock_kernel();
1875+
mutex_unlock(&ataflop_mutex);
18751876
return 0;
18761877
}
18771878

‎drivers/block/brd.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <linux/blkdev.h>
1616
#include <linux/bio.h>
1717
#include <linux/highmem.h>
18-
#include <linux/smp_lock.h>
18+
#include <linux/mutex.h>
1919
#include <linux/radix-tree.h>
2020
#include <linux/buffer_head.h> /* invalidate_bh_lrus() */
2121
#include <linux/slab.h>
@@ -55,6 +55,7 @@ struct brd_device {
5555
/*
5656
* Look up and return a brd's page for a given sector.
5757
*/
58+
static DEFINE_MUTEX(brd_mutex);
5859
static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)
5960
{
6061
pgoff_t idx;
@@ -402,7 +403,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
402403
* ram device BLKFLSBUF has special semantics, we want to actually
403404
* release and destroy the ramdisk data.
404405
*/
405-
lock_kernel();
406+
mutex_lock(&brd_mutex);
406407
mutex_lock(&bdev->bd_mutex);
407408
error = -EBUSY;
408409
if (bdev->bd_openers <= 1) {
@@ -419,7 +420,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
419420
error = 0;
420421
}
421422
mutex_unlock(&bdev->bd_mutex);
422-
unlock_kernel();
423+
mutex_unlock(&brd_mutex);
423424

424425
return error;
425426
}

‎drivers/block/cciss.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <linux/pci.h>
2727
#include <linux/kernel.h>
2828
#include <linux/slab.h>
29-
#include <linux/smp_lock.h>
3029
#include <linux/delay.h>
3130
#include <linux/major.h>
3231
#include <linux/fs.h>
@@ -66,6 +65,7 @@ MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");
6665
MODULE_VERSION("3.6.26");
6766
MODULE_LICENSE("GPL");
6867

68+
static DEFINE_MUTEX(cciss_mutex);
6969
static int cciss_allow_hpsa;
7070
module_param(cciss_allow_hpsa, int, S_IRUGO|S_IWUSR);
7171
MODULE_PARM_DESC(cciss_allow_hpsa,
@@ -1059,9 +1059,9 @@ static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode)
10591059
{
10601060
int ret;
10611061

1062-
lock_kernel();
1062+
mutex_lock(&cciss_mutex);
10631063
ret = cciss_open(bdev, mode);
1064-
unlock_kernel();
1064+
mutex_unlock(&cciss_mutex);
10651065

10661066
return ret;
10671067
}
@@ -1074,23 +1074,23 @@ static int cciss_release(struct gendisk *disk, fmode_t mode)
10741074
ctlr_info_t *h;
10751075
drive_info_struct *drv;
10761076

1077-
lock_kernel();
1077+
mutex_lock(&cciss_mutex);
10781078
h = get_host(disk);
10791079
drv = get_drv(disk);
10801080
dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name);
10811081
drv->usage_count--;
10821082
h->usage_count--;
1083-
unlock_kernel();
1083+
mutex_unlock(&cciss_mutex);
10841084
return 0;
10851085
}
10861086

10871087
static int do_ioctl(struct block_device *bdev, fmode_t mode,
10881088
unsigned cmd, unsigned long arg)
10891089
{
10901090
int ret;
1091-
lock_kernel();
1091+
mutex_lock(&cciss_mutex);
10921092
ret = cciss_ioctl(bdev, mode, cmd, arg);
1093-
unlock_kernel();
1093+
mutex_unlock(&cciss_mutex);
10941094
return ret;
10951095
}
10961096

0 commit comments

Comments
 (0)