hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/ide/ide-tape.c
....@@ -19,6 +19,7 @@
1919
2020 #define IDETAPE_VERSION "1.20"
2121
22
+#include <linux/compat.h>
2223 #include <linux/module.h>
2324 #include <linux/types.h>
2425 #include <linux/string.h>
....@@ -639,7 +640,7 @@
639640 goto out;
640641 }
641642 if (req->cmd[13] & REQ_IDETAPE_PC1) {
642
- pc = (struct ide_atapi_pc *)rq->special;
643
+ pc = (struct ide_atapi_pc *)ide_req(rq)->special;
643644 req->cmd[13] &= ~(REQ_IDETAPE_PC1);
644645 req->cmd[13] |= REQ_IDETAPE_PC2;
645646 goto out;
....@@ -1407,14 +1408,10 @@
14071408 if (tape->drv_write_prot)
14081409 mtget.mt_gstat |= GMT_WR_PROT(0xffffffff);
14091410
1410
- if (copy_to_user(argp, &mtget, sizeof(struct mtget)))
1411
- return -EFAULT;
1412
- return 0;
1411
+ return put_user_mtget(argp, &mtget);
14131412 case MTIOCPOS:
14141413 mtpos.mt_blkno = position / tape->user_bs_factor - block_offset;
1415
- if (copy_to_user(argp, &mtpos, sizeof(struct mtpos)))
1416
- return -EFAULT;
1417
- return 0;
1414
+ return put_user_mtpos(argp, &mtpos);
14181415 default:
14191416 if (tape->chrdev_dir == IDETAPE_DIR_READ)
14201417 ide_tape_discard_merge_buffer(drive, 1);
....@@ -1426,6 +1423,22 @@
14261423 unsigned int cmd, unsigned long arg)
14271424 {
14281425 long ret;
1426
+ mutex_lock(&ide_tape_mutex);
1427
+ ret = do_idetape_chrdev_ioctl(file, cmd, arg);
1428
+ mutex_unlock(&ide_tape_mutex);
1429
+ return ret;
1430
+}
1431
+
1432
+static long idetape_chrdev_compat_ioctl(struct file *file,
1433
+ unsigned int cmd, unsigned long arg)
1434
+{
1435
+ long ret;
1436
+
1437
+ if (cmd == MTIOCPOS32)
1438
+ cmd = MTIOCPOS;
1439
+ else if (cmd == MTIOCGET32)
1440
+ cmd = MTIOCGET;
1441
+
14291442 mutex_lock(&ide_tape_mutex);
14301443 ret = do_idetape_chrdev_ioctl(file, cmd, arg);
14311444 mutex_unlock(&ide_tape_mutex);
....@@ -1886,6 +1899,8 @@
18861899 .read = idetape_chrdev_read,
18871900 .write = idetape_chrdev_write,
18881901 .unlocked_ioctl = idetape_chrdev_ioctl,
1902
+ .compat_ioctl = IS_ENABLED(CONFIG_COMPAT) ?
1903
+ idetape_chrdev_compat_ioctl : NULL,
18891904 .open = idetape_chrdev_open,
18901905 .release = idetape_chrdev_release,
18911906 .llseek = noop_llseek,
....@@ -1930,11 +1945,22 @@
19301945 return err;
19311946 }
19321947
1948
+static int idetape_compat_ioctl(struct block_device *bdev, fmode_t mode,
1949
+ unsigned int cmd, unsigned long arg)
1950
+{
1951
+ if (cmd == 0x0340 || cmd == 0x350)
1952
+ arg = (unsigned long)compat_ptr(arg);
1953
+
1954
+ return idetape_ioctl(bdev, mode, cmd, arg);
1955
+}
1956
+
19331957 static const struct block_device_operations idetape_block_ops = {
19341958 .owner = THIS_MODULE,
19351959 .open = idetape_open,
19361960 .release = idetape_release,
19371961 .ioctl = idetape_ioctl,
1962
+ .compat_ioctl = IS_ENABLED(CONFIG_COMPAT) ?
1963
+ idetape_compat_ioctl : NULL,
19381964 };
19391965
19401966 static int ide_tape_probe(ide_drive_t *drive)