scsi: Push down BKL into ioctl functions

Push down the bkl into ioctl functions on the scsi layer.

[jkacur: Forward declaration missing ';'.
Conflicting declaraction in megaraid.h changed
Fixed missing inodes declarations]

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: John Kacur <jkacur@redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
This commit is contained in:
Arnd Bergmann 2010-04-27 00:24:01 +02:00 committed by Frederic Weisbecker
parent 16ef8def80
commit f4927c45be
11 changed files with 120 additions and 36 deletions

View File

@ -123,7 +123,7 @@ static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_H
static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id); static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id);
static char *twa_aen_severity_lookup(unsigned char severity_code); static char *twa_aen_severity_lookup(unsigned char severity_code);
static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id); static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id);
static int twa_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg); static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
static int twa_chrdev_open(struct inode *inode, struct file *file); static int twa_chrdev_open(struct inode *inode, struct file *file);
static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host); static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host);
static void twa_free_request_id(TW_Device_Extension *tw_dev,int request_id); static void twa_free_request_id(TW_Device_Extension *tw_dev,int request_id);
@ -218,7 +218,7 @@ static struct device_attribute *twa_host_attrs[] = {
/* File operations struct for character device */ /* File operations struct for character device */
static const struct file_operations twa_fops = { static const struct file_operations twa_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.ioctl = twa_chrdev_ioctl, .unlocked_ioctl = twa_chrdev_ioctl,
.open = twa_chrdev_open, .open = twa_chrdev_open,
.release = NULL .release = NULL
}; };
@ -635,8 +635,9 @@ out:
} /* End twa_check_srl() */ } /* End twa_check_srl() */
/* This function handles ioctl for the character device */ /* This function handles ioctl for the character device */
static int twa_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
struct inode *inode = file->f_path.dentry->d_inode;
long timeout; long timeout;
unsigned long *cpu_addr, data_buffer_length_adjusted = 0, flags = 0; unsigned long *cpu_addr, data_buffer_length_adjusted = 0, flags = 0;
dma_addr_t dma_handle; dma_addr_t dma_handle;
@ -655,6 +656,8 @@ static int twa_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
int retval = TW_IOCTL_ERROR_OS_EFAULT; int retval = TW_IOCTL_ERROR_OS_EFAULT;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
lock_kernel();
/* Only let one of these through at a time */ /* Only let one of these through at a time */
if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
retval = TW_IOCTL_ERROR_OS_EINTR; retval = TW_IOCTL_ERROR_OS_EINTR;
@ -874,6 +877,7 @@ out3:
out2: out2:
mutex_unlock(&tw_dev->ioctl_lock); mutex_unlock(&tw_dev->ioctl_lock);
out: out:
unlock_kernel();
return retval; return retval;
} /* End twa_chrdev_ioctl() */ } /* End twa_chrdev_ioctl() */

View File

@ -750,19 +750,22 @@ static void twl_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm
/* This function handles ioctl for the character device /* This function handles ioctl for the character device
This interface is used by smartmontools open source software */ This interface is used by smartmontools open source software */
static int twl_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) static long twl_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
long timeout; long timeout;
unsigned long *cpu_addr, data_buffer_length_adjusted = 0, flags = 0; unsigned long *cpu_addr, data_buffer_length_adjusted = 0, flags = 0;
dma_addr_t dma_handle; dma_addr_t dma_handle;
int request_id = 0; int request_id = 0;
TW_Ioctl_Driver_Command driver_command; TW_Ioctl_Driver_Command driver_command;
struct inode *inode = file->f_dentry->d_inode;
TW_Ioctl_Buf_Apache *tw_ioctl; TW_Ioctl_Buf_Apache *tw_ioctl;
TW_Command_Full *full_command_packet; TW_Command_Full *full_command_packet;
TW_Device_Extension *tw_dev = twl_device_extension_list[iminor(inode)]; TW_Device_Extension *tw_dev = twl_device_extension_list[iminor(inode)];
int retval = -EFAULT; int retval = -EFAULT;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
lock_kernel();
/* Only let one of these through at a time */ /* Only let one of these through at a time */
if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
retval = -EINTR; retval = -EINTR;
@ -858,6 +861,7 @@ out3:
out2: out2:
mutex_unlock(&tw_dev->ioctl_lock); mutex_unlock(&tw_dev->ioctl_lock);
out: out:
unlock_kernel();
return retval; return retval;
} /* End twl_chrdev_ioctl() */ } /* End twl_chrdev_ioctl() */
@ -884,7 +888,7 @@ out:
/* File operations struct for character device */ /* File operations struct for character device */
static const struct file_operations twl_fops = { static const struct file_operations twl_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.ioctl = twl_chrdev_ioctl, .unlocked_ioctl = twl_chrdev_ioctl,
.open = twl_chrdev_open, .open = twl_chrdev_open,
.release = NULL .release = NULL
}; };

