Re: [PATCH v3] scsi: core: clear driver private data when retry request

Bart Van Assche
2025-02-19T20:32:03Z

On 2/16/25 6:16 PM, Ye Bin wrote:
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index be0890e4e706..f1cfe0bb89b2 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -1669,13 +1669,6 @@ static blk_status_t scsi_prepare_cmd(struct request *req)
> if (in_flight)
> __set_bit(SCMD_STATE_INFLIGHT, &cmd->state);
>
> - /*
> - * Only clear the driver-private command data if the LLD does not supply
> - * a function to initialize that data.
> - */
> - if (!shost->hostt->init_cmd_priv)
> - memset(cmd + 1, 0, shost->hostt->cmd_size);
> -
> cmd->prot_op = SCSI_PROT_NORMAL;
> if (blk_rq_bytes(req))
> cmd->sc_data_direction = rq_dma_dir(req);
> @@ -1842,6 +1835,13 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
> if (!scsi_host_queue_ready(q, shost, sdev, cmd))
> goto out_dec_target_busy;
>
> + /*
> + * Only clear the driver-private command data if the LLD does not supply
> + * a function to initialize that data.
> + */
> + if (shost->hostt->cmd_size && !shost->hostt->init_cmd_priv)
> + memset(cmd + 1, 0, shost->hostt->cmd_size);
> +
> if (!(req->rq_flags & RQF_DONTPREP)) {
> ret = scsi_prepare_cmd(req);
> if (ret != BLK_STS_OK)

Reviewed-by: Bart Van Assche <bvanassche@acm.org>