Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a48fc0a authored by Arnd Bergmann's avatar Arnd Bergmann
Browse files

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: default avatarArnd Bergmann <arnd@arndb.de>
parent 613655fa
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@
#include <linux/uio.h>
#include <linux/uio.h>
#include <linux/idr.h>
#include <linux/idr.h>
#include <linux/bsg.h>
#include <linux/bsg.h>
#include <linux/smp_lock.h>
#include <linux/slab.h>
#include <linux/slab.h>


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


	lock_kernel();
	bd = bsg_get_device(inode, file);
	bd = bsg_get_device(inode, file);
	unlock_kernel();


	if (IS_ERR(bd))
	if (IS_ERR(bd))
		return PTR_ERR(bd);
		return PTR_ERR(bd);
+6 −5
Original line number Original line Diff line number Diff line
@@ -36,7 +36,7 @@
#include <linux/ioport.h>
#include <linux/ioport.h>
#include <linux/mm.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/seq_file.h>
#include <linux/reboot.h>
#include <linux/reboot.h>
@@ -54,6 +54,7 @@
#define DAC960_GAM_MINOR	252
#define DAC960_GAM_MINOR	252




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


	lock_kernel();
	mutex_lock(&DAC960_mutex);
	if (p->FirmwareType == DAC960_V1_Controller) {
	if (p->FirmwareType == DAC960_V1_Controller) {
		if (p->V1.LogicalDriveInformation[drive_nr].
		if (p->V1.LogicalDriveInformation[drive_nr].
		    LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
		    LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
@@ -99,7 +100,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
		goto out;
		goto out;
	ret = 0;
	ret = 0;
out:
out:
	unlock_kernel();
	mutex_unlock(&DAC960_mutex);
	return ret;
	return ret;
}
}


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


  lock_kernel();
  mutex_lock(&DAC960_mutex);
  switch (Request)
  switch (Request)
    {
    {
    case DAC960_IOCTL_GET_CONTROLLER_COUNT:
    case DAC960_IOCTL_GET_CONTROLLER_COUNT:
@@ -7056,7 +7057,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
      default:
      default:
	ErrorCode = -ENOTTY;
	ErrorCode = -ENOTTY;
    }
    }
  unlock_kernel();
  mutex_unlock(&DAC960_mutex);
  return ErrorCode;
  return ErrorCode;
}
}


+10 −9
Original line number Original line Diff line number Diff line
@@ -60,7 +60,7 @@
#include <linux/hdreg.h>
#include <linux/hdreg.h>
#include <linux/delay.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/init.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/amifdreg.h>
#include <linux/amifdreg.h>
#include <linux/amifd.h>
#include <linux/amifd.h>
#include <linux/buffer_head.h>
#include <linux/buffer_head.h>
@@ -109,6 +109,7 @@
#define FD_HD_3 	0x55555555  /* high-density 3.5" (1760K) drive */
#define FD_HD_3 	0x55555555  /* high-density 3.5" (1760K) drive */
#define FD_DD_5 	0xaaaaaaaa  /* double-density 5.25" (440K) drive */
#define FD_DD_5 	0xaaaaaaaa  /* double-density 5.25" (440K) drive */


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


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


	lock_kernel();
	mutex_lock(&amiflop_mutex);
	ret = fd_locked_ioctl(bdev, mode, cmd, param);
	ret = fd_locked_ioctl(bdev, mode, cmd, param);
	unlock_kernel();
	mutex_unlock(&amiflop_mutex);


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


	lock_kernel();
	mutex_lock(&amiflop_mutex);
	old_dev = fd_device[drive];
	old_dev = fd_device[drive];


	if (fd_ref[drive] && old_dev != system) {
	if (fd_ref[drive] && old_dev != system) {
		unlock_kernel();
		mutex_unlock(&amiflop_mutex);
		return -EBUSY;
		return -EBUSY;
	}
	}


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


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


	unlock_kernel();
	mutex_unlock(&amiflop_mutex);
	return 0;
	return 0;
}
}


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


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


+5 −4
Original line number Original line Diff line number Diff line
@@ -12,9 +12,10 @@
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/genhd.h>
#include <linux/genhd.h>
#include <linux/netdevice.h>
#include <linux/netdevice.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include "aoe.h"
#include "aoe.h"


static DEFINE_MUTEX(aoeblk_mutex);
static struct kmem_cache *buf_pool_cache;
static struct kmem_cache *buf_pool_cache;


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


	lock_kernel();
	mutex_lock(&aoeblk_mutex);
	spin_lock_irqsave(&d->lock, flags);
	spin_lock_irqsave(&d->lock, flags);
	if (d->flags & DEVFL_UP) {
	if (d->flags & DEVFL_UP) {
		d->nopen++;
		d->nopen++;
		spin_unlock_irqrestore(&d->lock, flags);
		spin_unlock_irqrestore(&d->lock, flags);
		unlock_kernel();
		mutex_unlock(&aoeblk_mutex);
		return 0;
		return 0;
	}
	}
	spin_unlock_irqrestore(&d->lock, flags);
	spin_unlock_irqrestore(&d->lock, flags);
	unlock_kernel();
	mutex_unlock(&aoeblk_mutex);
	return -ENODEV;
	return -ENODEV;
}
}


+5 −4
Original line number Original line Diff line number Diff line
@@ -9,7 +9,7 @@
#include <linux/completion.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
#include "aoe.h"
#include "aoe.h"


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


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


	lock_kernel();
	mutex_lock(&aoechr_mutex);
	n = iminor(inode);
	n = iminor(inode);
	filp->private_data = (void *) (unsigned long) n;
	filp->private_data = (void *) (unsigned long) n;


	for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
	for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
		if (chardevs[i].minor == n) {
		if (chardevs[i].minor == n) {
			unlock_kernel();
			mutex_unlock(&aoechr_mutex);
			return 0;
			return 0;
		}
		}
	unlock_kernel();
	mutex_unlock(&aoechr_mutex);
	return -EINVAL;
	return -EINVAL;
}
}


Loading