]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ata: libata-eh: Fix detection of deferred qc timeouts
authorGuenter Roeck <linux@roeck-us.net>
Fri, 6 Mar 2026 02:48:05 +0000 (18:48 -0800)
committerNiklas Cassel <cassel@kernel.org>
Fri, 6 Mar 2026 08:58:47 +0000 (09:58 +0100)
If the ata_qc_for_each_raw() loop finishes without finding a matching SCSI
command for any QC, the variable qc will hold a pointer to the last element
examined, which has the tag i == ATA_MAX_QUEUE - 1. This qc can match the
port deferred QC (ap->deferred_qc).

If that happens, the condition qc == ap->deferred_qc evaluates to true
despite the loop not breaking with a match on the SCSI command for this QC.
In that case, the error handler mistakenly intercepts a command that has
not been issued yet and that has not timed out, and thus erroneously
returning a timeout error.

Fix the problem by checking for i < ATA_MAX_QUEUE in addition to
qc == ap->deferred_qc.

The problem was found by an experimental code review agent based on
gemini-3.1-pro while reviewing backports into v6.18.y.

Assisted-by: Gemini:gemini-3.1-pro
Fixes: eddb98ad9364 ("ata: libata-eh: correctly handle deferred qc timeouts")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
[cassel: modified commit log as suggested by Damien]
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Niklas Cassel <cassel@kernel.org>
drivers/ata/libata-eh.c

index 563432400f727289e8feed2e1fed1c8a68730f42..23be85418b3b1d2b2f954d640537516c87a07b5c 100644 (file)
@@ -647,7 +647,7 @@ void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap,
                                break;
                }
 
-               if (qc == ap->deferred_qc) {
+               if (i < ATA_MAX_QUEUE && qc == ap->deferred_qc) {
                        /*
                         * This is a deferred command that timed out while
                         * waiting for the command queue to drain. Since the qc