Commit 558e3fbe authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Martin K. Petersen
Browse files

scsi: sr: Consolidate compat ioctl handling

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: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent beec64d0
Loading
Loading
Loading
Loading
+9 −55
Original line number Diff line number Diff line
@@ -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 = 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:
		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;

	if (in_compat_syscall())
		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,
};