From 7bde0f6d63604048db65e5be648d31b5f82829d9 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Wed, 21 Oct 2026 15:03:23 +0300 Subject: [PATCH] scst: Propagate read-only inputs through shared helper interfaces Declare copied CDB/copy-manager inputs, lookup keys, SGV private-data access and scalar command inspection inputs read-only. Change declarations and implementations together, then propagate const through inquiry, page counting and vector-allocation helpers and their dependent callers. Carry the same read-only exclusion command through reset handling and both unit-attention wrappers. These functions inspect identities or copy input data; buffer acquisition, release, outputs and registered callbacks retain their mutable contracts. Installed-header version generation continues to account for the interface changes. Cppcheck reports constParameterPointer and constVariablePointer, including: Parameter 'cmd' can be declared as pointer to const Parameter 'exclude_cmd' can be declared as pointer to const Parameter 'exclude' can be declared as pointer to const --- scst/include/scst.h | 24 ++++++++++++------------ scst/include/scst_sgv.h | 2 +- scst/src/dev_handlers/scst_disk.c | 2 +- scst/src/dev_handlers/scst_vdisk_main.c | 6 +++--- scst/src/scst_copy_mgr.c | 2 +- scst/src/scst_lib.c | 14 +++++++------- scst/src/scst_local_cmd.c | 2 +- scst/src/scst_mem.c | 2 +- scst/src/scst_priv.h | 10 +++++----- scst/src/scst_tg.c | 8 ++++---- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/scst/include/scst.h b/scst/include/scst.h index e4f4f18e0..48e96a1a8 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -3828,11 +3828,11 @@ static inline void scst_sess_set_tgt_priv(struct scst_session *sess, void *val) sess->sess_tgt_priv = val; } -u16 scst_lookup_tg_id(struct scst_device *dev, struct scst_tgt *tgt); -enum scst_tg_state scst_get_alua_state(struct scst_device *dev, struct scst_tgt *tgt); -bool scst_alua_configured(struct scst_device *dev); +u16 scst_lookup_tg_id(const struct scst_device *dev, const struct scst_tgt *tgt); +enum scst_tg_state scst_get_alua_state(const struct scst_device *dev, const struct scst_tgt *tgt); +bool scst_alua_configured(const struct scst_device *dev); int scst_tg_get_group_info(void **buf, u32 *length, - struct scst_device *dev, u8 data_format); + const struct scst_device *dev, u8 data_format); int scst_tg_set_group_info(struct scst_cmd *cmd); const char *scst_alua_state_name(enum scst_tg_state s); void scst_stpg_del_unblock_next(struct scst_cmd *cmd); @@ -4031,7 +4031,7 @@ static inline unsigned int scst_cmd_get_cdb_len(const struct scst_cmd *cmd) } void scst_cmd_set_ext_cdb(struct scst_cmd *cmd, - u8 *ext_cdb, unsigned int ext_cdb_len, gfp_t gfp_mask); + const u8 *ext_cdb, unsigned int ext_cdb_len, gfp_t gfp_mask); /* Returns cmd's session */ static inline struct scst_session *scst_cmd_get_session(const struct scst_cmd *cmd) @@ -4488,13 +4488,13 @@ static inline bool scst_cmd_aborted_on_xmit(struct scst_cmd *cmd) } /* Returns sense data format for cmd's dev */ -static inline bool scst_get_cmd_dev_d_sense(struct scst_cmd *cmd) +static inline bool scst_get_cmd_dev_d_sense(const struct scst_cmd *cmd) { return cmd->dev ? cmd->dev->d_sense : 0; } /* Returns if command is INQUIRY EVPD=0x83 (device identification) */ -static inline bool scst_cmd_inquired_dev_ident(struct scst_cmd *cmd) +static inline bool scst_cmd_inquired_dev_ident(const struct scst_cmd *cmd) { return (cmd->cdb[0] == INQUIRY) && ((cmd->cdb[1] & 0x01/*EVPD*/) == 0x01) && (cmd->cdb[2] == 0x83/*device identification*/); @@ -5106,7 +5106,7 @@ static inline void scst_put_out_sg_page(struct scst_cmd *cmd, struct page *page, * Returns approximate higher rounded buffers count that * scst_get_buf_[first|next]() return. */ -static inline int scst_get_buf_count(struct scst_cmd *cmd) +static inline int scst_get_buf_count(const struct scst_cmd *cmd) { return (cmd->sg_cnt == 0) ? 1 : cmd->sg_cnt; } @@ -5114,7 +5114,7 @@ static inline int scst_get_buf_count(struct scst_cmd *cmd) /* * Returns approximate higher rounded buffers count in pages */ -static inline int scst_get_buf_page_count(struct scst_cmd *cmd) +static inline int scst_get_buf_page_count(const struct scst_cmd *cmd) { struct scatterlist *sg; int page_cnt = 0, i; @@ -5132,7 +5132,7 @@ static inline int scst_get_buf_page_count(struct scst_cmd *cmd) * Returns approximate higher rounded buffers count that * scst_get_out_buf_[first|next]() return. */ -static inline int scst_get_out_buf_count(struct scst_cmd *cmd) +static inline int scst_get_out_buf_count(const struct scst_cmd *cmd) { return (cmd->out_sg_cnt == 0) ? 1 : cmd->out_sg_cnt; } @@ -5589,7 +5589,7 @@ extern struct lockdep_map scst_dev_dep_map; #endif char *scst_get_next_lexem(char **token_str); -void scst_restore_token_str(char *prev_lexem, char *token_str); +void scst_restore_token_str(char *prev_lexem, const char *token_str); char *scst_get_next_token_str(char **input_str); void scst_init_threads(struct scst_cmd_threads *cmd_threads); @@ -5733,7 +5733,7 @@ struct scst_ext_copy_seg_descr { int tgt_descr_offs; }; -void scst_ext_copy_remap_done(struct scst_cmd *ec_cmd, struct scst_ext_copy_data_descr *dds, +void scst_ext_copy_remap_done(struct scst_cmd *ec_cmd, const struct scst_ext_copy_data_descr *dds, int dds_cnt); int scst_ext_copy_get_cur_seg_data_len(struct scst_cmd *ec_cmd); diff --git a/scst/include/scst_sgv.h b/scst/include/scst_sgv.h index 136eb5cae..ba2f4f9e1 100644 --- a/scst/include/scst_sgv.h +++ b/scst/include/scst_sgv.h @@ -100,7 +100,7 @@ struct scatterlist *sgv_pool_alloc(struct sgv_pool *pool, unsigned int size, struct sgv_pool_obj **sgv, struct scst_mem_lim *mem_lim, void *priv); void sgv_pool_free(struct sgv_pool_obj *obj, struct scst_mem_lim *mem_lim); -void *sgv_get_priv(struct sgv_pool_obj *obj); +void *sgv_get_priv(const struct sgv_pool_obj *obj); void scst_init_mem_lim(struct scst_mem_lim *mem_lim); diff --git a/scst/src/dev_handlers/scst_disk.c b/scst/src/dev_handlers/scst_disk.c index 1b91d01d3..3e4c26103 100644 --- a/scst/src/dev_handlers/scst_disk.c +++ b/scst/src/dev_handlers/scst_disk.c @@ -460,7 +460,7 @@ out_complete: /* Executes command and split CDB, if necessary */ static enum scst_exec_res disk_exec(struct scst_cmd *cmd) { - struct scst_tgt *tgt = cmd->tgt; + const struct scst_tgt *tgt = cmd->tgt; enum scst_exec_res res; int rc; struct disk_work work; diff --git a/scst/src/dev_handlers/scst_vdisk_main.c b/scst/src/dev_handlers/scst_vdisk_main.c index 01b447826..40ad5372a 100644 --- a/scst/src/dev_handlers/scst_vdisk_main.c +++ b/scst/src/dev_handlers/scst_vdisk_main.c @@ -2964,7 +2964,7 @@ static void scst_do_verify_work(struct work_struct *work) */ static bool do_fileio_async(const struct vdisk_cmd_params *p) { - struct scst_cmd *cmd = p->cmd; + const struct scst_cmd *cmd = p->cmd; const struct scst_device *dev = cmd->dev; const struct scst_vdisk_dev *virt_dev = dev->dh_priv; @@ -2979,7 +2979,7 @@ static bool do_fileio_async(const struct vdisk_cmd_params *p) } } -static bool vdisk_alloc_async_bvec(struct scst_cmd *cmd, +static bool vdisk_alloc_async_bvec(const struct scst_cmd *cmd, struct vdisk_cmd_params *p) { int n; @@ -5010,7 +5010,7 @@ static enum compl_status_e vdisk_exec_prevent_allow_medium_removal(struct vdisk_ return CMD_SUCCEEDED; } -static struct kvec *vdisk_alloc_sync_kvec(struct scst_cmd *cmd, +static struct kvec *vdisk_alloc_sync_kvec(const struct scst_cmd *cmd, struct vdisk_cmd_params *p) { int kvec_segs; diff --git a/scst/src/scst_copy_mgr.c b/scst/src/scst_copy_mgr.c index 9b2dd16a5..0c042d430 100644 --- a/scst/src/scst_copy_mgr.c +++ b/scst/src/scst_copy_mgr.c @@ -1411,7 +1411,7 @@ EXPORT_SYMBOL_GPL(scst_ext_copy_get_cur_seg_data_len); * If dds is NULL, then all data have been remapped, so SCST core will switch * to the next segment descriptor, if any. */ -void scst_ext_copy_remap_done(struct scst_cmd *ec_cmd, struct scst_ext_copy_data_descr *dds, +void scst_ext_copy_remap_done(struct scst_cmd *ec_cmd, const struct scst_ext_copy_data_descr *dds, int dds_cnt) { TRACE_ENTRY(); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 160b9546c..c7b072494 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -2487,7 +2487,7 @@ out: } EXPORT_SYMBOL(scst_check_convert_sense); -int scst_set_cmd_error_sense(struct scst_cmd *cmd, u8 *sense, +int scst_set_cmd_error_sense(struct scst_cmd *cmd, const u8 *sense, unsigned int len) { int res; @@ -7574,7 +7574,7 @@ EXPORT_SYMBOL(scst_cmd_put); * scst_cmd_set_ext_cdb() - sets cmd's extended CDB and its length */ void scst_cmd_set_ext_cdb(struct scst_cmd *cmd, - u8 *ext_cdb, unsigned int ext_cdb_len, + const u8 *ext_cdb, unsigned int ext_cdb_len, gfp_t gfp_mask) { unsigned int len = cmd->cdb_len + ext_cdb_len; @@ -13114,7 +13114,7 @@ EXPORT_SYMBOL(scst_to_tgt_dma_dir); * !! scst_unblock_aborted_cmds() must be called after this function !! */ void scst_process_reset(struct scst_device *dev, - struct scst_session *originator, struct scst_cmd *exclude_cmd, + const struct scst_session *originator, const struct scst_cmd *exclude_cmd, struct scst_mgmt_cmd *mcmd, bool setUA) { struct scst_tgt_dev *tgt_dev; @@ -13443,7 +13443,7 @@ void scst_check_set_UA(struct scst_tgt_dev *tgt_dev, /* Called under dev_lock and BH off */ void scst_dev_check_set_local_UA(struct scst_device *dev, - struct scst_cmd *exclude, const u8 *sense, int sense_len) + const struct scst_cmd *exclude, const u8 *sense, int sense_len) { struct scst_tgt_dev *tgt_dev; const struct scst_tgt_dev *exclude_tgt_dev = NULL; @@ -13467,7 +13467,7 @@ void scst_dev_check_set_local_UA(struct scst_device *dev, * should be called outside of the dev_lock. */ static bool __scst_dev_check_set_UA(struct scst_device *dev, - struct scst_cmd *exclude, const u8 *sense, int sense_len) + const struct scst_cmd *exclude, const u8 *sense, int sense_len) { bool res = false; @@ -13491,7 +13491,7 @@ static bool __scst_dev_check_set_UA(struct scst_device *dev, } void scst_dev_check_set_UA(struct scst_device *dev, - struct scst_cmd *exclude, const u8 *sense, int sense_len) + const struct scst_cmd *exclude, const u8 *sense, int sense_len) { struct scst_lksb lksb; bool rc; @@ -14502,7 +14502,7 @@ EXPORT_SYMBOL_GPL(scst_get_next_lexem); * previous value before scst_get_next_lexem() was called. Prev_lexem is * a pointer to lexem returned by scst_get_next_lexem(). */ -void scst_restore_token_str(char *prev_lexem, char *token_str) +void scst_restore_token_str(char *prev_lexem, const char *token_str) { if (&prev_lexem[strlen(prev_lexem)] != token_str) prev_lexem[strlen(prev_lexem)] = ' '; diff --git a/scst/src/scst_local_cmd.c b/scst/src/scst_local_cmd.c index f54c175d0..da841a738 100644 --- a/scst/src/scst_local_cmd.c +++ b/scst/src/scst_local_cmd.c @@ -249,7 +249,7 @@ out_unlock_put_not_completed: /* SPC-4 REPORT TARGET PORT GROUPS command */ static enum scst_exec_res scst_report_tpgs(struct scst_cmd *cmd) { - struct scst_device *dev; + const struct scst_device *dev; u8 *address; void *buf; s32 buf_len; diff --git a/scst/src/scst_mem.c b/scst/src/scst_mem.c index e43506162..93ae36a97 100644 --- a/scst/src/scst_mem.c +++ b/scst/src/scst_mem.c @@ -1114,7 +1114,7 @@ EXPORT_SYMBOL_GPL(sgv_pool_alloc); * Allows to get the allocation private data for this SGV * cache object. The private data supposed to be set by sgv_pool_alloc(). */ -void *sgv_get_priv(struct sgv_pool_obj *obj) +void *sgv_get_priv(const struct sgv_pool_obj *obj) { return obj->allocator_priv; } diff --git a/scst/src/scst_priv.h b/scst/src/scst_priv.h index 5fcd9628c..800995924 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -386,7 +386,7 @@ struct scst_acn *scst_find_acn(struct scst_acg *acg, const char *name); int scst_prepare_request_sense(struct scst_cmd *orig_cmd); int scst_finish_internal_cmd(struct scst_cmd *cmd); -int scst_set_cmd_error_sense(struct scst_cmd *cmd, u8 *sense, unsigned int len); +int scst_set_cmd_error_sense(struct scst_cmd *cmd, const u8 *sense, unsigned int len); int scst_process_check_condition(struct scst_cmd *cmd); @@ -546,9 +546,9 @@ static inline void scst_clear_dev_reservation(struct scst_device *dev) void scst_tgt_dev_del_free_UA(struct scst_tgt_dev *tgt_dev, struct scst_tgt_dev_UA *ua); -void scst_dev_check_set_UA(struct scst_device *dev, struct scst_cmd *exclude, +void scst_dev_check_set_UA(struct scst_device *dev, const struct scst_cmd *exclude, const u8 *sense, int sense_len); -void scst_dev_check_set_local_UA(struct scst_device *dev, struct scst_cmd *exclude, +void scst_dev_check_set_local_UA(struct scst_device *dev, const struct scst_cmd *exclude, const u8 *sense, int sense_len); #define SCST_SET_UA_FLAG_AT_HEAD 1 @@ -562,8 +562,8 @@ void scst_report_luns_changed(struct scst_acg *acg); void scst_abort_cmd(struct scst_cmd *cmd, struct scst_mgmt_cmd *mcmd, bool other_ini, bool call_dev_task_mgmt_fn_received); -void scst_process_reset(struct scst_device *dev, struct scst_session *originator, - struct scst_cmd *exclude_cmd, struct scst_mgmt_cmd *mcmd, bool setUA); +void scst_process_reset(struct scst_device *dev, const struct scst_session *originator, + const struct scst_cmd *exclude_cmd, struct scst_mgmt_cmd *mcmd, bool setUA); void __scst_unblock_aborted_cmds(const struct scst_tgt *tgt, const struct scst_session *sess, const struct scst_device *device); void scst_unblock_aborted_cmds(const struct scst_tgt *tgt, const struct scst_session *sess, diff --git a/scst/src/scst_tg.c b/scst/src/scst_tg.c index f20185773..1fa7b8a4e 100644 --- a/scst/src/scst_tg.c +++ b/scst/src/scst_tg.c @@ -1452,7 +1452,7 @@ void scst_tg_cleanup(void) * * Returns a non-zero number if the lookup was successful and zero if not. */ -u16 scst_lookup_tg_id(struct scst_device *dev, struct scst_tgt *tgt) +u16 scst_lookup_tg_id(const struct scst_device *dev, const struct scst_tgt *tgt) { struct scst_dev_group *dg; const struct scst_target_group *tg; @@ -1485,7 +1485,7 @@ EXPORT_SYMBOL_GPL(scst_lookup_tg_id); * * Returns a valid ALUA state (SCST_TG_STATE_OPTIMIZED is no ALUA configured) */ -enum scst_tg_state scst_get_alua_state(struct scst_device *dev, struct scst_tgt *tgt) +enum scst_tg_state scst_get_alua_state(const struct scst_device *dev, const struct scst_tgt *tgt) { struct scst_dev_group *dg; const struct scst_target_group *tg; @@ -1515,7 +1515,7 @@ EXPORT_SYMBOL_GPL(scst_get_alua_state); * scst_alua_configured() - Whether implicit ALUA has been configured. * @dev: Pointer to the SCST device to verify. */ -bool scst_alua_configured(struct scst_device *dev) +bool scst_alua_configured(const struct scst_device *dev) { struct scst_dev_group *dg; @@ -1535,7 +1535,7 @@ EXPORT_SYMBOL_GPL(scst_alua_configured); * @data_format: Three-bit response data format specification. */ int scst_tg_get_group_info(void **buf, u32 *length, - struct scst_device *dev, u8 data_format) + const struct scst_device *dev, u8 data_format) { struct scst_dev_group *dg; struct scst_target_group *tg;