Commit f429b2ea authored by Artem Bityutskiy's avatar Artem Bityutskiy

UBI: add ioctl compatibility

UBI ioctl's do not work when running 64-bit kernel and 32-bit
user-land. Fix this by adding the compat_ioctl method.

Also, UBI serializes all ioctls, so more than one ioctl at a time
is not a problem. Amd UBI does not seem to depend on anything else,
so use unlocked_ioctl instead of ioctl (no BKL needed).
Reported-by: default avatarGeert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
parent 4d187a88
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <linux/ioctl.h> #include <linux/ioctl.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/compat.h>
#include <mtd/ubi-user.h> #include <mtd/ubi-user.h>
#include <asm/div64.h> #include <asm/div64.h>
#include "ubi.h" #include "ubi.h"
...@@ -401,8 +402,8 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf, ...@@ -401,8 +402,8 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
return count; return count;
} }
static int vol_cdev_ioctl(struct inode *inode, struct file *file, static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
unsigned int cmd, unsigned long arg) unsigned long arg)
{ {
int err = 0; int err = 0;
struct ubi_volume_desc *desc = file->private_data; struct ubi_volume_desc *desc = file->private_data;
...@@ -800,8 +801,8 @@ out_free: ...@@ -800,8 +801,8 @@ out_free:
return err; return err;
} }
static int ubi_cdev_ioctl(struct inode *inode, struct file *file, static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
unsigned int cmd, unsigned long arg) unsigned long arg)
{ {
int err = 0; int err = 0;
struct ubi_device *ubi; struct ubi_device *ubi;
...@@ -811,7 +812,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file, ...@@ -811,7 +812,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
if (!capable(CAP_SYS_RESOURCE)) if (!capable(CAP_SYS_RESOURCE))
return -EPERM; return -EPERM;
ubi = ubi_get_by_major(imajor(inode)); ubi = ubi_get_by_major(imajor(file->f_mapping->host));
if (!ubi) if (!ubi)
return -ENODEV; return -ENODEV;
...@@ -947,8 +948,8 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file, ...@@ -947,8 +948,8 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
return err; return err;
} }
static int ctrl_cdev_ioctl(struct inode *inode, struct file *file, static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd,
unsigned int cmd, unsigned long arg) unsigned long arg)
{ {
int err = 0; int err = 0;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
...@@ -1024,26 +1025,59 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file, ...@@ -1024,26 +1025,59 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
return err; return err;
} }
/* UBI control character device operations */ #ifdef CONFIG_COMPAT
const struct file_operations ubi_ctrl_cdev_operations = { static long vol_cdev_compat_ioctl(struct file *file, unsigned int cmd,
.ioctl = ctrl_cdev_ioctl, unsigned long arg)
.owner = THIS_MODULE, {
unsigned long translated_arg = (unsigned long)compat_ptr(arg);
return vol_cdev_ioctl(file, cmd, translated_arg);
}
static long ubi_cdev_compat_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
unsigned long translated_arg = (unsigned long)compat_ptr(arg);
return ubi_cdev_ioctl(file, cmd, translated_arg);
}
static long ctrl_cdev_compat_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
unsigned long translated_arg = (unsigned long)compat_ptr(arg);
return ctrl_cdev_ioctl(file, cmd, translated_arg);
}
#else
#define vol_cdev_compat_ioctl NULL
#define ubi_cdev_compat_ioctl NULL
#define ctrl_cdev_compat_ioctl NULL
#endif
/* UBI volume character device operations */
const struct file_operations ubi_vol_cdev_operations = {
.owner = THIS_MODULE,
.open = vol_cdev_open,
.release = vol_cdev_release,
.llseek = vol_cdev_llseek,
.read = vol_cdev_read,
.write = vol_cdev_write,
.unlocked_ioctl = vol_cdev_ioctl,
.compat_ioctl = vol_cdev_compat_ioctl,
}; };
/* UBI character device operations */ /* UBI character device operations */
const struct file_operations ubi_cdev_operations = { const struct file_operations ubi_cdev_operations = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.ioctl = ubi_cdev_ioctl, .llseek = no_llseek,
.llseek = no_llseek, .unlocked_ioctl = ubi_cdev_ioctl,
.compat_ioctl = ubi_cdev_compat_ioctl,
}; };
/* UBI volume character device operations */ /* UBI control character device operations */
const struct file_operations ubi_vol_cdev_operations = { const struct file_operations ubi_ctrl_cdev_operations = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = vol_cdev_open, .unlocked_ioctl = ctrl_cdev_ioctl,
.release = vol_cdev_release, .compat_ioctl = ctrl_cdev_compat_ioctl,
.llseek = vol_cdev_llseek,
.read = vol_cdev_read,
.write = vol_cdev_write,
.ioctl = vol_cdev_ioctl,
}; };
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