scst: Remove redundant values and simplify known conditions

Remove overwritten initial values, unused offsets and zero-bit flag
operands. Derive the saved sense length from its captured value and rely
on C zero initialization for static-duration userspace objects. The FC
copy path remains unconditional because its buffers outlive the request.

Select CRC availability with the same four CONFIG predicates and use
else for a negative SRP residual only inside the nonzero-residual branch.
Group ternary bit tests and trim the PR filename's newline with strchr(),
retaining the empty-filename fallback. Manual review also identified the
overwritten QLogic tag initializer; every allocator branch assigns it.

Cppcheck reports:
  redundantAssignment: Variable 'tp' is reassigned a value before the
    old one has been used.
  unreadVariable: Variable 'sg_cnt' is assigned a value that is never used.
  unreadVariable: Variable 'data_offset' is assigned a value that is
    never used.
  clarifyCalculation: Clarify calculation precedence for '&' and '?'.
  ignoredReturnValue: Return value of function strsep() is not used.
  knownConditionTrueFalse: Condition '!crc32c' is always false.
  knownConditionTrueFalse: Condition 'resid<0' is always true.
  badBitmaskCheck: Operator '|' with one operand equal to zero is redundant.
It also marks the initial rc value in dev_user_process_cleanup() unread.

Checkpatch reports GLOBAL_INITIALISERS:
  do not initialise globals to false
This commit is contained in:
Gleb Chesnokov
2026-10-21 22:12:26 +03:00
parent 9aa30fbbcc
commit 65aa3f7446
19 changed files with 43 additions and 54 deletions
-2
View File
@@ -107,8 +107,6 @@ int ft_send_read_data(struct scst_cmd *cmd)
#endif
}
/* no scatter/gather in skb for odd word length due to fc_seq_send() */
use_sg = !(remaining % 4) && lport->sg_supp;
/*
* Note: since libfc_function_template.seq_send() sends frames
* asynchronously and since the SCST data buffer is freed as soon as
+4 -8
View File
@@ -26,17 +26,13 @@
void digest_alg_available(int *val)
{
#if defined(CONFIG_LIBCRC32C_MODULE) || defined(CONFIG_LIBCRC32C) || \
defined(CONFIG_CRC32_MODULE) || defined(CONFIG_CRC32)
int crc32c = 1;
#else
int crc32c = 0;
#endif
if ((*val & DIGEST_CRC32C) && !crc32c) {
#if !defined(CONFIG_LIBCRC32C_MODULE) && !defined(CONFIG_LIBCRC32C) && \
!defined(CONFIG_CRC32_MODULE) && !defined(CONFIG_CRC32)
if (*val & DIGEST_CRC32C) {
PRINT_ERROR("CRC32C digest algorithm not available in kernel");
*val &= ~DIGEST_CRC32C;
}
#endif
}
/**
-1
View File
@@ -268,7 +268,6 @@ int isert_prepare_rdma(struct isert_cmnd *isert_pdu,
}
buff_offset = 0;
sg_cnt = 0;
for (wr_cnt = 0, sg_offset = 0; sg_offset < isert_buf->sg_cnt;
++wr_cnt) {
sg_cnt = min((int)isert_conn->max_sge,
-2
View File
@@ -286,7 +286,6 @@ static void isert_rx_pdu_parse_headers(struct isert_cmnd *isert_pdu)
u8 *addr = isert_buf->addr;
struct isert_hdr *isert_hdr = (struct isert_hdr *)addr;
struct iscsi_hdr *bhs = (struct iscsi_hdr *)(addr + sizeof(*isert_hdr));
unsigned int data_offset = ISER_HDRS_SZ;
unsigned int ahssize;
TRACE_ENTRY();
@@ -317,7 +316,6 @@ static void isert_rx_pdu_parse_headers(struct isert_cmnd *isert_pdu)
isert_pdu->ahs = NULL;
} else {
isert_pdu->ahs = addr + ISER_HDRS_SZ;
data_offset += ahssize;
}
iscsi_cmnd->pdu.ahs = isert_pdu->ahs;
+1 -1
View File
@@ -24,7 +24,7 @@
#include "iscsid.h"
int log_daemon = 1;
int log_level = 0;
int log_level;
void log_init(void)
{
@@ -486,7 +486,7 @@ static struct qla_tgt_cmd *sqa_qla2xxx_get_cmd(struct fc_port *sess)
struct sqa_scst_tgt *sqa_tgt =
(struct sqa_scst_tgt *)sess->vha->vha_tgt.target_lport_ptr;
struct qla_tgt_cmd *cmd;
int tag = -ENOENT;
int tag;
#if QLT_USE_PERCPU_IDA
tag = percpu_ida_alloc(&sqa_tgt->tgt_tag_pool, TASK_RUNNING);
+1 -1
View File
@@ -3834,7 +3834,7 @@ SCST_KUNIT_VISIBLE
int dev_user_process_cleanup(struct scst_user_dev *dev)
{
struct scst_user_cmd *ucmd;
int rc = 0, res = 1;
int rc, res = 1;
TRACE_ENTRY();
+11 -11
View File
@@ -1869,7 +1869,7 @@ static enum compl_status_e vdisk_exec_format_unit(struct vdisk_cmd_params *p)
break;
default:
scst_set_invalid_field_in_parm_list(cmd, 0,
SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out;
}
break;
@@ -1877,7 +1877,7 @@ static enum compl_status_e vdisk_exec_format_unit(struct vdisk_cmd_params *p)
switch (prot_usage) {
default:
scst_set_invalid_field_in_parm_list(cmd, 0,
SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out;
}
break;
@@ -1888,7 +1888,7 @@ static enum compl_status_e vdisk_exec_format_unit(struct vdisk_cmd_params *p)
break;
default:
scst_set_invalid_field_in_parm_list(cmd, 0,
SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out;
}
break;
@@ -1902,7 +1902,7 @@ static enum compl_status_e vdisk_exec_format_unit(struct vdisk_cmd_params *p)
break;
default:
scst_set_invalid_field_in_parm_list(cmd, 0,
SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out;
}
break;
@@ -3495,7 +3495,7 @@ static enum compl_status_e vdisk_exec_unmap(struct vdisk_cmd_params *p)
if (unlikely(cmd->cdb[1] & 1)) {
TRACE_DBG("ANCHOR not supported");
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out;
}
@@ -4402,7 +4402,7 @@ out:
out_not_sup:
TRACE(TRACE_MINOR, "MODE SENSE: Unsupported page %x", pcode);
scst_set_invalid_field_in_cdb(cmd, 2, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 2, SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out_put;
}
@@ -4598,7 +4598,7 @@ static void vdisk_caching_m_pg_select(unsigned char *p, struct scst_vdisk_dev *v
if (save && (!vdev_saved_mode_pages_enabled || virt_dev->nv_cache)) {
TRACE(TRACE_MINOR | TRACE_SCSI, "MODE SELECT: saved cache page not supported");
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out;
}
@@ -4710,7 +4710,7 @@ static enum compl_status_e vdisk_exec_mode_select(struct vdisk_cmd_params *p)
TRACE(TRACE_MINOR, "MODE SELECT: Invalid request %x",
address[offset] & 0x3f);
scst_set_invalid_field_in_parm_list(cmd, offset,
SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out_put;
}
offset += address[offset + 1];
@@ -4731,7 +4731,7 @@ static enum compl_status_e vdisk_exec_log(struct vdisk_cmd_params *p)
TRACE_ENTRY();
/* No log pages are supported */
scst_set_invalid_field_in_cdb(cmd, 2, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 2, SCST_INVAL_FIELD_BIT_OFFS_VALID);
TRACE_EXIT();
return CMD_SUCCEEDED;
@@ -4882,7 +4882,7 @@ out:
static enum compl_status_e vdisk_exec_get_lba_status(struct vdisk_cmd_params *p)
{
/* Changing it don't forget to add it to vdisk_opcode_descriptors! */
scst_set_invalid_field_in_cdb(p->cmd, 1, 0 | SCST_INVAL_FIELD_BIT_OFFS_VALID);
scst_set_invalid_field_in_cdb(p->cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID);
return CMD_SUCCEEDED;
}
@@ -4896,7 +4896,7 @@ enum compl_status_e vdisk_exec_sai_16(struct vdisk_cmd_params *p)
case SAI_GET_LBA_STATUS:
return vdisk_exec_get_lba_status(p);
}
scst_set_invalid_field_in_cdb(p->cmd, 1, 0 | SCST_INVAL_FIELD_BIT_OFFS_VALID);
scst_set_invalid_field_in_cdb(p->cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID);
return CMD_SUCCEEDED;
}
+3 -4
View File
@@ -582,7 +582,7 @@ static void scst_cm_prepare_final_sense(struct scst_cmd *ec_cmd)
int d_sense = scst_get_cmd_dev_d_sense(ec_cmd);
bool copy_sense = false;
int sense_to_copy = ec_cmd->sense_valid_len;
int sense_len = ec_cmd->sense_valid_len;
int sense_len = sense_to_copy;
TRACE_ENTRY();
@@ -2228,7 +2228,7 @@ enum scst_exec_res scst_cm_rcv_copy_res_exec(struct scst_cmd *cmd)
default:
TRACE(TRACE_MINOR, "%s: action %d not supported",
cmd->op_name, action);
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID);
break;
}
@@ -2970,7 +2970,7 @@ static int scst_cm_parse_id_tgt_descr(struct scst_cmd *cmd, const uint8_t *seg,
PRINT_WARNING("PERIPHERAL DEVICE TYPE %d not supported",
seg[1] & 0xF);
scst_set_invalid_field_in_parm_list(cmd, offs + 1,
SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out_err;
}
@@ -3203,7 +3203,6 @@ skip_fcmd_create:
sBUG();
break;
}
tp = t;
}
tp = t;
}
+1 -2
View File
@@ -1113,8 +1113,7 @@ int scst_event_init(void)
TRACE_ENTRY();
scst_event_wq = alloc_workqueue("scst_event_wq", 0
| WQ_UNBOUND,
scst_event_wq = alloc_workqueue("scst_event_wq", WQ_UNBOUND,
0);
if (unlikely(!scst_event_wq)) {
PRINT_ERROR("Failed to allocate scst_event_wq");
+3 -4
View File
@@ -7428,7 +7428,7 @@ struct scst_session *scst_alloc_session(struct scst_tgt *tgt, gfp_t gfp_mask,
* To do: remove higher order allocation from the code below
* for the GFP_ATOMIC case.
*/
sess->lat_stats = gfp_mask & GFP_ATOMIC ?
sess->lat_stats = (gfp_mask & GFP_ATOMIC) ?
kzalloc_obj(*sess->lat_stats, gfp_mask) :
vzalloc(sizeof(*sess->lat_stats));
if (!sess->lat_stats)
@@ -12118,7 +12118,7 @@ static int get_cdb_info_ext_copy(struct scst_cmd *cmd,
PRINT_WARNING("Not supported %s service action 0x%x",
scst_get_opcode_name(cmd), cmd->cdb[1]);
scst_set_invalid_field_in_cdb(cmd, 1,
0 | SCST_INVAL_FIELD_BIT_OFFS_VALID);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
return 1;
}
@@ -15692,8 +15692,7 @@ int __init scst_lib_init(void)
scst_scsi_op_list_init();
scst_release_acg_wq = alloc_workqueue("scst_release_acg", 0
| WQ_UNBOUND,
scst_release_acg_wq = alloc_workqueue("scst_release_acg", WQ_UNBOUND,
0);
if (unlikely(!scst_release_acg_wq)) {
PRINT_ERROR("Failed to allocate scst_release_acg_wq");
+6 -6
View File
@@ -303,7 +303,7 @@ static enum scst_exec_res scst_exec_set_tpgs(struct scst_cmd *cmd)
PRINT_ERROR("SET TARGET PORT GROUPS: not explicit ALUA mode (dev %s)",
dev->virt_name);
/* Invalid opcode, i.e. SA field */
scst_set_invalid_field_in_cdb(cmd, 1, 0 | SCST_INVAL_FIELD_BIT_OFFS_VALID);
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out;
}
@@ -415,7 +415,7 @@ static enum scst_exec_res scst_report_supported_opcodes(struct scst_cmd *cmd)
req_opcode, cmd->dev->virt_name,
cmd->sess->initiator_name);
scst_set_invalid_field_in_cdb(cmd, 2,
SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out_compl;
}
buf_len = 4 + op->od_cdb_size;
@@ -442,7 +442,7 @@ static enum scst_exec_res scst_report_supported_opcodes(struct scst_cmd *cmd)
req_opcode, cmd->dev->virt_name,
cmd->sess->initiator_name);
scst_set_invalid_field_in_cdb(cmd, 2,
SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out_compl;
}
if (req_sa != op->od_serv_action) {
@@ -465,7 +465,7 @@ static enum scst_exec_res scst_report_supported_opcodes(struct scst_cmd *cmd)
default:
PRINT_ERROR("REPORT SUPPORTED OPERATION CODES: REPORTING OPTIONS %x not supported (dev %s, initiator %s)",
options, cmd->dev->virt_name, cmd->sess->initiator_name);
scst_set_invalid_field_in_cdb(cmd, 2, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 2, SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out_compl;
}
@@ -842,7 +842,7 @@ out_done:
return SCST_EXEC_COMPLETED;
out_unsup_act:
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out_complete;
}
@@ -970,7 +970,7 @@ enum scst_exec_res scst_persistent_reserve_out_local(struct scst_cmd *cmd)
scst_pr_register_and_move(cmd, buffer, buffer_size);
break;
default:
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out_unlock;
}
+2 -2
View File
@@ -1882,7 +1882,7 @@ void scst_pr_reserve(struct scst_cmd *cmd, uint8_t *buffer, int buffer_size)
if (!scst_pr_type_valid(type)) {
TRACE_PR("Invalid reservation type %d", type);
scst_set_invalid_field_in_cdb(cmd, 2, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 2, SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out;
}
@@ -2080,7 +2080,7 @@ static void scst_pr_do_preempt(struct scst_cmd *cmd, uint8_t *buffer, int buffer
if (!scst_pr_type_valid(type)) {
TRACE_PR("Invalid reservation type %d", type);
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
scst_set_invalid_field_in_cdb(cmd, 1, SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out;
}
+3 -2
View File
@@ -3222,8 +3222,9 @@ static ssize_t scst_dev_sysfs_pr_file_name_store(struct kobject *kobj, struct ko
PRINT_ERROR("Unable to kasprintf() PR file name");
goto out;
}
p = pr_file_name;
strsep(&p, "\n"); /* strip trailing whitespace */
p = strchr(pr_file_name, '\n');
if (p)
*p = '\0';
if (pr_file_name[0] == '\0') {
kfree(pr_file_name);
pr_file_name = kasprintf(GFP_KERNEL, "%s/%s", SCST_PR_DIR,
+1 -1
View File
@@ -1152,7 +1152,7 @@ int scst_parse_cmd(struct scst_cmd *cmd)
PRINT_ERROR("Linked commands are not supported (opcode %s)",
scst_get_opcode_name(cmd));
scst_set_invalid_field_in_cdb(cmd, cmd->cdb_len - 1,
SCST_INVAL_FIELD_BIT_OFFS_VALID | 0);
SCST_INVAL_FIELD_BIT_OFFS_VALID);
goto out_done;
}
+1 -1
View File
@@ -170,7 +170,7 @@ static int scst_local_get_sas_transport_id(struct scst_local_sess *sess, uint8_t
goto out;
}
tr_id[0] = 0x00 | SCSI_TRANSPORTID_PROTOCOLID_SAS;
tr_id[0] = SCSI_TRANSPORTID_PROTOCOLID_SAS;
/*
* Assemble a valid SAS address = 0x5OOUUIIR12345678 ... Does SCST
+3 -3
View File
@@ -1649,14 +1649,14 @@ static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch,
if (scst_cmd_get_data_direction(cmd) & SCST_DATA_READ) {
if (resid > 0)
srp_rsp->flags |= SRP_RSP_FLAG_DIUNDER;
else if (resid < 0)
else
srp_rsp->flags |= SRP_RSP_FLAG_DIOVER;
srp_rsp->data_in_res_cnt = cpu_to_be32(abs(resid));
}
if (scst_cmd_get_data_direction(cmd) & SCST_DATA_WRITE) {
if (resid > 0)
srp_rsp->flags |= SRP_RSP_FLAG_DOUNDER;
else if (resid < 0)
else
srp_rsp->flags |= SRP_RSP_FLAG_DOOVER;
srp_rsp->data_out_res_cnt = cpu_to_be32(abs(resid));
}
@@ -2651,7 +2651,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
list_add_tail(&ch->ioctx_ring[i]->free_list, &ch->free_list);
}
if (!sdev->use_srq) {
u16 imm_data_offset = req->req_flags & SRP_IMMED_REQUESTED ?
u16 imm_data_offset = (req->req_flags & SRP_IMMED_REQUESTED) ?
be16_to_cpu(req->imm_data_offset) : 0;
u16 alignment_offset;
u32 req_sz;
+1 -1
View File
@@ -52,7 +52,7 @@ char *app_name;
# endif
#endif /* DEBUG */
bool log_daemon = false; /* needed for the tracing infrastructure */
bool log_daemon; /* needed for the tracing infrastructure */
unsigned long trace_flag = DEFAULT_LOG_FLAGS;
#endif /* defined(DEBUG) || defined(TRACING) */
+1 -1
View File
@@ -69,7 +69,7 @@ char *app_name;
unsigned long trace_flag = DEFAULT_LOG_FLAGS;
#endif /* defined(DEBUG) || defined(TRACING) */
bool log_daemon = false;
bool log_daemon;
#define DEF_BLOCK_SHIFT 9
#define THREADS 7