Skip to content

Commit 43abe48

Browse files
avri-altman-sndkmartinkpetersen
authored andcommitted
scsi: ufs: core: Zero utp_upiu_req at the beginning of each command
This patch introduces a previously missing step: zeroing the 'utp_upiu_req' structure at the beginning of each upiu transaction. This ensures that the upiu request fields are properly initialized, preventing potential issues caused by residual data from previous commands. While at it, re-use some of the common initializations for query and command upiu. Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Avri Altman <avri.altman@wdc.com> Link: https://lore.kernel.org/r/20240921062306.56019-1-avri.altman@wdc.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 71ef4e6 commit 43abe48

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

drivers/ufs/core/ufshcd.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,7 +2762,6 @@ void ufshcd_prepare_utp_scsi_cmd_upiu(struct ufshcd_lrb *lrbp, u8 upiu_flags)
27622762
ucd_req_ptr->sc.exp_data_transfer_len = cpu_to_be32(cmd->sdb.length);
27632763

27642764
cdb_len = min_t(unsigned short, cmd->cmd_len, UFS_CDB_SIZE);
2765-
memset(ucd_req_ptr->sc.cdb, 0, UFS_CDB_SIZE);
27662765
memcpy(ucd_req_ptr->sc.cdb, cmd->cmnd, cdb_len);
27672766

27682767
memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp));
@@ -2865,6 +2864,26 @@ static void ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
28652864
ufshcd_prepare_utp_scsi_cmd_upiu(lrbp, upiu_flags);
28662865
}
28672866

2867+
static void __ufshcd_setup_cmd(struct ufshcd_lrb *lrbp, struct scsi_cmnd *cmd, u8 lun, int tag)
2868+
{
2869+
memset(lrbp->ucd_req_ptr, 0, sizeof(*lrbp->ucd_req_ptr));
2870+
2871+
lrbp->cmd = cmd;
2872+
lrbp->task_tag = tag;
2873+
lrbp->lun = lun;
2874+
ufshcd_prepare_lrbp_crypto(cmd ? scsi_cmd_to_rq(cmd) : NULL, lrbp);
2875+
}
2876+
2877+
static void ufshcd_setup_scsi_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,
2878+
struct scsi_cmnd *cmd, u8 lun, int tag)
2879+
{
2880+
__ufshcd_setup_cmd(lrbp, cmd, lun, tag);
2881+
lrbp->intr_cmd = !ufshcd_is_intr_aggr_allowed(hba);
2882+
lrbp->req_abort_skip = false;
2883+
2884+
ufshcd_comp_scsi_upiu(hba, lrbp);
2885+
}
2886+
28682887
/**
28692888
* ufshcd_upiu_wlun_to_scsi_wlun - maps UPIU W-LUN id to SCSI W-LUN ID
28702889
* @upiu_wlun_id: UPIU W-LUN id
@@ -2998,16 +3017,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
29983017
ufshcd_hold(hba);
29993018

30003019
lrbp = &hba->lrb[tag];
3001-
lrbp->cmd = cmd;
3002-
lrbp->task_tag = tag;
3003-
lrbp->lun = ufshcd_scsi_to_upiu_lun(cmd->device->lun);
3004-
lrbp->intr_cmd = !ufshcd_is_intr_aggr_allowed(hba);
30053020

3006-
ufshcd_prepare_lrbp_crypto(scsi_cmd_to_rq(cmd), lrbp);
3007-
3008-
lrbp->req_abort_skip = false;
3009-
3010-
ufshcd_comp_scsi_upiu(hba, lrbp);
3021+
ufshcd_setup_scsi_cmd(hba, lrbp, cmd, ufshcd_scsi_to_upiu_lun(cmd->device->lun), tag);
30113022

30123023
err = ufshcd_map_sg(hba, lrbp);
30133024
if (err) {
@@ -3035,11 +3046,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
30353046
static void ufshcd_setup_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,
30363047
enum dev_cmd_type cmd_type, u8 lun, int tag)
30373048
{
3038-
lrbp->cmd = NULL;
3039-
lrbp->task_tag = tag;
3040-
lrbp->lun = lun;
3049+
__ufshcd_setup_cmd(lrbp, NULL, lun, tag);
30413050
lrbp->intr_cmd = true; /* No interrupt aggregation */
3042-
ufshcd_prepare_lrbp_crypto(NULL, lrbp);
30433051
hba->dev_cmd.type = cmd_type;
30443052
}
30453053

0 commit comments

Comments
 (0)