mirror of
https://github.com/SCST-project/scst.git
synced 2026-10-22 06:02:33 +00:00
scst: Match numeric formats while preserving identifier spelling
Cppcheck reports at the affected calls:
invalidPrintfArgType_sint: %d requires 'int' but the argument type
is 'unsigned int'.
invalidPrintfArgType_sint: %zd requires 'ssize_t' but the argument
type is 'size_t {aka unsigned long}'.
invalidPrintfArgType_uint: %llx requires 'unsigned long long' but
the argument type is 'unsigned long'.
invalidPrintfArgType_uint: %u requires 'unsigned int' but the
argument type is 'signed int'.
invalidScanfArgType_int: %lld requires 'long long *' but the
argument type is 'unsigned long long *'.
Use unsigned formats for command states, event IDs, handles and sizes.
Cast the u64 disk ID for %llx on both 32-bit and 64-bit builds. Preserve
unsigned export-link naming through an explicit counter conversion. Use
%llu for the unsigned virtual-disk size destination; retain the byte/MiB
shifts and overflow check.
At five DLM lock-name calls, explicitly convert node IDs to int for the
existing %d formats. Switching them to %u would change high-bit node
IDs' lock identities and break matching with older peers. Preserve that
signed spelling and leave membership and node-ID storage unchanged.
This commit is contained in:
@@ -589,7 +589,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event)
|
||||
res = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
snprintf(res_str, sizeof(res_str), "%d\n", target->per_portal_acl);
|
||||
snprintf(res_str, sizeof(res_str), "%u\n", target->per_portal_acl);
|
||||
if (target->per_portal_acl)
|
||||
add_key_mark(res_str, sizeof(res_str), 0);
|
||||
} else if (strcasecmp(ISCSI_TARGET_REDIRECTION_ATTR_NAME, pp) == 0) {
|
||||
|
||||
@@ -6590,7 +6590,7 @@ static int vdev_create_node(struct scst_dev_type *devt, const char *name, int no
|
||||
dev_id_num = vdisk_gen_dev_id_num(virt_dev->name);
|
||||
|
||||
snprintf(virt_dev->t10_dev_id, sizeof(virt_dev->t10_dev_id),
|
||||
"%llx-%s", dev_id_num, virt_dev->name);
|
||||
"%llx-%s", (unsigned long long)dev_id_num, virt_dev->name);
|
||||
TRACE_DBG("t10_dev_id %s", virt_dev->t10_dev_id);
|
||||
|
||||
sprintf(virt_dev->t10_vend_id, "%.*s",
|
||||
@@ -6612,7 +6612,8 @@ static int vdev_create_node(struct scst_dev_type *devt, const char *name, int no
|
||||
virt_dev->eui64_id_len = 0;
|
||||
virt_dev->naa_id_len = 0;
|
||||
|
||||
scnprintf(virt_dev->usn, sizeof(virt_dev->usn), "%llx", dev_id_num);
|
||||
scnprintf(virt_dev->usn, sizeof(virt_dev->usn), "%llx",
|
||||
(unsigned long long)dev_id_num);
|
||||
TRACE_DBG("usn %s", virt_dev->usn);
|
||||
|
||||
list_for_each_entry(vv, &vdev_list, vdev_list_entry) {
|
||||
@@ -7652,7 +7653,7 @@ static int vdev_size_process_store(struct scst_sysfs_work_item *work)
|
||||
int size_shift, res = -EINVAL;
|
||||
bool queue_ua;
|
||||
|
||||
if (sscanf(work->buf, "%d %lld", &size_shift, &new_size) != 2 ||
|
||||
if (sscanf(work->buf, "%d %llu", &size_shift, &new_size) != 2 ||
|
||||
new_size > (ULLONG_MAX >> size_shift))
|
||||
goto put;
|
||||
|
||||
|
||||
+6
-5
@@ -844,7 +844,8 @@ static void scst_pr_toggle_lock(struct scst_pr_dlm_data *pr_dlm,
|
||||
for (i = 0; i < pr_dlm->participants; i++) {
|
||||
if (pr_dlm->nodeid[i] == pr_dlm->local_nodeid)
|
||||
continue;
|
||||
snprintf(lock_name, sizeof(lock_name), fmt, pr_dlm->nodeid[i]);
|
||||
/* Preserve the signed node-ID representation in existing lock names. */
|
||||
snprintf(lock_name, sizeof(lock_name), fmt, (int)pr_dlm->nodeid[i]);
|
||||
lksb.lksb.sb_lkid = 0;
|
||||
res = scst_dlm_lock_wait(ls, DLM_LOCK_PR, &lksb, 0,
|
||||
lock_name, NULL);
|
||||
@@ -1062,7 +1063,7 @@ static dlm_lockspace_t *get_lockspace(struct scst_device *dev)
|
||||
goto unlock_dlm_pr;
|
||||
|
||||
snprintf(lock_name, sizeof(lock_name), PR_POST_JOIN_LOCK,
|
||||
pr_dlm->local_nodeid);
|
||||
(int)pr_dlm->local_nodeid);
|
||||
pr_dlm->post_join_lksb.pr_dlm = pr_dlm;
|
||||
res = scst_dlm_lock_wait(ls, DLM_LOCK_NL,
|
||||
&pr_dlm->post_join_lksb, 0, lock_name,
|
||||
@@ -1071,7 +1072,7 @@ static dlm_lockspace_t *get_lockspace(struct scst_device *dev)
|
||||
goto release_lockspace;
|
||||
|
||||
snprintf(lock_name, sizeof(lock_name), PR_PRE_JOIN_LOCK,
|
||||
pr_dlm->local_nodeid);
|
||||
(int)pr_dlm->local_nodeid);
|
||||
pr_dlm->pre_join_lksb.pr_dlm = pr_dlm;
|
||||
res = scst_dlm_lock_wait(ls, DLM_LOCK_EX,
|
||||
&pr_dlm->pre_join_lksb, 0, lock_name,
|
||||
@@ -1091,7 +1092,7 @@ static dlm_lockspace_t *get_lockspace(struct scst_device *dev)
|
||||
}
|
||||
|
||||
snprintf(lock_name, sizeof(lock_name), PR_POST_UPDATE_LOCK,
|
||||
pr_dlm->local_nodeid);
|
||||
(int)pr_dlm->local_nodeid);
|
||||
pr_dlm->post_upd_lksb.pr_dlm = pr_dlm;
|
||||
res = scst_dlm_lock_wait(ls, DLM_LOCK_NL,
|
||||
&pr_dlm->post_upd_lksb, 0, lock_name,
|
||||
@@ -1100,7 +1101,7 @@ static dlm_lockspace_t *get_lockspace(struct scst_device *dev)
|
||||
goto release_lockspace;
|
||||
|
||||
snprintf(lock_name, sizeof(lock_name), PR_PRE_UPDATE_LOCK,
|
||||
pr_dlm->local_nodeid);
|
||||
(int)pr_dlm->local_nodeid);
|
||||
pr_dlm->pre_upd_lksb.pr_dlm = pr_dlm;
|
||||
res = scst_dlm_lock_wait(ls, DLM_LOCK_EX, &pr_dlm->pre_upd_lksb,
|
||||
0, lock_name, scst_dlm_pre_bast);
|
||||
|
||||
@@ -622,7 +622,7 @@ char *scst_get_cmd_state_name(char *name, int len, unsigned int state)
|
||||
scst_cmd_state_name[state])
|
||||
strscpy(name, scst_cmd_state_name[state], len);
|
||||
else
|
||||
snprintf(name, len, "%d", state);
|
||||
snprintf(name, len, "%u", state);
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -700,7 +700,7 @@ char *scst_get_tm_fn_name(char *name, int len, unsigned int fn)
|
||||
if (fn < ARRAY_SIZE(scst_tm_fn_name) && scst_tm_fn_name[fn])
|
||||
strscpy(name, scst_tm_fn_name[fn], len);
|
||||
else
|
||||
snprintf(name, len, "%d", fn);
|
||||
snprintf(name, len, "%u", fn);
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -720,7 +720,7 @@ char *scst_get_mcmd_state_name(char *name, int len, unsigned int state)
|
||||
scst_mcmd_state_name[state])
|
||||
strscpy(name, scst_mcmd_state_name[state], len);
|
||||
else
|
||||
snprintf(name, len, "%d", state);
|
||||
snprintf(name, len, "%u", state);
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@@ -5228,7 +5228,7 @@ int scst_acg_dev_sysfs_create(struct scst_acg_dev *acg_dev, struct kobject *pare
|
||||
kobject_get(&acg_dev->dev->dev_kobj);
|
||||
|
||||
snprintf(acg_dev->acg_dev_link_name, sizeof(acg_dev->acg_dev_link_name),
|
||||
"export%u", acg_dev->dev->dev_exported_lun_num++);
|
||||
"export%u", (unsigned int)acg_dev->dev->dev_exported_lun_num++);
|
||||
|
||||
res = sysfs_create_link(acg_dev->dev->dev_exp_kobj, &acg_dev->acg_dev_kobj,
|
||||
acg_dev->acg_dev_link_name);
|
||||
|
||||
+4
-4
@@ -97,7 +97,7 @@ static void handle_tm_received(struct scst_event_user *event_user)
|
||||
{
|
||||
struct scst_event_tm_fn_received_payload *p = (struct scst_event_tm_fn_received_payload *)event_user->out_event.payload;
|
||||
|
||||
printf("fn %d, device %s\n", p->fn, p->device_name);
|
||||
printf("fn %u, device %s\n", p->fn, p->device_name);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -264,9 +264,9 @@ again_poll:
|
||||
|
||||
}
|
||||
|
||||
PRINT_INFO("\nevent_code %d, issuer_name %s",
|
||||
event_user->out_event.event_code,
|
||||
event_user->out_event.issuer_name);
|
||||
PRINT_INFO("\nevent_code %u, issuer_name %s",
|
||||
event_user->out_event.event_code,
|
||||
event_user->out_event.issuer_name);
|
||||
if (event_user->out_event.payload_len != 0)
|
||||
PRINT_BUFFER("payoad", event_user->out_event.payload,
|
||||
event_user->out_event.payload_len);
|
||||
|
||||
+7
-7
@@ -237,10 +237,10 @@ static int do_exec(struct vdisk_cmd *vcmd)
|
||||
|
||||
switch(cmd->queue_type) {
|
||||
case SCST_CMD_QUEUE_ORDERED:
|
||||
TRACE(TRACE_ORDER, "ORDERED cmd_h %d", vcmd->cmd->cmd_h);
|
||||
TRACE(TRACE_ORDER, "ORDERED cmd_h %u", vcmd->cmd->cmd_h);
|
||||
break;
|
||||
case SCST_CMD_QUEUE_HEAD_OF_QUEUE:
|
||||
TRACE(TRACE_ORDER, "HQ cmd_h %d", vcmd->cmd->cmd_h);
|
||||
TRACE(TRACE_ORDER, "HQ cmd_h %u", vcmd->cmd->cmd_h);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -521,14 +521,14 @@ static int do_on_free_cmd(struct vdisk_cmd *vcmd)
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
TRACE_DBG("On free cmd (cmd %d, resp_data_len %d, aborted %d, "
|
||||
TRACE_DBG("On free cmd (cmd %u, resp_data_len %d, aborted %d, "
|
||||
"status %d, delivery_status %d)", cmd->cmd_h,
|
||||
cmd->on_free_cmd.resp_data_len, cmd->on_free_cmd.aborted,
|
||||
cmd->on_free_cmd.status, cmd->on_free_cmd.delivery_status);
|
||||
|
||||
TRACE_MEM("On free cmd (cmd %d, buf %"PRIx64", buffer_cached %d)",
|
||||
cmd->cmd_h, cmd->on_free_cmd.pbuf,
|
||||
cmd->on_free_cmd.buffer_cached);
|
||||
TRACE_MEM("On free cmd (cmd %u, buf %" PRIx64 ", buffer_cached %d)",
|
||||
cmd->cmd_h, cmd->on_free_cmd.pbuf,
|
||||
cmd->on_free_cmd.buffer_cached);
|
||||
|
||||
if (!cmd->on_free_cmd.buffer_cached && (cmd->on_free_cmd.pbuf != 0)) {
|
||||
TRACE_MEM("Freeing buf %"PRIx64, cmd->on_free_cmd.pbuf);
|
||||
@@ -555,7 +555,7 @@ static int do_ext_copy_remap(struct vdisk_cmd *vcmd)
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
TRACE_DBG("Ext copy remap cmd %d", cmd->cmd_h);
|
||||
TRACE_DBG("Ext copy remap cmd %u", cmd->cmd_h);
|
||||
|
||||
memset(reply, 0, sizeof(*reply));
|
||||
reply->cmd_h = cmd->cmd_h;
|
||||
|
||||
+1
-1
@@ -207,7 +207,7 @@ static void *align_alloc(size_t size)
|
||||
assert(page_size > 0);
|
||||
}
|
||||
|
||||
TRACE_MEM("Request to alloc %zdKB", size / 1024);
|
||||
TRACE_MEM("Request to alloc %zuKB", size / 1024);
|
||||
return memalign(page_size, size);
|
||||
}
|
||||
|
||||
|
||||
@@ -310,7 +310,7 @@ static int stpg_event_loop(void)
|
||||
sizeof(e1.issuer_name));
|
||||
e1.issuer_name[sizeof(e1.issuer_name)-1] = '\0';
|
||||
|
||||
PRINT_INFO("Setting allowed event code %d, issuer_name %s",
|
||||
PRINT_INFO("Setting allowed event code %u, issuer_name %s",
|
||||
e1.event_code, e1.issuer_name);
|
||||
|
||||
res = ioctl(event_fd, SCST_EVENT_ALLOW_EVENT, &e1);
|
||||
@@ -326,7 +326,7 @@ static int stpg_event_loop(void)
|
||||
sizeof(e1.issuer_name));
|
||||
e1.issuer_name[sizeof(e1.issuer_name) - 1] = '\0';
|
||||
|
||||
PRINT_INFO("Setting allowed event code %d, issuer_name %s",
|
||||
PRINT_INFO("Setting allowed event code %u, issuer_name %s",
|
||||
e1.event_code, e1.issuer_name);
|
||||
|
||||
res = ioctl(event_fd, SCST_EVENT_ALLOW_EVENT, &e1);
|
||||
@@ -390,7 +390,7 @@ again_poll:
|
||||
}
|
||||
first_error = true;
|
||||
#ifdef DEBUG
|
||||
PRINT_INFO("event_code %d, issuer_name %s",
|
||||
PRINT_INFO("event_code %u, issuer_name %s",
|
||||
event_user->out_event.event_code,
|
||||
event_user->out_event.issuer_name);
|
||||
#endif
|
||||
@@ -425,7 +425,7 @@ again_poll:
|
||||
} else if (event_user->out_event.event_code == SCST_EVENT_TM_FN_RECEIVED) {
|
||||
stpg_handle_tm_received(event_user);
|
||||
} else {
|
||||
PRINT_ERROR("Unknown event %d received", event_user->out_event.event_code);
|
||||
PRINT_ERROR("Unknown event %u received", event_user->out_event.event_code);
|
||||
}
|
||||
}
|
||||
out:
|
||||
|
||||
Reference in New Issue
Block a user