View File

@ -880,7 +880,7 @@ static int tw_allocate_memory(TW_Device_Extension *tw_dev, int size, int which)
} /* End tw_allocate_memory() */ } /* End tw_allocate_memory() */
/* This function handles ioctl for the character device */ /* This function handles ioctl for the character device */
static int tw_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) static long tw_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
int request_id; int request_id;
dma_addr_t dma_handle; dma_addr_t dma_handle;
@ -888,6 +888,7 @@ static int tw_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
unsigned long flags; unsigned long flags;
unsigned int data_buffer_length = 0; unsigned int data_buffer_length = 0;
unsigned long data_buffer_length_adjusted = 0; unsigned long data_buffer_length_adjusted = 0;
struct inode *inode = file->f_dentry->d_inode;
unsigned long *cpu_addr; unsigned long *cpu_addr;
long timeout; long timeout;
TW_New_Ioctl *tw_ioctl; TW_New_Ioctl *tw_ioctl;
@ -898,9 +899,12 @@ static int tw_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
dprintk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl()\n"); dprintk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl()\n");
lock_kernel();
/* Only let one of these through at a time */ /* Only let one of these through at a time */
if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
unlock_kernel();
return -EINTR; return -EINTR;
}
/* First copy down the buffer length */ /* First copy down the buffer length */
if (copy_from_user(&data_buffer_length, argp, sizeof(unsigned int))) if (copy_from_user(&data_buffer_length, argp, sizeof(unsigned int)))
@ -1029,6 +1033,7 @@ out2:
dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, cpu_addr, dma_handle); dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, cpu_addr, dma_handle);
out: out:
mutex_unlock(&tw_dev->ioctl_lock); mutex_unlock(&tw_dev->ioctl_lock);
unlock_kernel();
return retval; return retval;
} /* End tw_chrdev_ioctl() */ } /* End tw_chrdev_ioctl() */
@ -1051,7 +1056,7 @@ static int tw_chrdev_open(struct inode *inode, struct file *file)
/* File operations struct for character device */ /* File operations struct for character device */
static const struct file_operations tw_fops = { static const struct file_operations tw_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.ioctl = tw_chrdev_ioctl, .unlocked_ioctl = tw_chrdev_ioctl,
.open = tw_chrdev_open, .open = tw_chrdev_open,
.release = NULL .release = NULL
}; };

View File

@ -705,12 +705,17 @@ static int aac_cfg_open(struct inode *inode, struct file *file)
* Bugs: Needs to handle hot plugging * Bugs: Needs to handle hot plugging
*/ */
static int aac_cfg_ioctl(struct inode *inode, struct file *file, static long aac_cfg_ioctl(struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
int ret;
if (!capable(CAP_SYS_RAWIO)) if (!capable(CAP_SYS_RAWIO))
return -EPERM; return -EPERM;
return aac_do_ioctl(file->private_data, cmd, (void __user *)arg); lock_kernel();
ret = aac_do_ioctl(file->private_data, cmd, (void __user *)arg);
unlock_kernel();
return ret;
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
@ -1029,7 +1034,7 @@ ssize_t aac_get_serial_number(struct device *device, char *buf)
static const struct file_operations aac_cfg_fops = { static const struct file_operations aac_cfg_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.ioctl = aac_cfg_ioctl, .unlocked_ioctl = aac_cfg_ioctl,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compat_ioctl = aac_compat_cfg_ioctl, .compat_ioctl = aac_compat_cfg_ioctl,
#endif #endif

View File

@ -114,12 +114,13 @@ static int hba_count = 0;
static struct class *adpt_sysfs_class; static struct class *adpt_sysfs_class;
static long adpt_unlocked_ioctl(struct file *, unsigned int, unsigned long);
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
static long compat_adpt_ioctl(struct file *, unsigned int, unsigned long); static long compat_adpt_ioctl(struct file *, unsigned int, unsigned long);
#endif #endif
static const struct file_operations adpt_fops = { static const struct file_operations adpt_fops = {
.ioctl = adpt_ioctl, .unlocked_ioctl = adpt_unlocked_ioctl,
.open = adpt_open, .open = adpt_open,
.release = adpt_close, .release = adpt_close,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
@ -2069,8 +2070,7 @@ static int adpt_system_info(void __user *buffer)
return 0; return 0;
} }
static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd, static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
ulong arg)
{ {
int minor; int minor;
int error = 0; int error = 0;
@ -2153,6 +2153,20 @@ static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd,
return error; return error;
} }
static long adpt_unlocked_ioctl(struct file *file, uint cmd, ulong arg)
{
struct inode *inode;
long ret;
inode = file->f_dentry->d_inode;
lock_kernel();
ret = adpt_ioctl(inode, file, cmd, arg);
unlock_kernel();
return ret;
}
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
static long compat_adpt_ioctl(struct file *file, static long compat_adpt_ioctl(struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)

View File

@ -180,8 +180,8 @@ static const char *gdth_ctr_name(gdth_ha_str *ha);
static int gdth_open(struct inode *inode, struct file *filep); static int gdth_open(struct inode *inode, struct file *filep);
static int gdth_close(struct inode *inode, struct file *filep); static int gdth_close(struct inode *inode, struct file *filep);
static int gdth_ioctl(struct inode *inode, struct file *filep, static long gdth_unlocked_ioctl(struct file *filep, unsigned int cmd,
unsigned int cmd, unsigned long arg); unsigned long arg);
static void gdth_flush(gdth_ha_str *ha); static void gdth_flush(gdth_ha_str *ha);
static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *)); static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *));
@ -369,7 +369,7 @@ MODULE_LICENSE("GPL");
/* ioctl interface */ /* ioctl interface */
static const struct file_operations gdth_fops = { static const struct file_operations gdth_fops = {
.ioctl = gdth_ioctl, .unlocked_ioctl = gdth_unlocked_ioctl,
.open = gdth_open, .open = gdth_open,
.release = gdth_close, .release = gdth_close,
}; };
@ -4462,8 +4462,7 @@ free_fail:
return rc; return rc;
} }
static int gdth_ioctl(struct inode *inode, struct file *filep, static int gdth_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
unsigned int cmd, unsigned long arg)
{ {
gdth_ha_str *ha; gdth_ha_str *ha;
Scsi_Cmnd *scp; Scsi_Cmnd *scp;
@ -4611,6 +4610,17 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
return 0; return 0;
} }
static long gdth_unlocked_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
int ret;
lock_kernel();
ret = gdth_ioctl(file, cmd, arg);
unlock_kernel();
return ret;
}
/* flush routine */ /* flush routine */
static void gdth_flush(gdth_ha_str *ha) static void gdth_flush(gdth_ha_str *ha)

