Skip to content

Commit

Permalink
drivers: Push down BKL into various drivers
Browse files Browse the repository at this point in the history
These are the last remaining device drivers using
the ->ioctl file operation in the drivers directory
(except from v4l drivers).

[fweisbec: drop i8k pushdown as it has been done from
procfs pushdown branch already]

Signed-off-by: Arnd Bergmann <[email protected]>
Signed-off-by: Frederic Weisbecker <[email protected]>
  • Loading branch information
arndb authored and fweisbec committed May 17, 2010
1 parent 703c631 commit 5592933
Show file tree
Hide file tree
Showing 23 changed files with 280 additions and 115 deletions.
8 changes: 5 additions & 3 deletions drivers/char/apm-emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,16 @@ static unsigned int apm_poll(struct file *fp, poll_table * wait)
* Only when everyone who has opened /dev/apm_bios with write permission
* has acknowledge does the actual suspend happen.
*/
static int
apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
static long
apm_ioctl(struct file *filp, u_int cmd, u_long arg)
{
struct apm_user *as = filp->private_data;
int err = -EINVAL;

if (!as->suser || !as->writer)
return -EPERM;

lock_kernel();
switch (cmd) {
case APM_IOC_SUSPEND:
mutex_lock(&state_lock);
Expand Down Expand Up @@ -334,6 +335,7 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
mutex_unlock(&state_lock);
break;
}
unlock_kernel();

return err;
}
Expand Down Expand Up @@ -397,7 +399,7 @@ static const struct file_operations apm_bios_fops = {
.owner = THIS_MODULE,
.read = apm_read,
.poll = apm_poll,
.ioctl = apm_ioctl,
.unlocked_ioctl = apm_ioctl,
.open = apm_open,
.release = apm_release,
};
Expand Down
13 changes: 8 additions & 5 deletions drivers/char/applicom.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/smp_lock.h>
#include <linux/miscdevice.h>
#include <linux/pci.h>
#include <linux/wait.h>
Expand Down Expand Up @@ -106,16 +107,15 @@ static unsigned int DeviceErrorCount; /* number of device error */

static ssize_t ac_read (struct file *, char __user *, size_t, loff_t *);
static ssize_t ac_write (struct file *, const char __user *, size_t, loff_t *);
static int ac_ioctl(struct inode *, struct file *, unsigned int,
unsigned long);
static long ac_ioctl(struct file *, unsigned int, unsigned long);
static irqreturn_t ac_interrupt(int, void *);

static const struct file_operations ac_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = ac_read,
.write = ac_write,
.ioctl = ac_ioctl,
.unlocked_ioctl = ac_ioctl,
};

static struct miscdevice ac_miscdev = {
Expand Down Expand Up @@ -689,7 +689,7 @@ static irqreturn_t ac_interrupt(int vec, void *dev_instance)



static int ac_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

{ /* @ ADG ou ATO selon le cas */
int i;
Expand All @@ -711,7 +711,8 @@ static int ac_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
kfree(adgl);
return -EFAULT;
}


lock_kernel();
IndexCard = adgl->num_card-1;

if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
Expand All @@ -721,6 +722,7 @@ static int ac_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
warncount--;
}
kfree(adgl);
unlock_kernel();
return -EINVAL;
}

Expand Down Expand Up @@ -838,6 +840,7 @@ static int ac_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
}
Dummy = readb(apbs[IndexCard].RamIO + VERS);
kfree(adgl);
unlock_kernel();
return 0;
}

16 changes: 14 additions & 2 deletions drivers/char/ds1620.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ ds1620_read(struct file *file, char __user *buf, size_t count, loff_t *ptr)
}

static int
ds1620_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
ds1620_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
struct therm therm;
union {
Expand Down Expand Up @@ -316,6 +316,18 @@ ds1620_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned
return 0;
}

static long
ds1620_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
int ret;

lock_kernel();
ret = ds1620_ioctl(file, cmd, arg);
unlock_kernel();

return ret;
}

#ifdef THERM_USE_PROC
static int
proc_therm_ds1620_read(char *buf, char **start, off_t offset,
Expand Down Expand Up @@ -344,7 +356,7 @@ static const struct file_operations ds1620_fops = {
.owner = THIS_MODULE,
.open = ds1620_open,
.read = ds1620_read,
.ioctl = ds1620_ioctl,
.unlocked_ioctl = ds1620_unlocked_ioctl,
};

static struct miscdevice ds1620_miscdev = {
Expand Down
15 changes: 8 additions & 7 deletions drivers/char/dtlk.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ static ssize_t dtlk_write(struct file *, const char __user *,
static unsigned int dtlk_poll(struct file *, poll_table *);
static int dtlk_open(struct inode *, struct file *);
static int dtlk_release(struct inode *, struct file *);
static int dtlk_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg);
static long dtlk_ioctl(struct file *file,
unsigned int cmd, unsigned long arg);

static const struct file_operations dtlk_fops =
{
.owner = THIS_MODULE,
.read = dtlk_read,
.write = dtlk_write,
.poll = dtlk_poll,
.ioctl = dtlk_ioctl,
.unlocked_ioctl = dtlk_ioctl,
.open = dtlk_open,
.release = dtlk_release,
};
Expand Down Expand Up @@ -263,10 +263,9 @@ static void dtlk_timer_tick(unsigned long data)
wake_up_interruptible(&dtlk_process_list);
}

static int dtlk_ioctl(struct inode *inode,
struct file *file,
unsigned int cmd,
unsigned long arg)
static long dtlk_ioctl(struct file *file,
unsigned int cmd,
unsigned long arg)
{
char __user *argp = (char __user *)arg;
struct dtlk_settings *sp;
Expand All @@ -276,7 +275,9 @@ static int dtlk_ioctl(struct inode *inode,
switch (cmd) {

case DTLK_INTERROGATE:
lock_kernel();
sp = dtlk_interrogate();
unlock_kernel();
if (copy_to_user(argp, sp, sizeof(struct dtlk_settings)))
return -EINVAL;
return 0;
Expand Down
17 changes: 14 additions & 3 deletions drivers/char/generic_nvram.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/miscdevice.h>
#include <linux/fcntl.h>
#include <linux/init.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include <asm/nvram.h>
#ifdef CONFIG_PPC_PMAC
Expand Down Expand Up @@ -84,8 +85,7 @@ static ssize_t write_nvram(struct file *file, const char __user *buf,
return p - buf;
}

static int nvram_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
static int nvram_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
switch(cmd) {
#ifdef CONFIG_PPC_PMAC
Expand Down Expand Up @@ -116,12 +116,23 @@ static int nvram_ioctl(struct inode *inode, struct file *file,
return 0;
}

static long nvram_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
int ret;

lock_kernel();
ret = nvram_ioctl(file, cmd, arg);
unlock_kernel();

return ret;
}

const struct file_operations nvram_fops = {
.owner = THIS_MODULE,
.llseek = nvram_llseek,
.read = read_nvram,
.write = write_nvram,
.ioctl = nvram_ioctl,
.unlocked_ioctl = nvram_unlocked_ioctl,
};

static struct miscdevice nvram_dev = {
Expand Down
16 changes: 14 additions & 2 deletions drivers/char/genrtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static inline int gen_set_rtc_irq_bit(unsigned char bit)
#endif
}

static int gen_rtc_ioctl(struct inode *inode, struct file *file,
static int gen_rtc_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
struct rtc_time wtime;
Expand Down Expand Up @@ -332,6 +332,18 @@ static int gen_rtc_ioctl(struct inode *inode, struct file *file,
return -EINVAL;
}

static long gen_rtc_unlocked_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
int ret;

lock_kernel();
ret = gen_rtc_ioctl(file, cmd, arg);
unlock_kernel();

return ret;
}

/*
* We enforce only one user at a time here with the open/close.
* Also clear the previous interrupt data on an open, and clean
Expand Down Expand Up @@ -482,7 +494,7 @@ static const struct file_operations gen_rtc_fops = {
.read = gen_rtc_read,
.poll = gen_rtc_poll,
#endif
.ioctl = gen_rtc_ioctl,
.unlocked_ioctl = gen_rtc_unlocked_ioctl,
.open = gen_rtc_open,
.release = gen_rtc_release,
};
Expand Down
14 changes: 9 additions & 5 deletions drivers/char/hpet.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,18 @@ static int hpet_release(struct inode *inode, struct file *file)

static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);

static int
hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
unsigned long arg)
static long hpet_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
struct hpet_dev *devp;
int ret;

devp = file->private_data;
return hpet_ioctl_common(devp, cmd, arg, 0);
lock_kernel();
ret = hpet_ioctl_common(devp, cmd, arg, 0);
unlock_kernel();

return ret;
}

static int hpet_ioctl_ieon(struct hpet_dev *devp)
Expand Down Expand Up @@ -654,7 +658,7 @@ static const struct file_operations hpet_fops = {
.llseek = no_llseek,
.read = hpet_read,
.poll = hpet_poll,
.ioctl = hpet_ioctl,
.unlocked_ioctl = hpet_ioctl,
.open = hpet_open,
.release = hpet_release,
.fasync = hpet_fasync,
Expand Down
26 changes: 21 additions & 5 deletions drivers/char/ipmi/ipmi_devintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ static int handle_send_req(ipmi_user_t user,
return rv;
}

static int ipmi_ioctl(struct inode *inode,
struct file *file,
static int ipmi_ioctl(struct file *file,
unsigned int cmd,
unsigned long data)
{
Expand Down Expand Up @@ -630,6 +629,23 @@ static int ipmi_ioctl(struct inode *inode,
return rv;
}

/*
* Note: it doesn't make sense to take the BKL here but
* not in compat_ipmi_ioctl. -arnd
*/
static long ipmi_unlocked_ioctl(struct file *file,
unsigned int cmd,
unsigned long data)
{
int ret;

lock_kernel();
ret = ipmi_ioctl(file, cmd, data);
unlock_kernel();

return ret;
}

#ifdef CONFIG_COMPAT

/*
Expand Down Expand Up @@ -802,7 +818,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
if (copy_to_user(precv64, &recv64, sizeof(recv64)))
return -EFAULT;

rc = ipmi_ioctl(filep->f_path.dentry->d_inode, filep,
rc = ipmi_ioctl(filep,
((cmd == COMPAT_IPMICTL_RECEIVE_MSG)
? IPMICTL_RECEIVE_MSG
: IPMICTL_RECEIVE_MSG_TRUNC),
Expand All @@ -819,14 +835,14 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
return rc;
}
default:
return ipmi_ioctl(filep->f_path.dentry->d_inode, filep, cmd, arg);
return ipmi_ioctl(filep, cmd, arg);
}
}
#endif

static const struct file_operations ipmi_fops = {
.owner = THIS_MODULE,
.ioctl = ipmi_ioctl,
.unlocked_ioctl = ipmi_unlocked_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_ipmi_ioctl,
#endif
Expand Down
17 changes: 15 additions & 2 deletions drivers/char/ipmi/ipmi_watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ static struct watchdog_info ident = {
.identity = "IPMI"
};

static int ipmi_ioctl(struct inode *inode, struct file *file,
static int ipmi_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
void __user *argp = (void __user *)arg;
Expand Down Expand Up @@ -730,6 +730,19 @@ static int ipmi_ioctl(struct inode *inode, struct file *file,
}
}

static long ipmi_unlocked_ioctl(struct file *file,
unsigned int cmd,
unsigned long arg)
{
int ret;

lock_kernel();
ret = ipmi_ioctl(file, cmd, arg);
unlock_kernel();

return ret;
}

static ssize_t ipmi_write(struct file *file,
const char __user *buf,
size_t len,
Expand Down Expand Up @@ -880,7 +893,7 @@ static const struct file_operations ipmi_wdog_fops = {
.read = ipmi_read,
.poll = ipmi_poll,
.write = ipmi_write,
.ioctl = ipmi_ioctl,
.unlocked_ioctl = ipmi_unlocked_ioctl,
.open = ipmi_open,
.release = ipmi_close,
.fasync = ipmi_fasync,
Expand Down
Loading

0 comments on commit 5592933

Please sign in to comment.