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

scsi: scsi_ioctl: Factor SCSI_IOCTL_GET_IDLUN handling into a helper

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

Link: https://lore.kernel.org/r/20210724072033.1284840-23-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
2102a5cc 51476187

+16 -12
+16 -12
drivers/scsi/scsi_ioctl.c
··· 218 218 return put_user(1, p); 219 219 } 220 220 221 + static int scsi_get_idlun(struct scsi_device *sdev, void __user *argp) 222 + { 223 + struct scsi_idlun v = { 224 + .dev_id = (sdev->id & 0xff) + 225 + ((sdev->lun & 0xff) << 8) + 226 + ((sdev->channel & 0xff) << 16) + 227 + ((sdev->host->host_no & 0xff) << 24), 228 + .host_unique_id = sdev->host->unique_id 229 + }; 230 + if (copy_to_user(argp, &v, sizeof(struct scsi_idlun))) 231 + return -EFAULT; 232 + return 0; 233 + } 234 + 221 235 static int scsi_send_start_stop(struct scsi_device *sdev, int data) 222 236 { 223 237 u8 cdb[MAX_COMMAND_SIZE] = { }; ··· 935 921 return scsi_send_start_stop(sdev, 3); 936 922 case CDROMEJECT: 937 923 return scsi_send_start_stop(sdev, 2); 938 - case SCSI_IOCTL_GET_IDLUN: { 939 - struct scsi_idlun v = { 940 - .dev_id = (sdev->id & 0xff) 941 - + ((sdev->lun & 0xff) << 8) 942 - + ((sdev->channel & 0xff) << 16) 943 - + ((sdev->host->host_no & 0xff) << 24), 944 - .host_unique_id = sdev->host->unique_id 945 - }; 946 - if (copy_to_user(arg, &v, sizeof(struct scsi_idlun))) 947 - return -EFAULT; 948 - return 0; 949 - } 924 + case SCSI_IOCTL_GET_IDLUN: 925 + return scsi_get_idlun(sdev, arg); 950 926 case SCSI_IOCTL_GET_BUS_NUMBER: 951 927 return put_user(sdev->host->host_no, (int __user *)arg); 952 928 case SCSI_IOCTL_PROBE_HOST: