From 176aa9d6ee2db582e7e856dbe1983004a82869b4 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sat, 11 Oct 2014 12:06:47 +0200 Subject: scsi: refactor scsi_reset_provider handling Pull the common code from the two callers into the function, and rename it to scsi_ioctl_reset. Signed-off-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Reviewed-by: Hannes Reinecke --- drivers/scsi/sg.c | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) (limited to 'drivers/scsi/sg.c') diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 2fe2701d86db..7c55cacceb7c 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -847,7 +847,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) { void __user *p = (void __user *)arg; int __user *ip = p; - int result, val, val2, read_only; + int result, val, read_only; Sg_device *sdp; Sg_fd *sfp; Sg_request *srp; @@ -1079,36 +1079,8 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) return -EBUSY; } else if (!scsi_block_when_processing_errors(sdp->device)) return -EBUSY; - result = get_user(val, ip); - if (result) - return result; - if (val & SG_SCSI_RESET_NO_ESCALATE) { - val &= ~SG_SCSI_RESET_NO_ESCALATE; - val2 = SCSI_TRY_RESET_NO_ESCALATE; - } else - val2 = 0; - if (SG_SCSI_RESET_NOTHING == val) - return 0; - switch (val) { - case SG_SCSI_RESET_DEVICE: - val2 |= SCSI_TRY_RESET_DEVICE; - break; - case SG_SCSI_RESET_TARGET: - val2 |= SCSI_TRY_RESET_TARGET; - break; - case SG_SCSI_RESET_BUS: - val2 |= SCSI_TRY_RESET_BUS; - break; - case SG_SCSI_RESET_HOST: - val2 |= SCSI_TRY_RESET_HOST; - break; - default: - return -EINVAL; - } - if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) - return -EACCES; - return (scsi_reset_provider(sdp->device, val2) == - SUCCESS) ? 0 : -EIO; + + return scsi_ioctl_reset(sdp->device, ip); case SCSI_IOCTL_SEND_COMMAND: if (atomic_read(&sdp->detaching)) return -ENODEV; -- cgit v1.2.3-59-g8ed1b