scsi: sr: Consolidate compat ioctl handling
authorChristoph Hellwig <hch@lst.de>
Sat, 24 Jul 2021 07:20:11 +0000 (09:20 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 29 Jul 2021 02:24:24 +0000 (22:24 -0400)
Merge the native and compat ioctl handlers into a single one using
in_compat_syscall().

Link: https://lore.kernel.org/r/20210724072033.1284840-3-hch@lst.de
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/sr.c

index 94c254e..b34f069 100644 (file)
@@ -577,68 +577,24 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
        switch (cmd) {
        case SCSI_IOCTL_GET_IDLUN:
        case SCSI_IOCTL_GET_BUS_NUMBER:
-               ret = scsi_ioctl(sdev, cmd, argp);
-               goto put;
+               break;
+       default:
+               ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg);
+               if (ret != -ENOSYS)
+                       goto put;
        }
 
-       ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg);
-       if (ret != -ENOSYS)
-               goto put;
-
-       ret = scsi_ioctl(sdev, cmd, argp);
-
-put:
-       scsi_autopm_put_device(sdev);
-
-out:
-       mutex_unlock(&cd->lock);
-       return ret;
-}
-
-#ifdef CONFIG_COMPAT
-static int sr_block_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
-                         unsigned long arg)
-{
-       struct scsi_cd *cd = scsi_cd(bdev->bd_disk);
-       struct scsi_device *sdev = cd->device;
-       void __user *argp = compat_ptr(arg);
-       int ret;
-
-       mutex_lock(&cd->lock);
-
-       ret = scsi_ioctl_block_when_processing_errors(sdev, cmd,
-                       (mode & FMODE_NDELAY) != 0);
-       if (ret)
-               goto out;
-
-       scsi_autopm_get_device(sdev);
-
-       /*
-        * Send SCSI addressing ioctls directly to mid level, send other
-        * ioctls to cdrom/block level.
-        */
-       switch (cmd) {
-       case SCSI_IOCTL_GET_IDLUN:
-       case SCSI_IOCTL_GET_BUS_NUMBER:
+       if (in_compat_syscall())
                ret = scsi_compat_ioctl(sdev, cmd, argp);
-               goto put;
-       }
-
-       ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, (unsigned long)argp);
-       if (ret != -ENOSYS)
-               goto put;
-
-       ret = scsi_compat_ioctl(sdev, cmd, argp);
+       else
+               ret = scsi_ioctl(sdev, cmd, argp);
 
 put:
        scsi_autopm_put_device(sdev);
-
 out:
        mutex_unlock(&cd->lock);
        return ret;
-
 }
-#endif
 
 static unsigned int sr_block_check_events(struct gendisk *disk,
                                          unsigned int clearing)
@@ -663,9 +619,7 @@ static const struct block_device_operations sr_bdops =
        .open           = sr_block_open,
        .release        = sr_block_release,
        .ioctl          = sr_block_ioctl,
-#ifdef CONFIG_COMPAT
-       .compat_ioctl   = sr_block_compat_ioctl,
-#endif
+       .compat_ioctl   = blkdev_compat_ptr_ioctl,
        .check_events   = sr_block_check_events,
 };