Skip to content

Commit 6f4e626

Browse files
nathanchancemartinkpetersen
authored andcommitted
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: ClangBuiltLinux/linux#85 Link: ClangBuiltLinux/linux#154 Link: ClangBuiltLinux/linux#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>
1 parent 42fb055 commit 6f4e626

19 files changed

Lines changed: 54 additions & 44 deletions

File tree

‎drivers/ata/libata-scsi.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ static int ata_ioc32(struct ata_port *ap)
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,
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3455,7 +3455,7 @@ static int delete_disk(struct aac_dev *dev, void __user *arg)
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‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,12 +2706,12 @@ void aac_set_intx_mode(struct aac_dev *dev);
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ static int aac_send_reset_adapter(struct aac_dev *dev, void __user *arg)
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‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ static struct device_attribute *aac_dev_attrs[] = {
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
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‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ int cxlflash_afu_sync(struct afu *afu, ctx_hndl_t c, res_hndl_t r, u8 mode);
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3282,7 +3282,7 @@ static int cxlflash_chr_open(struct inode *inode, struct file *file)
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‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ static int cxlflash_disk_verify(struct scsi_device *sdev,
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 @@ static int cxlflash_disk_direct_open(struct scsi_device *sdev, void *arg)
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 @@ static int ioctl_common(struct scsi_device *sdev, int cmd)
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)
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)
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‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,8 @@ struct esas2r_adapter {
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‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ int esas2r_write_params(struct esas2r_adapter *a, struct esas2r_request *rq,
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)
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)
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 @@ int esas2r_ioctl_handler(void *hostdata, int cmd, void __user *arg)
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 @@ int esas2r_ioctl_handler(void *hostdata, int cmd, void __user *arg)
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
}

0 commit comments

Comments
 (0)