View File

@ -91,12 +91,15 @@ static struct proc_dir_entry *mega_proc_dir_entry;
/* For controller re-ordering */ /* For controller re-ordering */
static struct mega_hbas mega_hbas[MAX_CONTROLLERS]; static struct mega_hbas mega_hbas[MAX_CONTROLLERS];
static long
megadev_unlocked_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
/* /*
* The File Operations structure for the serial/ioctl interface of the driver * The File Operations structure for the serial/ioctl interface of the driver
*/ */
static const struct file_operations megadev_fops = { static const struct file_operations megadev_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.ioctl = megadev_ioctl, .unlocked_ioctl = megadev_unlocked_ioctl,
.open = megadev_open, .open = megadev_open,
}; };
@ -3302,8 +3305,7 @@ megadev_open (struct inode *inode, struct file *filep)
* controller. * controller.
*/ */
static int static int
megadev_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, megadev_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
unsigned long arg)
{ {
adapter_t *adapter; adapter_t *adapter;
nitioctl_t uioc; nitioctl_t uioc;
@ -3694,6 +3696,18 @@ freemem_and_return:
return 0; return 0;
} }
static long
megadev_unlocked_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
{
int ret;
lock_kernel();
ret = megadev_ioctl(filep, cmd, arg);
unlock_kernel();
return ret;
}
/** /**
* mega_m_to_n() * mega_m_to_n()
* @arg - user address * @arg - user address

View File

@ -1013,8 +1013,7 @@ static void mega_8_to_40ld (mraid_inquiry *inquiry,
mega_inquiry3 *enquiry3, mega_product_info *); mega_inquiry3 *enquiry3, mega_product_info *);
static int megadev_open (struct inode *, struct file *); static int megadev_open (struct inode *, struct file *);
static int megadev_ioctl (struct inode *, struct file *, unsigned int, static int megadev_ioctl (struct file *, unsigned int, unsigned long);
unsigned long);
static int mega_m_to_n(void __user *, nitioctl_t *); static int mega_m_to_n(void __user *, nitioctl_t *);
static int mega_n_to_m(void __user *, megacmd_t *); static int mega_n_to_m(void __user *, megacmd_t *);

View File

@ -22,7 +22,7 @@
// Entry points for char node driver // Entry points for char node driver
static int mraid_mm_open(struct inode *, struct file *); static int mraid_mm_open(struct inode *, struct file *);
static int mraid_mm_ioctl(struct inode *, struct file *, uint, unsigned long); static long mraid_mm_unlocked_ioctl(struct file *, uint, unsigned long);
// routines to convert to and from the old the format // routines to convert to and from the old the format
@ -70,7 +70,7 @@ static wait_queue_head_t wait_q;
static const struct file_operations lsi_fops = { static const struct file_operations lsi_fops = {
.open = mraid_mm_open, .open = mraid_mm_open,
.ioctl = mraid_mm_ioctl, .unlocked_ioctl = mraid_mm_unlocked_ioctl,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compat_ioctl = mraid_mm_compat_ioctl, .compat_ioctl = mraid_mm_compat_ioctl,
#endif #endif
@ -110,8 +110,7 @@ mraid_mm_open(struct inode *inode, struct file *filep)
* @arg : user ioctl packet * @arg : user ioctl packet
*/ */
static int static int
mraid_mm_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, mraid_mm_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
unsigned long arg)
{ {
uioc_t *kioc; uioc_t *kioc;
char signature[EXT_IOCTL_SIGN_SZ] = {0}; char signature[EXT_IOCTL_SIGN_SZ] = {0};
@ -218,6 +217,19 @@ mraid_mm_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
return rval; return rval;
} }
static long
mraid_mm_unlocked_ioctl(struct file *filep, unsigned int cmd,
unsigned long arg)
{
int err;
/* inconsistant: mraid_mm_compat_ioctl doesn't take the BKL */
lock_kernel();
err = mraid_mm_ioctl(filep, cmd, arg);
unlock_kernel();
return err;
}
/** /**
* mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet
@ -1225,7 +1237,7 @@ mraid_mm_compat_ioctl(struct file *filep, unsigned int cmd,
{ {
int err; int err;
err = mraid_mm_ioctl(NULL, filep, cmd, arg); err = mraid_mm_ioctl(filep, cmd, arg);
return err; return err;
} }

View File

@ -4932,7 +4932,7 @@ static int os_scsi_tape_close(struct inode * inode, struct file * filp)
/* The ioctl command */ /* The ioctl command */
static int osst_ioctl(struct inode * inode,struct file * file, static long osst_ioctl(struct file * file,
unsigned int cmd_in, unsigned long arg) unsigned int cmd_in, unsigned long arg)
{ {
int i, cmd_nr, cmd_type, blk, retval = 0; int i, cmd_nr, cmd_type, blk, retval = 0;
@ -4943,8 +4943,11 @@ static int osst_ioctl(struct inode * inode,struct file * file,
char * name = tape_name(STp); char * name = tape_name(STp);
void __user * p = (void __user *)arg; void __user * p = (void __user *)arg;
if (mutex_lock_interruptible(&STp->lock)) lock_kernel();
if (mutex_lock_interruptible(&STp->lock)) {
unlock_kernel();
return -ERESTARTSYS; return -ERESTARTSYS;
}
#if DEBUG #if DEBUG
if (debugging && !STp->in_use) { if (debugging && !STp->in_use) {
@ -5256,12 +5259,15 @@ static int osst_ioctl(struct inode * inode,struct file * file,
mutex_unlock(&STp->lock); mutex_unlock(&STp->lock);
return scsi_ioctl(STp->device, cmd_in, p); retval = scsi_ioctl(STp->device, cmd_in, p);
unlock_kernel();
return retval;
out: out:
if (SRpnt) osst_release_request(SRpnt); if (SRpnt) osst_release_request(SRpnt);
mutex_unlock(&STp->lock); mutex_unlock(&STp->lock);
unlock_kernel();
return retval; return retval;
} }
@ -5613,7 +5619,7 @@ static const struct file_operations osst_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.read = osst_read, .read = osst_read,
.write = osst_write, .write = osst_write,
.ioctl = osst_ioctl, .unlocked_ioctl = osst_ioctl,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compat_ioctl = osst_compat_ioctl, .compat_ioctl = osst_compat_ioctl,
#endif #endif

View File

@ -758,8 +758,7 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp,
} }
static int static int
sg_ioctl(struct inode *inode, struct file *filp, sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
unsigned int cmd_in, unsigned long arg)
{ {
void __user *p = (void __user *)arg; void __user *p = (void __user *)arg;
int __user *ip = p; int __user *ip = p;
@ -1078,6 +1077,18 @@ sg_ioctl(struct inode *inode, struct file *filp,
} }
} }
static long
sg_unlocked_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
{
int ret;
lock_kernel();
ret = sg_ioctl(filp, cmd_in, arg);
unlock_kernel();
return ret;
}
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
static long sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) static long sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
{ {
@ -1322,7 +1333,7 @@ static const struct file_operations sg_fops = {
.read = sg_read, .read = sg_read,
.write = sg_write, .write = sg_write,
.poll = sg_poll, .poll = sg_poll,
.ioctl = sg_ioctl, .unlocked_ioctl = sg_unlocked_ioctl,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compat_ioctl = sg_compat_ioctl, .compat_ioctl = sg_compat_ioctl,
#endif #endif