Skip to content

Commit

Permalink
Add a bunch of cycle_kernel_lock() calls
Browse files Browse the repository at this point in the history
All of the open() functions which don't need the BKL on their face may
still depend on its acquisition to serialize opens against driver
initialization.  So make those functions acquire then release the BKL to be
on the safe side.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
  • Loading branch information
Jonathan Corbet committed Jun 20, 2008
1 parent 0b28067 commit f2b9857
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 55 deletions.
4 changes: 2 additions & 2 deletions arch/cris/arch-v10/drivers/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/smp_lock.h>
#include <linux/wait.h>
#include <asm/uaccess.h>
#include "i2c.h"
Expand Down Expand Up @@ -375,10 +376,9 @@ int __init eeprom_init(void)
}

/* Opens the device. */
/* BKL not needed: no global resources accessed */
static int eeprom_open(struct inode * inode, struct file * file)
{

cycle_kernel_lock();
if(iminor(inode) != EEPROM_MINOR_NR)
return -ENXIO;
if(imajor(inode) != EEPROM_MAJOR_NR)
Expand Down
2 changes: 2 additions & 0 deletions arch/cris/arch-v10/drivers/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/fs.h>
Expand Down Expand Up @@ -566,6 +567,7 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg)
static int
i2c_open(struct inode *inode, struct file *filp)
{
cycle_kernel_lock();
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion arch/cris/arch-v32/drivers/cryptocop.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/smp_lock.h>
#include <linux/spinlock.h>
#include <linux/stddef.h>

Expand Down Expand Up @@ -2302,11 +2303,11 @@ static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_
return 0;
}

/* No BKL needed here - no global resources accessed */
static int cryptocop_open(struct inode *inode, struct file *filp)
{
int p = iminor(inode);

cycle_kernel_lock();
if (p != CRYPTOCOP_MINOR) return -EINVAL;

filp->private_data = NULL;
Expand Down
2 changes: 2 additions & 0 deletions arch/cris/arch-v32/drivers/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/smp_lock.h>

#include <asm/etraxi2c.h>

Expand Down Expand Up @@ -636,6 +637,7 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg)
static int
i2c_open(struct inode *inode, struct file *filp)
{
cycle_kernel_lock();
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/char/cs5535_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/cdev.h>
#include <linux/ioport.h>
#include <linux/pci.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include <asm/io.h>

Expand Down Expand Up @@ -153,12 +154,11 @@ static ssize_t cs5535_gpio_read(struct file *file, char __user *buf,
return count;
}

/* No BKL needed here - "mask" is the only global resource used
here and it's a boot-time parameter */
static int cs5535_gpio_open(struct inode *inode, struct file *file)
{
u32 m = iminor(inode);

cycle_kernel_lock();
/* the mask says which pins are usable by this driver */
if ((mask & (1 << m)) == 0)
return -EINVAL;
Expand Down
5 changes: 3 additions & 2 deletions drivers/char/dtlk.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <linux/errno.h> /* for -EBUSY */
#include <linux/ioport.h> /* for request_region */
#include <linux/delay.h> /* for loops_per_jiffy */
#include <linux/smp_lock.h> /* cycle_kernel_lock() */
#include <asm/io.h> /* for inb_p, outb_p, inb, outb, etc. */
#include <asm/uaccess.h> /* for get_user, etc. */
#include <linux/wait.h> /* for wait_queue */
Expand Down Expand Up @@ -288,12 +289,12 @@ static int dtlk_ioctl(struct inode *inode,
}
}

/* No BKL needed here; "dtlk_busy" is the only global resource,
and it is not ever set by anybody (test is broken) */
/* Note that nobody ever sets dtlk_busy... */
static int dtlk_open(struct inode *inode, struct file *file)
{
TRACE_TEXT("(dtlk_open");

cycle_kernel_lock();
nonseekable_open(inode, file);
switch (iminor(inode)) {
case DTLK_MINOR:
Expand Down
34 changes: 2 additions & 32 deletions drivers/char/ip2/ip2main.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
#include <linux/major.h>
#include <linux/wait.h>
#include <linux/device.h>
#include <linux/smp_lock.h>

#include <linux/tty.h>
#include <linux/tty_flip.h>
Expand Down Expand Up @@ -2931,42 +2932,11 @@ ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
static int
ip2_ipl_open( struct inode *pInode, struct file *pFile )
{
unsigned int iplminor = iminor(pInode);
i2eBordStrPtr pB;
i2ChanStrPtr pCh;

#ifdef IP2DEBUG_IPL
printk (KERN_DEBUG "IP2IPL: open\n" );
#endif

switch(iplminor) {
// These are the IPL devices
case 0:
case 4:
case 8:
case 12:
break;

// These are the status devices
case 1:
case 5:
case 9:
case 13:
break;

// These are the debug devices
case 2:
case 6:
case 10:
case 14:
pB = i2BoardPtrTable[iplminor / 4];
pCh = (i2ChanStrPtr) pB->i2eChannelPtr;
break;

// This is the trace device
case 3:
break;
}
cycle_kernel_lock();
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion drivers/char/pc8736x_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/mutex.h>
#include <linux/nsc_gpio.h>
#include <linux/platform_device.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>

#define DEVNAME "pc8736x_gpio"
Expand Down Expand Up @@ -212,12 +213,12 @@ static struct nsc_gpio_ops pc8736x_gpio_ops = {
.gpio_current = pc8736x_gpio_current
};

/* No BKL needed here; no global resources accessed */
static int pc8736x_gpio_open(struct inode *inode, struct file *file)
{
unsigned m = iminor(inode);
file->private_data = &pc8736x_gpio_ops;

cycle_kernel_lock();
dev_dbg(&pdev->dev, "open %d\n", m);

if (m >= PC8736X_GPIO_CT)
Expand Down
3 changes: 2 additions & 1 deletion drivers/char/ppdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include <linux/poll.h>
#include <linux/major.h>
#include <linux/ppdev.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>

#define PP_VERSION "ppdev: user-space parallel port driver"
Expand Down Expand Up @@ -633,12 +634,12 @@ static int pp_ioctl(struct inode *inode, struct file *file,
return 0;
}

/* No BKL needed here: only local resources used */
static int pp_open (struct inode * inode, struct file * file)
{
unsigned int minor = iminor(inode);
struct pp_struct *pp;

cycle_kernel_lock();
if (minor >= PARPORT_MAX)
return -ENXIO;

Expand Down
3 changes: 2 additions & 1 deletion drivers/char/scx200_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include <asm/io.h>

Expand Down Expand Up @@ -46,12 +47,12 @@ struct nsc_gpio_ops scx200_gpio_ops = {
};
EXPORT_SYMBOL_GPL(scx200_gpio_ops);

/* No BKL needed here: no global resources used */
static int scx200_gpio_open(struct inode *inode, struct file *file)
{
unsigned m = iminor(inode);
file->private_data = &scx200_gpio_ops;

cycle_kernel_lock();
if (m >= MAX_PINS)
return -EINVAL;
return nonseekable_open(inode, file);
Expand Down
3 changes: 2 additions & 1 deletion drivers/char/tb0219.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/smp_lock.h>

#include <asm/io.h>
#include <asm/reboot.h>
Expand Down Expand Up @@ -232,11 +233,11 @@ static ssize_t tanbac_tb0219_write(struct file *file, const char __user *data,
return i;
}

/* No BKL needed here; no global resources accessed */
static int tanbac_tb0219_open(struct inode *inode, struct file *file)
{
unsigned int minor;

cycle_kernel_lock();
minor = iminor(inode);
switch (minor) {
case 0:
Expand Down
4 changes: 2 additions & 2 deletions drivers/char/vr41xx_giu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/smp_lock.h>
#include <linux/spinlock.h>
#include <linux/types.h>

Expand Down Expand Up @@ -543,12 +544,11 @@ static ssize_t gpio_write(struct file *file, const char __user *data,
return i;
}

/* No BKL needed here; only global (giu_nr_pins) is only set
at probe time */
static int gpio_open(struct inode *inode, struct file *file)
{
unsigned int pin;

cycle_kernel_lock();
pin = iminor(inode);
if (pin >= giu_nr_pins)
return -EBADF;
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/core/ucm.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <linux/cdev.h>
#include <linux/idr.h>
#include <linux/mutex.h>
#include <linux/smp_lock.h>

#include <asm/uaccess.h>

Expand Down Expand Up @@ -1155,11 +1156,11 @@ static unsigned int ib_ucm_poll(struct file *filp,
return mask;
}

/* No BKL needed here: no global resources used */
static int ib_ucm_open(struct inode *inode, struct file *filp)
{
struct ib_ucm_file *file;

cycle_kernel_lock();
file = kmalloc(sizeof(*file), GFP_KERNEL);
if (!file)
return -ENOMEM;
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/ipath/ipath_file_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <linux/highmem.h>
#include <linux/io.h>
#include <linux/jiffies.h>
#include <linux/smp_lock.h>
#include <asm/pgtable.h>

#include "ipath_kernel.h"
Expand Down Expand Up @@ -1812,10 +1813,10 @@ static int find_shared_port(struct file *fp,
return ret;
}

/* No BKL needed here */
static int ipath_open(struct inode *in, struct file *fp)
{
/* The real work is performed later in ipath_assign_port() */
cycle_kernel_lock();
fp->private_data = kzalloc(sizeof(struct ipath_filedata), GFP_KERNEL);
return fp->private_data ? 0 : -ENOMEM;
}
Expand Down
2 changes: 2 additions & 0 deletions drivers/isdn/hardware/eicon/divasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/poll.h>
#include <linux/proc_fs.h>
#include <linux/skbuff.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>

#include "platform.h"
Expand Down Expand Up @@ -400,6 +401,7 @@ static unsigned int um_idi_poll(struct file *file, poll_table * wait)

static int um_idi_open(struct inode *inode, struct file *file)
{
cycle_kernel_lock();
return (0);
}

Expand Down
2 changes: 2 additions & 0 deletions drivers/isdn/hardware/eicon/divasmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/list.h>
#include <linux/poll.h>
#include <linux/kmod.h>
#include <linux/smp_lock.h>

#include "platform.h"
#undef ID_MASK
Expand Down Expand Up @@ -580,6 +581,7 @@ xdi_copy_from_user(void *os_handle, void *dst, const void __user *src, int lengt
*/
static int divas_open(struct inode *inode, struct file *file)
{
cycle_kernel_lock();
return (0);
}

Expand Down
3 changes: 2 additions & 1 deletion drivers/net/ppp_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <linux/if_arp.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/smp_lock.h>
#include <linux/spinlock.h>
#include <linux/rwsem.h>
#include <linux/stddef.h>
Expand Down Expand Up @@ -351,9 +352,9 @@ static const int npindex_to_ethertype[NUM_NP] = {
* Open instances of /dev/ppp can be in one of three states:
* unattached, attached to a ppp unit, or attached to a ppp channel.
*/
/* No BKL needed here */
static int ppp_open(struct inode *inode, struct file *file)
{
cycle_kernel_lock();
/*
* This could (should?) be enforced by the permissions on /dev/ppp.
*/
Expand Down
5 changes: 3 additions & 2 deletions drivers/scsi/3w-9xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include <linux/pci.h>
#include <linux/time.h>
#include <linux/mutex.h>
#include <linux/smp_lock.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
Expand Down Expand Up @@ -862,13 +863,13 @@ static int twa_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
} /* End twa_chrdev_ioctl() */

/* This function handles open for the character device */
/* NOTE that this function will race with remove; adding BKL
will not help. */
/* NOTE that this function will race with remove. */
static int twa_chrdev_open(struct inode *inode, struct file *file)
{
unsigned int minor_number;
int retval = TW_IOCTL_ERROR_OS_ENODEV;

cycle_kernel_lock();
minor_number = iminor(inode);
if (minor_number >= twa_device_extension_count)
goto out;
Expand Down
Loading

0 comments on commit f2b9857

Please sign in to comment.