Commit f2b9857e authored by Jonathan Corbet's avatar Jonathan Corbet

Add a bunch of cycle_kernel_lock() calls

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: default avatarJonathan Corbet <corbet@lwn.net>
parent 0b280676
......@@ -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"
......@@ -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)
......
......@@ -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>
......@@ -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;
}
......
......@@ -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>
......@@ -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;
......
......@@ -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>
......@@ -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;
}
......
......@@ -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>
......@@ -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;
......
......@@ -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 */
......@@ -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:
......
......@@ -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>
......@@ -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;
}
......
......@@ -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"
......@@ -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)
......
......@@ -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"
......@@ -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;
......
......@@ -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>
......@@ -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);
......
......@@ -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>
......@@ -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:
......
......@@ -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>
......@@ -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;
......
......@@ -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>
......@@ -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;
......
......@@ -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"
......@@ -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;
}
......
......@@ -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"
......@@ -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);
}
......
......@@ -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
......@@ -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);
}
......
......@@ -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>
......@@ -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.
*/
......
......@@ -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>
......@@ -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;
......
......@@ -198,6 +198,7 @@
#include <linux/module.h>
#include <linux/reboot.h>
#include <linux/smp_lock.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/moduleparam.h>
......@@ -1027,12 +1028,12 @@ static int tw_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
} /* End tw_chrdev_ioctl() */
/* This function handles open for the character device */
/* NOTE that this function races with remove - adding BKL
won't help */
/* NOTE that this function races with remove. */
static int tw_chrdev_open(struct inode *inode, struct file *file)
{
unsigned int minor_number;
cycle_kernel_lock();
dprintk(KERN_WARNING "3w-xxxx: tw_ioctl_open()\n");
minor_number = iminor(inode);
......
......@@ -46,6 +46,7 @@
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/dma-mapping.h>
#include <linux/smp_lock.h>
#include <scsi/scsicam.h>
#include "scsi.h"
......@@ -3273,12 +3274,11 @@ mega_init_scb(adapter_t *adapter)
*
* Routines for the character/ioctl interface to the driver. Find out if this
* is a valid open.
*
* No BKL needed here.
*/
static int
megadev_open (struct inode *inode, struct file *filep)
{
cycle_kernel_lock();
/*
* Only allow superuser to access private ioctl interface
*/
......
......@@ -33,6 +33,7 @@
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/smp_lock.h>
#include <linux/uio.h>
#include <asm/uaccess.h>
#include <linux/fs.h>
......@@ -2860,10 +2861,10 @@ static void megasas_shutdown(struct pci_dev *pdev)
/**
* megasas_mgmt_open - char node "open" entry point
* No BKL is needed here.
*/
static int megasas_mgmt_open(struct inode *inode, struct file *filep)
{
cycle_kernel_lock();
/*
* Allow only those users with admin rights
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment