Skip to content

Commit 18cf7f8

Browse files
arndbJens Axboe
authored andcommitted
compat_ioctl: move BLKPG handling to block/compat_ioctl.c
BLKPG is common to all block devices, so it should be handled by common code. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent 9617db0 commit 18cf7f8

2 files changed

Lines changed: 31 additions & 33 deletions

File tree

‎block/compat_ioctl.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,35 @@ static int compat_hdio_ioctl(struct inode *inode, struct file *file,
9292
return error;
9393
}
9494

95+
struct compat_blkpg_ioctl_arg {
96+
compat_int_t op;
97+
compat_int_t flags;
98+
compat_int_t datalen;
99+
compat_caddr_t data;
100+
};
101+
102+
static int compat_blkpg_ioctl(struct inode *inode, struct file *file,
103+
unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32)
104+
{
105+
struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
106+
compat_caddr_t udata;
107+
compat_int_t n;
108+
int err;
109+
110+
err = get_user(n, &ua32->op);
111+
err |= put_user(n, &a->op);
112+
err |= get_user(n, &ua32->flags);
113+
err |= put_user(n, &a->flags);
114+
err |= get_user(n, &ua32->datalen);
115+
err |= put_user(n, &a->datalen);
116+
err |= get_user(udata, &ua32->data);
117+
err |= put_user(compat_ptr(udata), &a->data);
118+
if (err)
119+
return err;
120+
121+
return blkdev_ioctl(inode, file, cmd, (unsigned long)a);
122+
}
123+
95124
#define BLKBSZGET_32 _IOR(0x12, 112, int)
96125
#define BLKBSZSET_32 _IOW(0x12, 113, int)
97126
#define BLKGETSIZE64_32 _IOR(0x12, 114, int)
@@ -348,6 +377,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
348377
case BLKBSZSET_32:
349378
return blkdev_ioctl(inode, file, BLKBSZSET,
350379
(unsigned long)compat_ptr(arg));
380+
case BLKPG:
381+
return compat_blkpg_ioctl(inode, file, cmd, compat_ptr(arg));
351382
}
352383

353384
lock_kernel();

‎fs/compat_ioctl.c‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include <linux/netdevice.h>
4848
#include <linux/raw.h>
4949
#include <linux/smb_fs.h>
50-
#include <linux/blkpg.h>
5150
#include <linux/blkdev.h>
5251
#include <linux/elevator.h>
5352
#include <linux/rtc.h>
@@ -1487,37 +1486,6 @@ ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
14871486
return -EINVAL;
14881487
}
14891488

1490-
#ifdef CONFIG_BLOCK
1491-
struct blkpg_ioctl_arg32 {
1492-
compat_int_t op;
1493-
compat_int_t flags;
1494-
compat_int_t datalen;
1495-
compat_caddr_t data;
1496-
};
1497-
1498-
static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1499-
{
1500-
struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg);
1501-
struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
1502-
compat_caddr_t udata;
1503-
compat_int_t n;
1504-
int err;
1505-
1506-
err = get_user(n, &ua32->op);
1507-
err |= put_user(n, &a->op);
1508-
err |= get_user(n, &ua32->flags);
1509-
err |= put_user(n, &a->flags);
1510-
err |= get_user(n, &ua32->datalen);
1511-
err |= put_user(n, &a->datalen);
1512-
err |= get_user(udata, &ua32->data);
1513-
err |= put_user(compat_ptr(udata), &a->data);
1514-
if (err)
1515-
return err;
1516-
1517-
return sys_ioctl(fd, cmd, (unsigned long)a);
1518-
}
1519-
#endif
1520-
15211489
static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
15221490
{
15231491
return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
@@ -3160,7 +3128,6 @@ HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
31603128
HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns)
31613129
#endif
31623130
#ifdef CONFIG_BLOCK
3163-
HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
31643131
HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
31653132
HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
31663133
HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)

0 commit comments

Comments
 (0)