Skip to content

Commit 549e91a

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: ufs: core: Fix handling of lrbp->cmd
ufshcd_queuecommand() may be called two times in a row for a SCSI command before it is completed. Hence make the following changes: - In the functions that submit a command, do not check the old value of lrbp->cmd nor clear lrbp->cmd in error paths. - In ufshcd_release_scsi_cmd(), do not clear lrbp->cmd. See also scsi_send_eh_cmnd(). This commit prevents that the following appears if a command times out: WARNING: at drivers/ufs/core/ufshcd.c:2965 ufshcd_queuecommand+0x6f8/0x9a8 Call trace: ufshcd_queuecommand+0x6f8/0x9a8 scsi_send_eh_cmnd+0x2c0/0x960 scsi_eh_test_devices+0x100/0x314 scsi_eh_ready_devs+0xd90/0x114c scsi_error_handler+0x2b4/0xb70 kthread+0x16c/0x1e0 Fixes: 5a0b0cb ("[SCSI] ufs: Add support for sending NOP OUT UPIU") Signed-off-by: Bart Van Assche <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Adrian Hunter <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent fe8637f commit 549e91a

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,7 +2945,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
29452945
(hba->clk_gating.state != CLKS_ON));
29462946

29472947
lrbp = &hba->lrb[tag];
2948-
WARN_ON(lrbp->cmd);
29492948
lrbp->cmd = cmd;
29502949
lrbp->task_tag = tag;
29512950
lrbp->lun = ufshcd_scsi_to_upiu_lun(cmd->device->lun);
@@ -2961,7 +2960,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
29612960

29622961
err = ufshcd_map_sg(hba, lrbp);
29632962
if (err) {
2964-
lrbp->cmd = NULL;
29652963
ufshcd_release(hba);
29662964
goto out;
29672965
}
@@ -3180,7 +3178,7 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
31803178
down_read(&hba->clk_scaling_lock);
31813179

31823180
lrbp = &hba->lrb[tag];
3183-
WARN_ON(lrbp->cmd);
3181+
lrbp->cmd = NULL;
31843182
err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag);
31853183
if (unlikely(err))
31863184
goto out;
@@ -5422,7 +5420,6 @@ static void ufshcd_release_scsi_cmd(struct ufs_hba *hba,
54225420
struct scsi_cmnd *cmd = lrbp->cmd;
54235421

54245422
scsi_dma_unmap(cmd);
5425-
lrbp->cmd = NULL; /* Mark the command as completed. */
54265423
ufshcd_release(hba);
54275424
ufshcd_clk_scaling_update_busy(hba);
54285425
}
@@ -7037,7 +7034,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba,
70377034
down_read(&hba->clk_scaling_lock);
70387035

70397036
lrbp = &hba->lrb[tag];
7040-
WARN_ON(lrbp->cmd);
70417037
lrbp->cmd = NULL;
70427038
lrbp->task_tag = tag;
70437039
lrbp->lun = 0;
@@ -7209,7 +7205,6 @@ int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *r
72097205
down_read(&hba->clk_scaling_lock);
72107206

72117207
lrbp = &hba->lrb[tag];
7212-
WARN_ON(lrbp->cmd);
72137208
lrbp->cmd = NULL;
72147209
lrbp->task_tag = tag;
72157210
lrbp->lun = UFS_UPIU_RPMB_WLUN;

0 commit comments

Comments
 (0)