compat_ioctl: block: simplify compat_blkpg_ioctl()
There is no need to go through a compat_alloc_user_space() copy any more, just wrap the function in a small helper that works the same way for native and compat mode. Reviewed-by: Ben Hutchings <ben.hutchings@codethink.co.uk> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
@@ -12,12 +12,12 @@
|
|||||||
#include <linux/pr.h>
|
#include <linux/pr.h>
|
||||||
#include <linux/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
|
|
||||||
static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user *arg)
|
static int blkpg_do_ioctl(struct block_device *bdev,
|
||||||
|
struct blkpg_partition __user *upart, int op)
|
||||||
{
|
{
|
||||||
struct block_device *bdevp;
|
struct block_device *bdevp;
|
||||||
struct gendisk *disk;
|
struct gendisk *disk;
|
||||||
struct hd_struct *part, *lpart;
|
struct hd_struct *part, *lpart;
|
||||||
struct blkpg_ioctl_arg a;
|
|
||||||
struct blkpg_partition p;
|
struct blkpg_partition p;
|
||||||
struct disk_part_iter piter;
|
struct disk_part_iter piter;
|
||||||
long long start, length;
|
long long start, length;
|
||||||
@@ -25,9 +25,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
|
|||||||
|
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
if (copy_from_user(&a, arg, sizeof(struct blkpg_ioctl_arg)))
|
if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))
|
||||||
return -EFAULT;
|
|
||||||
if (copy_from_user(&p, a.data, sizeof(struct blkpg_partition)))
|
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
disk = bdev->bd_disk;
|
disk = bdev->bd_disk;
|
||||||
if (bdev != bdev->bd_contains)
|
if (bdev != bdev->bd_contains)
|
||||||
@@ -35,7 +33,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
|
|||||||
partno = p.pno;
|
partno = p.pno;
|
||||||
if (partno <= 0)
|
if (partno <= 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
switch (a.op) {
|
switch (op) {
|
||||||
case BLKPG_ADD_PARTITION:
|
case BLKPG_ADD_PARTITION:
|
||||||
start = p.start >> 9;
|
start = p.start >> 9;
|
||||||
length = p.length >> 9;
|
length = p.length >> 9;
|
||||||
@@ -156,6 +154,39 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int blkpg_ioctl(struct block_device *bdev,
|
||||||
|
struct blkpg_ioctl_arg __user *arg)
|
||||||
|
{
|
||||||
|
struct blkpg_partition __user *udata;
|
||||||
|
int op;
|
||||||
|
|
||||||
|
if (get_user(op, &arg->op) || get_user(udata, &arg->data))
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
|
return blkpg_do_ioctl(bdev, udata, op);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_COMPAT
|
||||||
|
struct compat_blkpg_ioctl_arg {
|
||||||
|
compat_int_t op;
|
||||||
|
compat_int_t flags;
|
||||||
|
compat_int_t datalen;
|
||||||
|
compat_caddr_t data;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int compat_blkpg_ioctl(struct block_device *bdev,
|
||||||
|
struct compat_blkpg_ioctl_arg __user *arg)
|
||||||
|
{
|
||||||
|
compat_caddr_t udata;
|
||||||
|
int op;
|
||||||
|
|
||||||
|
if (get_user(op, &arg->op) || get_user(udata, &arg->data))
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
|
return blkpg_do_ioctl(bdev, compat_ptr(udata), op);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int blkdev_reread_part(struct block_device *bdev)
|
static int blkdev_reread_part(struct block_device *bdev)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@@ -676,35 +707,6 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
|
|||||||
EXPORT_SYMBOL_GPL(blkdev_ioctl);
|
EXPORT_SYMBOL_GPL(blkdev_ioctl);
|
||||||
|
|
||||||
#ifdef CONFIG_COMPAT
|
#ifdef CONFIG_COMPAT
|
||||||
struct compat_blkpg_ioctl_arg {
|
|
||||||
compat_int_t op;
|
|
||||||
compat_int_t flags;
|
|
||||||
compat_int_t datalen;
|
|
||||||
compat_caddr_t data;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode,
|
|
||||||
unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32)
|
|
||||||
{
|
|
||||||
struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
|
|
||||||
compat_caddr_t udata;
|
|
||||||
compat_int_t n;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = get_user(n, &ua32->op);
|
|
||||||
err |= put_user(n, &a->op);
|
|
||||||
err |= get_user(n, &ua32->flags);
|
|
||||||
err |= put_user(n, &a->flags);
|
|
||||||
err |= get_user(n, &ua32->datalen);
|
|
||||||
err |= put_user(n, &a->datalen);
|
|
||||||
err |= get_user(udata, &ua32->data);
|
|
||||||
err |= put_user(compat_ptr(udata), &a->data);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
return blkdev_ioctl(bdev, mode, cmd, (unsigned long)a);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BLKBSZGET_32 _IOR(0x12, 112, int)
|
#define BLKBSZGET_32 _IOR(0x12, 112, int)
|
||||||
#define BLKBSZSET_32 _IOW(0x12, 113, int)
|
#define BLKBSZSET_32 _IOW(0x12, 113, int)
|
||||||
#define BLKGETSIZE64_32 _IOR(0x12, 114, int)
|
#define BLKGETSIZE64_32 _IOR(0x12, 114, int)
|
||||||
@@ -767,7 +769,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
|
|||||||
return blkdev_ioctl(bdev, mode, BLKBSZSET,
|
return blkdev_ioctl(bdev, mode, BLKBSZSET,
|
||||||
(unsigned long)compat_ptr(arg));
|
(unsigned long)compat_ptr(arg));
|
||||||
case BLKPG:
|
case BLKPG:
|
||||||
return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg));
|
return compat_blkpg_ioctl(bdev, compat_ptr(arg));
|
||||||
case BLKRAGET:
|
case BLKRAGET:
|
||||||
case BLKFRAGET:
|
case BLKFRAGET:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
|
Reference in New Issue
Block a user