Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yang Xiuwei" <yangxiuwei@kylinos.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v1 4/4] scsi: sd: fix sd_done() sense handling condition
Date: Tue, 23 Jun 2026 10:18:59 +0000	[thread overview]
Message-ID: <20260623101900.5E81F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260623100159.4018066-5-yangxiuwei@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch introduces a logic regression by unconditionally bypassing valid sense data processing for any SCSI status other than SAM_STAT_CHECK_CONDITION.
--

commit 6e9e6fa97257d1c3c528406c9719d2273c7f5a65
Author: Yang Xiuwei <yangxiuwei@kylinos.cn>

scsi: sd: fix sd_done() sense handling condition

This commit modifies the conditional in sd_done() to avoid entering the
sense_key switch with an uninitialized or stale sshdr when a CHECK CONDITION
occurs with invalid or deferred sense data. It replaces the previous logic
with an OR condition.

> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -2419,8 +2419,8 @@ static int sd_done(struct scsi_cmnd *SCpnt)
>  	}
>  	sdkp->medium_access_timed_out = 0;
>  
> -	if (!scsi_status_is_check_condition(result) &&
> -	    (!sense_valid || sense_deferred))
> +	if (!scsi_status_is_check_condition(result) ||
> +	    !sense_valid || sense_deferred)

[Severity: High]
Does this logic change inadvertently bypass valid sense data processing for
any SCSI status other than SAM_STAT_CHECK_CONDITION?

For example, if a low-level driver completes an I/O with
SAM_STAT_COMMAND_TERMINATED alongside valid sense data like RECOVERED_ERROR,
!scsi_status_is_check_condition(result) will evaluate to true.

This would cause the code to immediately jump to the 'out' label, skipping
the sense key switch block. Because good_bytes is initialized to 0 for any
non-zero result, the command will incorrectly fail instead of being handled
as fully or partially completed.

Would it be better to solely check if (!sense_valid || sense_deferred) to
ensure sshdr is initialized without discarding valid sense data on other
statuses?

>  		goto out;
>  
>  	switch (sshdr.sense_key) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260623100159.4018066-1-yangxiuwei@kylinos.cn?part=4

  reply	other threads:[~2026-06-23 10:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23 10:01 [PATCH v1 0/4] scsi: sd: fix probe error cleanup, special_vec leak and sd_done() sense gate Yang Xiuwei
2026-06-23 10:01 ` [PATCH v1 1/4] scsi: sd: fix error handling in sd_probe() after large pool creation failure Yang Xiuwei
2026-06-26 21:52   ` Damien Le Moal
2026-06-23 10:01 ` [PATCH v1 2/4] scsi: sd: unify sd_probe() error cleanup through out_put Yang Xiuwei
2026-06-26 21:54   ` Damien Le Moal
2026-06-29  1:16     ` Yang Xiuwei
2026-06-29  5:03       ` Damien Le Moal
2026-06-23 10:01 ` [PATCH v1 3/4] scsi: sd: fix special_vec mempool leak when scsi_alloc_sgtables() fails Yang Xiuwei
2026-06-23 10:20   ` sashiko-bot
2026-06-26 21:57   ` Damien Le Moal
2026-06-23 10:01 ` [PATCH v1 4/4] scsi: sd: fix sd_done() sense handling condition Yang Xiuwei
2026-06-23 10:18   ` sashiko-bot [this message]
2026-06-26 22:07   ` Damien Le Moal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260623101900.5E81F1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yangxiuwei@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox