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

scsi: ata: Use unsigned int for cmd's type in ioctls in scsi_host_template

Clang warns several times in the scsi subsystem (trimmed for brevity):

drivers/scsi/hpsa.c:6209:7: warning: overflow converting case value to
switch condition type (2147762695 to 18446744071562347015) [-Wswitch]
case CCISS_GETBUSTYPES:
^
drivers/scsi/hpsa.c:6208:7: warning: overflow converting case value to
switch condition type (2147762694 to 18446744071562347014) [-Wswitch]
case CCISS_GETHEARTBEAT:
^

The root cause is that the _IOC macro can generate really large numbers,
which don't fit into type 'int', which is used for the cmd parameter in
the ioctls in scsi_host_template. My research into how GCC and Clang are
handling this at a low level didn't prove fruitful. However, looking at
the rest of the kernel tree, all ioctls use an 'unsigned int' for the
cmd parameter, which will fit all of the _IOC values in the scsi/ata
subsystems.

Make that change because none of the ioctls expect a negative value for
any command, it brings the ioctls inline with the reset of the kernel,
and it removes ambiguity, which is never good when dealing with compilers.

Link: https://github.com/ClangBuiltLinux/linux/issues/85
Link: https://github.com/ClangBuiltLinux/linux/issues/154
Link: https://github.com/ClangBuiltLinux/linux/issues/157
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Acked-by: Bradley Grove <bgrove@attotech.com>
Acked-by: Don Brace <don.brace@microsemi.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Nathan Chancellor and committed by
Martin K. Petersen
6f4e626f 42fb055a

+54 -44
+3 -2
drivers/ata/libata-scsi.c
··· 778 778 } 779 779 780 780 int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev, 781 - int cmd, void __user *arg) 781 + unsigned int cmd, void __user *arg) 782 782 { 783 783 unsigned long val; 784 784 int rc = -EINVAL; ··· 829 829 } 830 830 EXPORT_SYMBOL_GPL(ata_sas_scsi_ioctl); 831 831 832 - int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) 832 + int ata_scsi_ioctl(struct scsi_device *scsidev, unsigned int cmd, 833 + void __user *arg) 833 834 { 834 835 return ata_sas_scsi_ioctl(ata_shost_to_port(scsidev->host), 835 836 scsidev, cmd, arg);
+1 -1
drivers/scsi/aacraid/aachba.c
··· 3455 3455 } 3456 3456 } 3457 3457 3458 - int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg) 3458 + int aac_dev_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg) 3459 3459 { 3460 3460 switch (cmd) { 3461 3461 case FSACTL_QUERY_DISK:
+2 -2
drivers/scsi/aacraid/aacraid.h
··· 2706 2706 int aac_get_config_status(struct aac_dev *dev, int commit_flag); 2707 2707 int aac_get_containers(struct aac_dev *dev); 2708 2708 int aac_scsi_cmd(struct scsi_cmnd *cmd); 2709 - int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg); 2709 + int aac_dev_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg); 2710 2710 #ifndef shost_to_class 2711 2711 #define shost_to_class(shost) &shost->shost_dev 2712 2712 #endif 2713 2713 ssize_t aac_get_serial_number(struct device *dev, char *buf); 2714 - int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg); 2714 + int aac_do_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg); 2715 2715 int aac_rx_init(struct aac_dev *dev); 2716 2716 int aac_rkt_init(struct aac_dev *dev); 2717 2717 int aac_nark_init(struct aac_dev *dev);
+1 -1
drivers/scsi/aacraid/commctrl.c
··· 1060 1060 return retval; 1061 1061 } 1062 1062 1063 - int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg) 1063 + int aac_do_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg) 1064 1064 { 1065 1065 int status; 1066 1066
+4 -2
drivers/scsi/aacraid/linit.c
··· 616 616 NULL, 617 617 }; 618 618 619 - static int aac_ioctl(struct scsi_device *sdev, int cmd, void __user * arg) 619 + static int aac_ioctl(struct scsi_device *sdev, unsigned int cmd, 620 + void __user *arg) 620 621 { 621 622 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata; 622 623 if (!capable(CAP_SYS_RAWIO)) ··· 1206 1205 return ret; 1207 1206 } 1208 1207 1209 - static int aac_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) 1208 + static int aac_compat_ioctl(struct scsi_device *sdev, unsigned int cmd, 1209 + void __user *arg) 1210 1210 { 1211 1211 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata; 1212 1212 if (!capable(CAP_SYS_RAWIO))
+2 -1
drivers/scsi/cxlflash/common.h
··· 334 334 void cxlflash_list_init(void); 335 335 void cxlflash_term_global_luns(void); 336 336 void cxlflash_free_errpage(void); 337 - int cxlflash_ioctl(struct scsi_device *sdev, int cmd, void __user *arg); 337 + int cxlflash_ioctl(struct scsi_device *sdev, unsigned int cmd, 338 + void __user *arg); 338 339 void cxlflash_stop_term_user_contexts(struct cxlflash_cfg *cfg); 339 340 int cxlflash_mark_contexts_error(struct cxlflash_cfg *cfg); 340 341 void cxlflash_term_local_luns(struct cxlflash_cfg *cfg);
+1 -1
drivers/scsi/cxlflash/main.c
··· 3282 3282 * 3283 3283 * Return: A string identifying the decoded host ioctl. 3284 3284 */ 3285 - static char *decode_hioctl(int cmd) 3285 + static char *decode_hioctl(unsigned int cmd) 3286 3286 { 3287 3287 switch (cmd) { 3288 3288 case HT_CXLFLASH_LUN_PROVISION:
+5 -7
drivers/scsi/cxlflash/superpipe.c
··· 1924 1924 * 1925 1925 * Return: A string identifying the decoded ioctl. 1926 1926 */ 1927 - static char *decode_ioctl(int cmd) 1927 + static char *decode_ioctl(unsigned int cmd) 1928 1928 { 1929 1929 switch (cmd) { 1930 1930 case DK_CXLFLASH_ATTACH: ··· 2051 2051 * 2052 2052 * Return: 0 on success, -errno on failure 2053 2053 */ 2054 - static int ioctl_common(struct scsi_device *sdev, int cmd) 2054 + static int ioctl_common(struct scsi_device *sdev, unsigned int cmd) 2055 2055 { 2056 2056 struct cxlflash_cfg *cfg = shost_priv(sdev->host); 2057 2057 struct device *dev = &cfg->dev->dev; ··· 2096 2096 * 2097 2097 * Return: 0 on success, -errno on failure 2098 2098 */ 2099 - int cxlflash_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) 2099 + int cxlflash_ioctl(struct scsi_device *sdev, unsigned int cmd, void __user *arg) 2100 2100 { 2101 2101 typedef int (*sioctl) (struct scsi_device *, void *); 2102 2102 ··· 2179 2179 } 2180 2180 2181 2181 if (unlikely(copy_from_user(&buf, arg, size))) { 2182 - dev_err(dev, "%s: copy_from_user() fail " 2183 - "size=%lu cmd=%d (%s) arg=%p\n", 2182 + dev_err(dev, "%s: copy_from_user() fail size=%lu cmd=%u (%s) arg=%p\n", 2184 2183 __func__, size, cmd, decode_ioctl(cmd), arg); 2185 2184 rc = -EFAULT; 2186 2185 goto cxlflash_ioctl_exit; ··· 2202 2203 rc = do_ioctl(sdev, (void *)&buf); 2203 2204 if (likely(!rc)) 2204 2205 if (unlikely(copy_to_user(arg, &buf, size))) { 2205 - dev_err(dev, "%s: copy_to_user() fail " 2206 - "size=%lu cmd=%d (%s) arg=%p\n", 2206 + dev_err(dev, "%s: copy_to_user() fail size=%lu cmd=%u (%s) arg=%p\n", 2207 2207 __func__, size, cmd, decode_ioctl(cmd), arg); 2208 2208 rc = -EFAULT; 2209 2209 }
+2 -2
drivers/scsi/esas2r/esas2r.h
··· 965 965 const char *esas2r_info(struct Scsi_Host *); 966 966 int esas2r_write_params(struct esas2r_adapter *a, struct esas2r_request *rq, 967 967 struct esas2r_sas_nvram *data); 968 - int esas2r_ioctl_handler(void *hostdata, int cmd, void __user *arg); 969 - int esas2r_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 968 + int esas2r_ioctl_handler(void *hostdata, unsigned int cmd, void __user *arg); 969 + int esas2r_ioctl(struct scsi_device *dev, unsigned int cmd, void __user *arg); 970 970 u8 handle_hba_ioctl(struct esas2r_adapter *a, 971 971 struct atto_ioctl *ioctl_hba); 972 972 int esas2r_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd);
+7 -9
drivers/scsi/esas2r/esas2r_ioctl.c
··· 1274 1274 1275 1275 1276 1276 /* This function only cares about ATTO-specific ioctls (atto_express_ioctl) */ 1277 - int esas2r_ioctl_handler(void *hostdata, int cmd, void __user *arg) 1277 + int esas2r_ioctl_handler(void *hostdata, unsigned int cmd, void __user *arg) 1278 1278 { 1279 1279 struct atto_express_ioctl *ioctl = NULL; 1280 1280 struct esas2r_adapter *a; ··· 1292 1292 ioctl = memdup_user(arg, sizeof(struct atto_express_ioctl)); 1293 1293 if (IS_ERR(ioctl)) { 1294 1294 esas2r_log(ESAS2R_LOG_WARN, 1295 - "ioctl_handler access_ok failed for cmd %d, " 1296 - "address %p", cmd, 1297 - arg); 1295 + "ioctl_handler access_ok failed for cmd %u, address %p", 1296 + cmd, arg); 1298 1297 return PTR_ERR(ioctl); 1299 1298 } 1300 1299 ··· 1492 1493 ioctl_done: 1493 1494 1494 1495 if (err < 0) { 1495 - esas2r_log(ESAS2R_LOG_WARN, "err %d on ioctl cmd %d", err, 1496 + esas2r_log(ESAS2R_LOG_WARN, "err %d on ioctl cmd %u", err, 1496 1497 cmd); 1497 1498 1498 1499 switch (err) { ··· 1517 1518 err = __copy_to_user(arg, ioctl, sizeof(struct atto_express_ioctl)); 1518 1519 if (err != 0) { 1519 1520 esas2r_log(ESAS2R_LOG_WARN, 1520 - "ioctl_handler copy_to_user didn't copy " 1521 - "everything (err %d, cmd %d)", err, 1522 - cmd); 1521 + "ioctl_handler copy_to_user didn't copy everything (err %d, cmd %u)", 1522 + err, cmd); 1523 1523 kfree(ioctl); 1524 1524 1525 1525 return -EFAULT; ··· 1529 1531 return 0; 1530 1532 } 1531 1533 1532 - int esas2r_ioctl(struct scsi_device *sd, int cmd, void __user *arg) 1534 + int esas2r_ioctl(struct scsi_device *sd, unsigned int cmd, void __user *arg) 1533 1535 { 1534 1536 return esas2r_ioctl_handler(sd->host->hostdata, cmd, arg); 1535 1537 }
+1 -1
drivers/scsi/esas2r/esas2r_main.c
··· 623 623 long esas2r_proc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) 624 624 { 625 625 return esas2r_ioctl_handler(esas2r_proc_host->hostdata, 626 - (int)cmd, (void __user *)arg); 626 + cmd, (void __user *)arg); 627 627 } 628 628 629 629 static void __exit esas2r_exit(void)
+9 -6
drivers/scsi/hpsa.c
··· 251 251 252 252 static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id); 253 253 static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id); 254 - static int hpsa_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 254 + static int hpsa_ioctl(struct scsi_device *dev, unsigned int cmd, 255 + void __user *arg); 255 256 256 257 #ifdef CONFIG_COMPAT 257 - static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, 258 + static int hpsa_compat_ioctl(struct scsi_device *dev, unsigned int cmd, 258 259 void __user *arg); 259 260 #endif 260 261 ··· 6128 6127 6129 6128 #ifdef CONFIG_COMPAT 6130 6129 6131 - static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, 6130 + static int hpsa_ioctl32_passthru(struct scsi_device *dev, unsigned int cmd, 6132 6131 void __user *arg) 6133 6132 { 6134 6133 IOCTL32_Command_struct __user *arg32 = ··· 6165 6164 } 6166 6165 6167 6166 static int hpsa_ioctl32_big_passthru(struct scsi_device *dev, 6168 - int cmd, void __user *arg) 6167 + unsigned int cmd, void __user *arg) 6169 6168 { 6170 6169 BIG_IOCTL32_Command_struct __user *arg32 = 6171 6170 (BIG_IOCTL32_Command_struct __user *) arg; ··· 6202 6201 return err; 6203 6202 } 6204 6203 6205 - static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void __user *arg) 6204 + static int hpsa_compat_ioctl(struct scsi_device *dev, unsigned int cmd, 6205 + void __user *arg) 6206 6206 { 6207 6207 switch (cmd) { 6208 6208 case CCISS_GETPCIINFO: ··· 6523 6521 /* 6524 6522 * ioctl 6525 6523 */ 6526 - static int hpsa_ioctl(struct scsi_device *dev, int cmd, void __user *arg) 6524 + static int hpsa_ioctl(struct scsi_device *dev, unsigned int cmd, 6525 + void __user *arg) 6527 6526 { 6528 6527 struct ctlr_info *h; 6529 6528 void __user *argp = (void __user *)arg;
+2 -1
drivers/scsi/ipr.c
··· 6696 6696 * Return value: 6697 6697 * 0 on success / other on failure 6698 6698 **/ 6699 - static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) 6699 + static int ipr_ioctl(struct scsi_device *sdev, unsigned int cmd, 6700 + void __user *arg) 6700 6701 { 6701 6702 struct ipr_resource_entry *res; 6702 6703
+1 -1
drivers/scsi/libsas/sas_scsi_host.c
··· 799 799 shost->host_failed, tries); 800 800 } 801 801 802 - int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) 802 + int sas_ioctl(struct scsi_device *sdev, unsigned int cmd, void __user *arg) 803 803 { 804 804 struct domain_device *dev = sdev_to_domain_dev(sdev); 805 805
+2 -1
drivers/scsi/scsi_debug.c
··· 832 832 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_OPCODE, 0); 833 833 } 834 834 835 - static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) 835 + static int scsi_debug_ioctl(struct scsi_device *dev, unsigned int cmd, 836 + void __user *arg) 836 837 { 837 838 if (sdebug_verbose) { 838 839 if (0x1261 == cmd)
+2 -1
drivers/scsi/smartpqi/smartpqi_init.c
··· 6043 6043 return rc; 6044 6044 } 6045 6045 6046 - static int pqi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) 6046 + static int pqi_ioctl(struct scsi_device *sdev, unsigned int cmd, 6047 + void __user *arg) 6047 6048 { 6048 6049 int rc; 6049 6050 struct pqi_ctrl_info *ctrl_info;
+3 -2
include/linux/libata.h
··· 1122 1122 extern void ata_host_detach(struct ata_host *host); 1123 1123 extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *); 1124 1124 extern int ata_scsi_detect(struct scsi_host_template *sht); 1125 - extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 1125 + extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd, 1126 + void __user *arg); 1126 1127 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd); 1127 1128 extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev, 1128 - int cmd, void __user *arg); 1129 + unsigned int cmd, void __user *arg); 1129 1130 extern void ata_sas_port_destroy(struct ata_port *); 1130 1131 extern struct ata_port *ata_sas_port_alloc(struct ata_host *, 1131 1132 struct ata_port_info *, struct Scsi_Host *);
+2 -1
include/scsi/libsas.h
··· 707 707 708 708 extern void sas_target_destroy(struct scsi_target *); 709 709 extern int sas_slave_alloc(struct scsi_device *); 710 - extern int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg); 710 + extern int sas_ioctl(struct scsi_device *sdev, unsigned int cmd, 711 + void __user *arg); 711 712 extern int sas_drain_work(struct sas_ha_struct *ha); 712 713 713 714 extern void sas_ssp_task_response(struct device *dev, struct sas_task *task,
+4 -2
include/scsi/scsi_host.h
··· 60 60 * 61 61 * Status: OPTIONAL 62 62 */ 63 - int (* ioctl)(struct scsi_device *dev, int cmd, void __user *arg); 63 + int (*ioctl)(struct scsi_device *dev, unsigned int cmd, 64 + void __user *arg); 64 65 65 66 66 67 #ifdef CONFIG_COMPAT ··· 71 70 * 72 71 * Status: OPTIONAL 73 72 */ 74 - int (* compat_ioctl)(struct scsi_device *dev, int cmd, void __user *arg); 73 + int (*compat_ioctl)(struct scsi_device *dev, unsigned int cmd, 74 + void __user *arg); 75 75 #endif 76 76 77 77 /*