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

Configure Feed

Select the types of activity you want to include in your feed.

scsi: replace the fmode_t argument to scsi_ioctl with a simple bool

Instead of passing a fmode_t and only checking it for FMODE_WRITE, pass
a bool open_for_write to prepare for callers that won't have the fmode_t.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Christian Brauner <brauner@kernel.org>
Link: https://lore.kernel.org/r/20230608110258.189493-20-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
2e80089c 5f4eb9d5

+26 -24
+2 -1
drivers/scsi/ch.c
··· 877 877 } 878 878 879 879 default: 880 - return scsi_ioctl(ch->device, file->f_mode, cmd, argp); 880 + return scsi_ioctl(ch->device, file->f_mode & FMODE_WRITE, cmd, 881 + argp); 881 882 882 883 } 883 884 }
+17 -17
drivers/scsi/scsi_ioctl.c
··· 346 346 EXPORT_SYMBOL(scsi_cmd_allowed); 347 347 348 348 static int scsi_fill_sghdr_rq(struct scsi_device *sdev, struct request *rq, 349 - struct sg_io_hdr *hdr, fmode_t mode) 349 + struct sg_io_hdr *hdr, bool open_for_write) 350 350 { 351 351 struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq); 352 352 ··· 354 354 return -EMSGSIZE; 355 355 if (copy_from_user(scmd->cmnd, hdr->cmdp, hdr->cmd_len)) 356 356 return -EFAULT; 357 - if (!scsi_cmd_allowed(scmd->cmnd, mode & FMODE_WRITE)) 357 + if (!scsi_cmd_allowed(scmd->cmnd, open_for_write)) 358 358 return -EPERM; 359 359 scmd->cmd_len = hdr->cmd_len; 360 360 ··· 407 407 return ret; 408 408 } 409 409 410 - static int sg_io(struct scsi_device *sdev, struct sg_io_hdr *hdr, fmode_t mode) 410 + static int sg_io(struct scsi_device *sdev, struct sg_io_hdr *hdr, 411 + bool open_for_write) 411 412 { 412 413 unsigned long start_time; 413 414 ssize_t ret = 0; ··· 449 448 goto out_put_request; 450 449 } 451 450 452 - ret = scsi_fill_sghdr_rq(sdev, rq, hdr, mode); 451 + ret = scsi_fill_sghdr_rq(sdev, rq, hdr, open_for_write); 453 452 if (ret < 0) 454 453 goto out_put_request; 455 454 ··· 478 477 /** 479 478 * sg_scsi_ioctl -- handle deprecated SCSI_IOCTL_SEND_COMMAND ioctl 480 479 * @q: request queue to send scsi commands down 481 - * @mode: mode used to open the file through which the ioctl has been 482 - * submitted 480 + * @open_for_write: is the file / block device opened for writing? 483 481 * @sic: userspace structure describing the command to perform 484 482 * 485 483 * Send down the scsi command described by @sic to the device below ··· 501 501 * Positive numbers returned are the compacted SCSI error codes (4 502 502 * bytes in one int) where the lowest byte is the SCSI status. 503 503 */ 504 - static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode, 504 + static int sg_scsi_ioctl(struct request_queue *q, bool open_for_write, 505 505 struct scsi_ioctl_command __user *sic) 506 506 { 507 507 struct request *rq; ··· 554 554 goto error; 555 555 556 556 err = -EPERM; 557 - if (!scsi_cmd_allowed(scmd->cmnd, mode & FMODE_WRITE)) 557 + if (!scsi_cmd_allowed(scmd->cmnd, open_for_write)) 558 558 goto error; 559 559 560 560 /* default. possible overridden later */ ··· 776 776 return 0; 777 777 } 778 778 779 - static int scsi_cdrom_send_packet(struct scsi_device *sdev, fmode_t mode, 779 + static int scsi_cdrom_send_packet(struct scsi_device *sdev, bool open_for_write, 780 780 void __user *arg) 781 781 { 782 782 struct cdrom_generic_command cgc; ··· 817 817 hdr.cmdp = ((struct cdrom_generic_command __user *) arg)->cmd; 818 818 hdr.cmd_len = sizeof(cgc.cmd); 819 819 820 - err = sg_io(sdev, &hdr, mode); 820 + err = sg_io(sdev, &hdr, open_for_write); 821 821 if (err == -EFAULT) 822 822 return -EFAULT; 823 823 ··· 832 832 return err; 833 833 } 834 834 835 - static int scsi_ioctl_sg_io(struct scsi_device *sdev, fmode_t mode, 835 + static int scsi_ioctl_sg_io(struct scsi_device *sdev, bool open_for_write, 836 836 void __user *argp) 837 837 { 838 838 struct sg_io_hdr hdr; ··· 841 841 error = get_sg_io_hdr(&hdr, argp); 842 842 if (error) 843 843 return error; 844 - error = sg_io(sdev, &hdr, mode); 844 + error = sg_io(sdev, &hdr, open_for_write); 845 845 if (error == -EFAULT) 846 846 return error; 847 847 if (put_sg_io_hdr(&hdr, argp)) ··· 852 852 /** 853 853 * scsi_ioctl - Dispatch ioctl to scsi device 854 854 * @sdev: scsi device receiving ioctl 855 - * @mode: mode the block/char device is opened with 855 + * @open_for_write: is the file / block device opened for writing? 856 856 * @cmd: which ioctl is it 857 857 * @arg: data associated with ioctl 858 858 * ··· 860 860 * does not take a major/minor number as the dev field. Rather, it takes 861 861 * a pointer to a &struct scsi_device. 862 862 */ 863 - int scsi_ioctl(struct scsi_device *sdev, fmode_t mode, int cmd, 863 + int scsi_ioctl(struct scsi_device *sdev, bool open_for_write, int cmd, 864 864 void __user *arg) 865 865 { 866 866 struct request_queue *q = sdev->request_queue; ··· 896 896 case SG_EMULATED_HOST: 897 897 return sg_emulated_host(q, arg); 898 898 case SG_IO: 899 - return scsi_ioctl_sg_io(sdev, mode, arg); 899 + return scsi_ioctl_sg_io(sdev, open_for_write, arg); 900 900 case SCSI_IOCTL_SEND_COMMAND: 901 - return sg_scsi_ioctl(q, mode, arg); 901 + return sg_scsi_ioctl(q, open_for_write, arg); 902 902 case CDROM_SEND_PACKET: 903 - return scsi_cdrom_send_packet(sdev, mode, arg); 903 + return scsi_cdrom_send_packet(sdev, open_for_write, arg); 904 904 case CDROMCLOSETRAY: 905 905 return scsi_send_start_stop(sdev, 3); 906 906 case CDROMEJECT:
+1 -1
drivers/scsi/sd.c
··· 1463 1463 1464 1464 if (is_sed_ioctl(cmd)) 1465 1465 return sed_ioctl(sdkp->opal_dev, cmd, p); 1466 - return scsi_ioctl(sdp, mode, cmd, p); 1466 + return scsi_ioctl(sdp, mode & FMODE_WRITE, cmd, p); 1467 1467 } 1468 1468 1469 1469 static void set_media_not_present(struct scsi_disk *sdkp)
+3 -2
drivers/scsi/sg.c
··· 1103 1103 case SCSI_IOCTL_SEND_COMMAND: 1104 1104 if (atomic_read(&sdp->detaching)) 1105 1105 return -ENODEV; 1106 - return scsi_ioctl(sdp->device, filp->f_mode, cmd_in, p); 1106 + return scsi_ioctl(sdp->device, filp->f_mode & FMODE_WRITE, 1107 + cmd_in, p); 1107 1108 case SG_SET_DEBUG: 1108 1109 result = get_user(val, ip); 1109 1110 if (result) ··· 1160 1159 ret = sg_ioctl_common(filp, sdp, sfp, cmd_in, p); 1161 1160 if (ret != -ENOIOCTLCMD) 1162 1161 return ret; 1163 - return scsi_ioctl(sdp->device, filp->f_mode, cmd_in, p); 1162 + return scsi_ioctl(sdp->device, filp->f_mode & FMODE_WRITE, cmd_in, p); 1164 1163 } 1165 1164 1166 1165 static __poll_t
+1 -1
drivers/scsi/sr.c
··· 543 543 if (ret != -ENOSYS) 544 544 goto put; 545 545 } 546 - ret = scsi_ioctl(sdev, mode, cmd, argp); 546 + ret = scsi_ioctl(sdev, mode & FMODE_WRITE, cmd, argp); 547 547 548 548 put: 549 549 scsi_autopm_put_device(sdev);
+1 -1
drivers/scsi/st.c
··· 3832 3832 break; 3833 3833 } 3834 3834 3835 - retval = scsi_ioctl(STp->device, file->f_mode, cmd_in, p); 3835 + retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE, cmd_in, p); 3836 3836 if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) { 3837 3837 /* unload */ 3838 3838 STp->rew_at_close = 0;
+1 -1
include/scsi/scsi_ioctl.h
··· 45 45 46 46 int scsi_ioctl_block_when_processing_errors(struct scsi_device *sdev, 47 47 int cmd, bool ndelay); 48 - int scsi_ioctl(struct scsi_device *sdev, fmode_t mode, int cmd, 48 + int scsi_ioctl(struct scsi_device *sdev, bool open_for_write, int cmd, 49 49 void __user *arg); 50 50 int get_sg_io_hdr(struct sg_io_hdr *hdr, const void __user *argp); 51 51 int put_sg_io_hdr(const struct sg_io_hdr *hdr, void __user *argp);