Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: scsi_ioctl: Factor SG_IO handling into a helper

Split the SG_IO handler from the main scsi_ioctl() routine.

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

authored by

Christoph Hellwig and committed by
Martin K. Petersen
b2123d3b 2102a5cc

+19 -16
+19 -16
drivers/scsi/scsi_ioctl.c
··· 864 864 return err; 865 865 } 866 866 867 + static int scsi_ioctl_sg_io(struct request_queue *q, struct gendisk *disk, 868 + fmode_t mode, void __user *argp) 869 + { 870 + struct sg_io_hdr hdr; 871 + int error; 872 + 873 + error = get_sg_io_hdr(&hdr, argp); 874 + if (error) 875 + return error; 876 + error = sg_io(q, disk, &hdr, mode); 877 + if (error == -EFAULT) 878 + return error; 879 + if (put_sg_io_hdr(&hdr, argp)) 880 + return -EFAULT; 881 + return 0; 882 + } 883 + 867 884 /** 868 885 * scsi_ioctl - Dispatch ioctl to scsi device 869 886 * @sdev: scsi device receiving ioctl ··· 898 881 { 899 882 struct request_queue *q = sdev->request_queue; 900 883 struct scsi_sense_hdr sense_hdr; 901 - int error; 902 884 903 885 /* Check for deprecated ioctls ... all the ioctls which don't 904 886 * follow the new unique numbering scheme are deprecated */ ··· 928 912 return sg_set_reserved_size(q, arg); 929 913 case SG_EMULATED_HOST: 930 914 return sg_emulated_host(q, arg); 931 - case SG_IO: { 932 - struct sg_io_hdr hdr; 933 - 934 - error = get_sg_io_hdr(&hdr, arg); 935 - if (error) 936 - return error; 937 - 938 - error = sg_io(q, disk, &hdr, mode); 939 - if (error == -EFAULT) 940 - return error; 941 - 942 - if (put_sg_io_hdr(&hdr, arg)) 943 - return -EFAULT; 944 - return 0; 945 - } 915 + case SG_IO: 916 + return scsi_ioctl_sg_io(q, disk, mode, arg); 946 917 case SCSI_IOCTL_SEND_COMMAND: 947 918 return sg_scsi_ioctl(q, disk, mode, arg); 948 919 case CDROM_SEND_PACKET: