History

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.

Nathan Chancellor committed 7 years ago

Commit 6f4e6261 parent 42fb05519 files · +54 −44Browse files

Unified · Split

19 files
  1. drivers/ata/libata-scsi.c +3 −2
  2. drivers/scsi/aacraid/aachba.c +1 −1
  3. drivers/scsi/aacraid/aacraid.h +2 −2
  4. drivers/scsi/aacraid/commctrl.c +1 −1
  5. drivers/scsi/aacraid/linit.c +4 −2
  6. drivers/scsi/cxlflash/common.h +2 −1
  7. drivers/scsi/cxlflash/main.c +1 −1
  8. drivers/scsi/cxlflash/superpipe.c +5 −7
  9. drivers/scsi/esas2r/esas2r.h +2 −2
  10. drivers/scsi/esas2r/esas2r_ioctl.c +7 −9
  11. drivers/scsi/esas2r/esas2r_main.c +1 −1
  12. drivers/scsi/hpsa.c +9 −6
  13. drivers/scsi/ipr.c +2 −1
  14. drivers/scsi/libsas/sas_scsi_host.c +1 −1
  15. drivers/scsi/scsi_debug.c +2 −1
  16. drivers/scsi/smartpqi/smartpqi_init.c +2 −1
  17. include/linux/libata.h +3 −2
  18. include/scsi/libsas.h +2 −1
  19. include/scsi/scsi_host.h +4 −2
drivers/ata/libata-scsi.c+3−2
@@ -778,7 +778,7 @@ static int ata_ioc32(struct ata_port *ap) · 777 unmodified lines
778778 }
779779
780780 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)
782782 {
783783 unsigned long val;
784784 int rc = -EINVAL;
@@ -829,7 +829,8 @@ int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev, · 44 unmodified lines
829829 }
830830 EXPORT_SYMBOL_GPL(ata_sas_scsi_ioctl);
831831
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)
833834 {
834835 return ata_sas_scsi_ioctl(ata_shost_to_port(scsidev->host),
835836 scsidev, cmd, arg);
drivers/scsi/aacraid/aachba.c+1−1
@@ -3455,7 +3455,7 @@ static int delete_disk(struct aac_dev *dev, void __user *arg) · 3454 unmodified lines
34553455 }
34563456 }
34573457
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)
34593459 {
34603460 switch (cmd) {
34613461 case FSACTL_QUERY_DISK:
drivers/scsi/aacraid/aacraid.h+2−2
@@ -2706,12 +2706,12 @@ void aac_set_intx_mode(struct aac_dev *dev); · 2705 unmodified lines
27062706 int aac_get_config_status(struct aac_dev *dev, int commit_flag);
27072707 int aac_get_containers(struct aac_dev *dev);
27082708 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);
27102710 #ifndef shost_to_class
27112711 #define shost_to_class(shost) &shost->shost_dev
27122712 #endif
27132713 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);
27152715 int aac_rx_init(struct aac_dev *dev);
27162716 int aac_rkt_init(struct aac_dev *dev);
27172717 int aac_nark_init(struct aac_dev *dev);
drivers/scsi/aacraid/commctrl.c+1−1
@@ -1060,7 +1060,7 @@ static int aac_send_reset_adapter(struct aac_dev *dev, void __user *arg) · 1059 unmodified lines
10601060 return retval;
10611061 }
10621062
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)
10641064 {
10651065 int status;
10661066
drivers/scsi/aacraid/linit.c+4−2
@@ -616,7 +616,8 @@ static struct device_attribute *aac_dev_attrs[] = { · 615 unmodified lines
616616 NULL,
617617 };
618618
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)
620621 {
621622 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
622623 if (!capable(CAP_SYS_RAWIO))
@@ -1205,7 +1206,8 @@ static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long · 582 unmodified lines
12051206 return ret;
12061207 }
12071208
1208−static int aac_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
1209+static int aac_compat_ioctl(struct scsi_device *sdev, unsigned int cmd,
1210+ void __user *arg)
12091211 {
12101212 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
12111213 if (!capable(CAP_SYS_RAWIO))
drivers/scsi/cxlflash/common.h+2−1
@@ -334,7 +334,8 @@ int cxlflash_afu_sync(struct afu *afu, ctx_hndl_t c, res_hndl_t r, u8 mode); · 333 unmodified lines
334334 void cxlflash_list_init(void);
335335 void cxlflash_term_global_luns(void);
336336 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);
338339 void cxlflash_stop_term_user_contexts(struct cxlflash_cfg *cfg);
339340 int cxlflash_mark_contexts_error(struct cxlflash_cfg *cfg);
340341 void cxlflash_term_local_luns(struct cxlflash_cfg *cfg);
drivers/scsi/cxlflash/main.c+1−1
@@ -3282,7 +3282,7 @@ static int cxlflash_chr_open(struct inode *inode, struct file *file) · 3281 unmodified lines
32823282 *
32833283 * Return: A string identifying the decoded host ioctl.
32843284 */
3285−static char *decode_hioctl(int cmd)
3285+static char *decode_hioctl(unsigned int cmd)
32863286 {
32873287 switch (cmd) {
32883288 case HT_CXLFLASH_LUN_PROVISION:
drivers/scsi/cxlflash/superpipe.c+5−7
@@ -1924,7 +1924,7 @@ out: · 1923 unmodified lines
19241924 *
19251925 * Return: A string identifying the decoded ioctl.
19261926 */
1927−static char *decode_ioctl(int cmd)
1927+static char *decode_ioctl(unsigned int cmd)
19281928 {
19291929 switch (cmd) {
19301930 case DK_CXLFLASH_ATTACH:
@@ -2051,7 +2051,7 @@ err1: · 120 unmodified lines
20512051 *
20522052 * Return: 0 on success, -errno on failure
20532053 */
2054−static int ioctl_common(struct scsi_device *sdev, int cmd)
2054+static int ioctl_common(struct scsi_device *sdev, unsigned int cmd)
20552055 {
20562056 struct cxlflash_cfg *cfg = shost_priv(sdev->host);
20572057 struct device *dev = &cfg->dev->dev;
@@ -2096,7 +2096,7 @@ out: · 38 unmodified lines
20962096 *
20972097 * Return: 0 on success, -errno on failure
20982098 */
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)
21002100 {
21012101 typedef int (*sioctl) (struct scsi_device *, void *);
21022102
@@ -2179,8 +2179,7 @@ int cxlflash_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) · 76 unmodified lines
21792179 }
21802180
21812181 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",
21842183 __func__, size, cmd, decode_ioctl(cmd), arg);
21852184 rc = -EFAULT;
21862185 goto cxlflash_ioctl_exit;
@@ -2203,8 +2202,7 @@ int cxlflash_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) · 16 unmodified lines
22032202 rc = do_ioctl(sdev, (void *)&buf);
22042203 if (likely(!rc))
22052204 if (unlikely(copy_to_user(arg, &buf, size))) {
2206− dev_err(dev, "%s: copy_to_user() fail "
2207− "size=%lu cmd=%d (%s) arg=%p\n",
2205+ dev_err(dev, "%s: copy_to_user() fail size=%lu cmd=%u (%s) arg=%p\n",
22082206 __func__, size, cmd, decode_ioctl(cmd), arg);
22092207 rc = -EFAULT;
22102208 }
drivers/scsi/esas2r/esas2r.h+2−2
@@ -965,8 +965,8 @@ struct esas2r_adapter { · 964 unmodified lines
965965 const char *esas2r_info(struct Scsi_Host *);
966966 int esas2r_write_params(struct esas2r_adapter *a, struct esas2r_request *rq,
967967 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);
970970 u8 handle_hba_ioctl(struct esas2r_adapter *a,
971971 struct atto_ioctl *ioctl_hba);
972972 int esas2r_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd);
drivers/scsi/esas2r/esas2r_ioctl.c+7−9
@@ -1274,7 +1274,7 @@ int esas2r_write_params(struct esas2r_adapter *a, struct esas2r_request *rq, · 1273 unmodified lines
12741274
12751275
12761276 /* 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)
12781278 {
12791279 struct atto_express_ioctl *ioctl = NULL;
12801280 struct esas2r_adapter *a;
@@ -1292,9 +1292,8 @@ int esas2r_ioctl_handler(void *hostdata, int cmd, void __user *arg) · 11 unmodified lines
12921292 ioctl = memdup_user(arg, sizeof(struct atto_express_ioctl));
12931293 if (IS_ERR(ioctl)) {
12941294 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);
12981297 return PTR_ERR(ioctl);
12991298 }
13001299
@@ -1493,7 +1492,7 @@ int esas2r_ioctl_handler(void *hostdata, int cmd, void __user *arg) · 192 unmodified lines
14931492 ioctl_done:
14941493
14951494 if (err < 0) {
1496− esas2r_log(ESAS2R_LOG_WARN, "err %d on ioctl cmd %d", err,
1495+ esas2r_log(ESAS2R_LOG_WARN, "err %d on ioctl cmd %u", err,
14971496 cmd);
14981497
14991498 switch (err) {
@@ -1518,9 +1517,8 @@ ioctl_done: · 18 unmodified lines
15181517 err = __copy_to_user(arg, ioctl, sizeof(struct atto_express_ioctl));
15191518 if (err != 0) {
15201519 esas2r_log(ESAS2R_LOG_WARN,
1521− "ioctl_handler copy_to_user didn't copy "
1522− "everything (err %d, cmd %d)", err,
1523− cmd);
1520+ "ioctl_handler copy_to_user didn't copy everything (err %d, cmd %u)",
1521+ err, cmd);
15241522 kfree(ioctl);
15251523
15261524 return -EFAULT;
@@ -1531,7 +1529,7 @@ ioctl_done: · 4 unmodified lines
15311529 return 0;
15321530 }
15331531
1534−int esas2r_ioctl(struct scsi_device *sd, int cmd, void __user *arg)
1532+int esas2r_ioctl(struct scsi_device *sd, unsigned int cmd, void __user *arg)
15351533 {
15361534 return esas2r_ioctl_handler(sd->host->hostdata, cmd, arg);
15371535 }
drivers/scsi/esas2r/esas2r_main.c+1−1
@@ -623,7 +623,7 @@ static int esas2r_proc_major; · 622 unmodified lines
623623 long esas2r_proc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
624624 {
625625 return esas2r_ioctl_handler(esas2r_proc_host->hostdata,
626− (int)cmd, (void __user *)arg);
626+ cmd, (void __user *)arg);
627627 }
628628
629629 static void __exit esas2r_exit(void)
drivers/scsi/hpsa.c+9−6
@@ -251,10 +251,11 @@ static int number_of_controllers; · 250 unmodified lines
251251
252252 static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id);
253253 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);
255256
256257 #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,
258259 void __user *arg);
259260 #endif
260261
@@ -6127,7 +6128,7 @@ static void cmd_free(struct ctlr_info *h, struct CommandList *c) · 5866 unmodified lines
61276128
61286129 #ifdef CONFIG_COMPAT
61296130
6130−static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd,
6131+static int hpsa_ioctl32_passthru(struct scsi_device *dev, unsigned int cmd,
61316132 void __user *arg)
61326133 {
61336134 IOCTL32_Command_struct __user *arg32 =
@@ -6164,7 +6165,7 @@ static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, · 30 unmodified lines
61646165 }
61656166
61666167 static int hpsa_ioctl32_big_passthru(struct scsi_device *dev,
6167− int cmd, void __user *arg)
6168+ unsigned int cmd, void __user *arg)
61686169 {
61696170 BIG_IOCTL32_Command_struct __user *arg32 =
61706171 (BIG_IOCTL32_Command_struct __user *) arg;
@@ -6201,7 +6202,8 @@ static int hpsa_ioctl32_big_passthru(struct scsi_device *dev, · 30 unmodified lines
62016202 return err;
62026203 }
62036204
6204−static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
6205+static int hpsa_compat_ioctl(struct scsi_device *dev, unsigned int cmd,
6206+ void __user *arg)
62056207 {
62066208 switch (cmd) {
62076209 case CCISS_GETPCIINFO:
@@ -6521,7 +6523,8 @@ static void check_ioctl_unit_attention(struct ctlr_info *h, · 313 unmodified lines
65216523 /*
65226524 * ioctl
65236525 */
6524−static int hpsa_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
6526+static int hpsa_ioctl(struct scsi_device *dev, unsigned int cmd,
6527+ void __user *arg)
65256528 {
65266529 struct ctlr_info *h;
65276530 void __user *argp = (void __user *)arg;
drivers/scsi/ipr.c+2−1
@@ -6696,7 +6696,8 @@ err_nodev: · 6695 unmodified lines
66966696 * Return value:
66976697 * 0 on success / other on failure
66986698 **/
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)
67006701 {
67016702 struct ipr_resource_entry *res;
67026703
drivers/scsi/libsas/sas_scsi_host.c+1−1
@@ -799,7 +799,7 @@ out: · 798 unmodified lines
799799 shost->host_failed, tries);
800800 }
801801
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)
803803 {
804804 struct domain_device *dev = sdev_to_domain_dev(sdev);
805805
drivers/scsi/scsi_debug.c+2−1
@@ -832,7 +832,8 @@ static void mk_sense_invalid_opcode(struct scsi_cmnd *scp) · 831 unmodified lines
832832 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_OPCODE, 0);
833833 }
834834
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)
836837 {
837838 if (sdebug_verbose) {
838839 if (0x1261 == cmd)
drivers/scsi/smartpqi/smartpqi_init.c+2−1
@@ -6043,7 +6043,8 @@ out: · 6042 unmodified lines
60436043 return rc;
60446044 }
60456045
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)
60476048 {
60486049 int rc;
60496050 struct pqi_ctrl_info *ctrl_info;
include/linux/libata.h+3−2
@@ -1122,10 +1122,11 @@ extern int ata_host_activate(struct ata_host *host, int irq, · 1121 unmodified lines
11221122 extern void ata_host_detach(struct ata_host *host);
11231123 extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *);
11241124 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);
11261127 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
11271128 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);
11291130 extern void ata_sas_port_destroy(struct ata_port *);
11301131 extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
11311132 struct ata_port_info *, struct Scsi_Host *);
include/scsi/libsas.h+2−1
@@ -707,7 +707,8 @@ int sas_eh_target_reset_handler(struct scsi_cmnd *cmd); · 706 unmodified lines
707707
708708 extern void sas_target_destroy(struct scsi_target *);
709709 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);
711712 extern int sas_drain_work(struct sas_ha_struct *ha);
712713
713714 extern void sas_ssp_task_response(struct device *dev, struct sas_task *task,
include/scsi/scsi_host.h+4−2
@@ -60,7 +60,8 @@ struct scsi_host_template { · 59 unmodified lines
6060 *
6161 * Status: OPTIONAL
6262 */
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);
6465
6566
6667 #ifdef CONFIG_COMPAT
@@ -70,7 +71,8 @@ struct scsi_host_template { · 3 unmodified lines
7071 *
7172 * Status: OPTIONAL
7273 */
73− int (* compat_ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
74+ int (*compat_ioctl)(struct scsi_device *dev, unsigned int cmd,
75+ void __user *arg);
7476 #endif
7577
7678 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t