From bd203697988bfeea96378f1daffa5f713f605af2 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Wed, 21 Oct 2026 13:25:05 +0300 Subject: [PATCH] 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. --- iscsi-scst/usr/event.c | 2 +- scst/src/dev_handlers/scst_vdisk_main.c | 7 ++++--- scst/src/scst_dlm.c | 11 ++++++----- scst/src/scst_main.c | 6 +++--- scst/src/scst_sysfs.c | 2 +- usr/events/events.c | 8 ++++---- usr/fileio/common.c | 14 +++++++------- usr/fileio/fileio.c | 2 +- usr/stpgd/stpgd_main.c | 8 ++++---- 9 files changed, 31 insertions(+), 29 deletions(-) diff --git a/iscsi-scst/usr/event.c b/iscsi-scst/usr/event.c index 769505987..bf3292c18 100644 --- a/iscsi-scst/usr/event.c +++ b/iscsi-scst/usr/event.c @@ -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) { diff --git a/scst/src/dev_handlers/scst_vdisk_main.c b/scst/src/dev_handlers/scst_vdisk_main.c index 38ec3d09b..ab27f464c 100644 --- a/scst/src/dev_handlers/scst_vdisk_main.c +++ b/scst/src/dev_handlers/scst_vdisk_main.c @@ -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; diff --git a/scst/src/scst_dlm.c b/scst/src/scst_dlm.c index 127eed628..805397c31 100644 --- a/scst/src/scst_dlm.c +++ b/scst/src/scst_dlm.c @@ -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); diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index fb6d866a1..8bdcc662f 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -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; } diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 7070b4c14..e13034e56 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -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); diff --git a/usr/events/events.c b/usr/events/events.c index 4e1f73425..5ce15a17d 100644 --- a/usr/events/events.c +++ b/usr/events/events.c @@ -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); diff --git a/usr/fileio/common.c b/usr/fileio/common.c index e68a3d044..ac8984b19 100644 --- a/usr/fileio/common.c +++ b/usr/fileio/common.c @@ -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; diff --git a/usr/fileio/fileio.c b/usr/fileio/fileio.c index 64f9247c5..053d23104 100644 --- a/usr/fileio/fileio.c +++ b/usr/fileio/fileio.c @@ -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); } diff --git a/usr/stpgd/stpgd_main.c b/usr/stpgd/stpgd_main.c index 1f260245a..b8f09ecb7 100644 --- a/usr/stpgd/stpgd_main.c +++ b/usr/stpgd/stpgd_main.c @@ -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: