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
This commit is contained in:
Gleb Chesnokov
2026-10-21 22:12:26 +03:00
parent 179d5185d6
commit 7bde0f6d63
10 changed files with 36 additions and 36 deletions
+12 -12
View File
@@ -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);
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -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();
+7 -7
View File
@@ -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)] = ' ';
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
}
+5 -5
View File
@@ -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,
+4 -4
View File
@@ -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;