From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: dwmw2@redhat.com, linux-kernel@vger.kernel.org
Subject: [PATCH] mtd: Switch to unlocked_ioctl and do BKL in the mtd layer
Date: Thu, 22 May 2008 21:55:07 +0100 [thread overview]
Message-ID: <20080522215507.64481a33@core> (raw)
This helps us get to the point of removing ->ioctl and getting drivers
fixed.
Signed-off-by: Alan Cox <alan@redhat.com>
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 5d3ac51..d2e63fa 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/sched.h>
+#include <linux/smp_lock.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/compatmac.h>
@@ -369,8 +370,7 @@ static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
# define otp_select_filemode(f,m) -EOPNOTSUPP
#endif
-static int mtd_ioctl(struct inode *inode, struct file *file,
- u_int cmd, u_long arg)
+static long do_mtd_ioctl(struct file *file, u_int cmd, u_long arg)
{
struct mtd_file_info *mfi = file->private_data;
struct mtd_info *mtd = mfi->mtd;
@@ -764,12 +764,21 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
return ret;
} /* memory_ioctl */
+static long mtd_ioctl(struct file *file, u_int cmd, u_long arg)
+{
+ long ret;
+ lock_kernel();
+ ret = do_mtd_ioctl(file, cmd, arg);
+ unlock_kernel();
+ return ret;
+}
+
static const struct file_operations mtd_fops = {
.owner = THIS_MODULE,
.llseek = mtd_lseek,
.read = mtd_read,
.write = mtd_write,
- .ioctl = mtd_ioctl,
+ .unlocked_ioctl = mtd_ioctl,
.open = mtd_open,
.release = mtd_close,
};
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 9d6aae5..2b029cc 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -39,6 +39,7 @@
#include <linux/stat.h>
#include <linux/ioctl.h>
#include <linux/capability.h>
+#include <linux/smp_lock.h>
#include <mtd/ubi-user.h>
#include <asm/uaccess.h>
#include <asm/div64.h>
@@ -401,8 +402,8 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
return count;
}
-static int vol_cdev_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
+static long do_vol_cdev_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg)
{
int err = 0;
struct ubi_volume_desc *desc = file->private_data;
@@ -526,6 +527,18 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file,
return err;
}
+static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg)
+{
+ long ret;
+ /* For the moment take the lock before calling as the lifetime
+ and locking for the references are not clear */
+ lock_kernel();
+ ret = do_vol_cdev_ioctl(file, cmd, arg);
+ unlock_kernel();
+ return ret;
+}
+
/**
* verify_mkvol_req - verify volume creation request.
* @ubi: UBI device description object
@@ -595,9 +608,10 @@ static int verify_rsvol_req(const struct ubi_device *ubi,
return 0;
}
-static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
+static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg)
{
+ struct inode *inode = file->f_path.dentry->d_inode;
int err = 0;
struct ubi_device *ubi;
struct ubi_volume_desc *desc;
@@ -606,9 +620,12 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
if (!capable(CAP_SYS_RESOURCE))
return -EPERM;
+ lock_kernel();
ubi = ubi_get_by_major(imajor(inode));
- if (!ubi)
+ if (!ubi) {
+ unlock_kernel();
return -ENODEV;
+ }
switch (cmd) {
/* Create volume command */
@@ -714,11 +731,12 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
}
ubi_put_device(ubi);
+ unlock_kernel();
return err;
}
-static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
+static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg)
{
int err = 0;
void __user *argp = (void __user *)arg;
@@ -726,6 +744,7 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
if (!capable(CAP_SYS_RESOURCE))
return -EPERM;
+ lock_kernel();
switch (cmd) {
/* Attach an MTD device command */
case UBI_IOCATT:
@@ -745,7 +764,6 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
err = -EINVAL;
break;
}
-
mtd = get_mtd_device(NULL, req.mtd_num);
if (IS_ERR(mtd)) {
err = PTR_ERR(mtd);
@@ -790,20 +808,21 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
err = -ENOTTY;
break;
}
+ unlock_kernel();
return err;
}
/* UBI control character device operations */
struct file_operations ubi_ctrl_cdev_operations = {
- .ioctl = ctrl_cdev_ioctl,
+ .unlocked_ioctl = ctrl_cdev_ioctl,
.owner = THIS_MODULE,
};
/* UBI character device operations */
struct file_operations ubi_cdev_operations = {
.owner = THIS_MODULE,
- .ioctl = ubi_cdev_ioctl,
+ .unlocked_ioctl = ubi_cdev_ioctl,
.llseek = no_llseek,
};
@@ -815,5 +834,5 @@ struct file_operations ubi_vol_cdev_operations = {
.llseek = vol_cdev_llseek,
.read = vol_cdev_read,
.write = vol_cdev_write,
- .ioctl = vol_cdev_ioctl,
+ .unlocked_ioctl = vol_cdev_ioctl,
};
reply other threads:[~2008-05-22 21:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080522215507.64481a33@core \
--to=alan@lxorguk.ukuu.org.uk \
--cc=dwmw2@redhat.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.