Commit 44328310 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Martin K. Petersen

scsi: sd: Consolidate compat ioctl handling

Merge the native and compat ioctl handlers into a single one using
in_compat_syscall(), and also simplify the calling conventions by merging
sd_ioctl_common() into sd_ioctl().

Link: https://lore.kernel.org/r/20210724072033.1284840-4-hch@lst.deSigned-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 558e3fbe
......@@ -1530,11 +1530,11 @@ static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
}
/**
* sd_ioctl_common - process an ioctl
* sd_ioctl - process an ioctl
* @bdev: target block device
* @mode: FMODE_* mask
* @cmd: ioctl command number
* @p: this is third argument given to ioctl(2) system call.
* @arg: this is third argument given to ioctl(2) system call.
* Often contains a pointer.
*
* Returns 0 if successful (some ioctls return positive numbers on
......@@ -1543,12 +1543,13 @@ static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
* Note: most ioctls are forward onto the block subsystem or further
* down in the scsi subsystem.
**/
static int sd_ioctl_common(struct block_device *bdev, fmode_t mode,
unsigned int cmd, void __user *p)
static int sd_ioctl(struct block_device *bdev, fmode_t mode,
unsigned int cmd, unsigned long arg)
{
struct gendisk *disk = bdev->bd_disk;
struct scsi_disk *sdkp = scsi_disk(disk);
struct scsi_device *sdp = sdkp->device;
void __user *p = (void __user *)arg;
int error;
SCSI_LOG_IOCTL(1, sd_printk(KERN_INFO, sdkp, "sd_ioctl: disk=%s, "
......@@ -1567,7 +1568,7 @@ static int sd_ioctl_common(struct block_device *bdev, fmode_t mode,
error = scsi_ioctl_block_when_processing_errors(sdp, cmd,
(mode & FMODE_NDELAY) != 0);
if (error)
goto out;
return error;
if (is_sed_ioctl(cmd))
return sed_ioctl(sdkp->opal_dev, cmd, p);
......@@ -1578,16 +1579,18 @@ static int sd_ioctl_common(struct block_device *bdev, fmode_t mode,
* resolved.
*/
switch (cmd) {
case SCSI_IOCTL_GET_IDLUN:
case SCSI_IOCTL_GET_BUS_NUMBER:
error = scsi_ioctl(sdp, cmd, p);
break;
default:
error = scsi_cmd_blk_ioctl(bdev, mode, cmd, p);
break;
case SCSI_IOCTL_GET_IDLUN:
case SCSI_IOCTL_GET_BUS_NUMBER:
break;
default:
error = scsi_cmd_blk_ioctl(bdev, mode, cmd, p);
if (error != -ENOTTY)
return error;
}
out:
return error;
if (in_compat_syscall())
return scsi_compat_ioctl(sdp, cmd, p);
return scsi_ioctl(sdp, cmd, p);
}
static void set_media_not_present(struct scsi_disk *sdkp)
......@@ -1770,34 +1773,6 @@ static void sd_rescan(struct device *dev)
sd_revalidate_disk(sdkp->disk);
}
static int sd_ioctl(struct block_device *bdev, fmode_t mode,
unsigned int cmd, unsigned long arg)
{
void __user *p = (void __user *)arg;
int ret;
ret = sd_ioctl_common(bdev, mode, cmd, p);
if (ret != -ENOTTY)
return ret;
return scsi_ioctl(scsi_disk(bdev->bd_disk)->device, cmd, p);
}
#ifdef CONFIG_COMPAT
static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
unsigned int cmd, unsigned long arg)
{
void __user *p = compat_ptr(arg);
int ret;
ret = sd_ioctl_common(bdev, mode, cmd, p);
if (ret != -ENOTTY)
return ret;
return scsi_compat_ioctl(scsi_disk(bdev->bd_disk)->device, cmd, p);
}
#endif
static char sd_pr_type(enum pr_type type)
{
switch (type) {
......@@ -1898,9 +1873,7 @@ static const struct block_device_operations sd_fops = {
.release = sd_release,
.ioctl = sd_ioctl,
.getgeo = sd_getgeo,
#ifdef CONFIG_COMPAT
.compat_ioctl = sd_compat_ioctl,
#endif
.compat_ioctl = blkdev_compat_ptr_ioctl,
.check_events = sd_check_events,
.unlock_native_capacity = sd_unlock_native_capacity,
.report_zones = sd_zbc_report_zones,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment