linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: linux-ide@vger.kernel.org, Niklas Cassel <cassel@kernel.org>
Subject: [PATCH v5 3/9] ata: libata: Improve __ata_qc_complete()
Date: Fri,  6 Sep 2024 10:58:41 +0900	[thread overview]
Message-ID: <20240906015847.229539-4-dlemoal@kernel.org> (raw)
In-Reply-To: <20240906015847.229539-1-dlemoal@kernel.org>

The function __ata_qc_complete() is always called with a qc that already
has been dereferenced and so is guaranteed to be non-NULL (as otherwise
the kernel would have crashed). So remove the warning for a NULL qc as
it is useless.

Furthermore, the qc passed to __ata_qc_complete() must always be marked
as active with the ATA_QCFLAG_ACTIVE flag. If that is not the case, in
addition to the existing warning, return early so that we do not attempt
to complete an invalid qc.

Finally, fix the comment related to clearing the qc active flag as that
operation applies to all devices, not just ATAPI ones.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
 drivers/ata/libata-core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index e4023fc288ac..5acc37397f4b 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4829,8 +4829,9 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
 	struct ata_port *ap;
 	struct ata_link *link;
 
-	WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
-	WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
+	if (WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE)))
+		return;
+
 	ap = qc->ap;
 	link = qc->dev->link;
 
@@ -4852,9 +4853,10 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
 		     ap->excl_link == link))
 		ap->excl_link = NULL;
 
-	/* atapi: mark qc as inactive to prevent the interrupt handler
-	 * from completing the command twice later, before the error handler
-	 * is called. (when rc != 0 and atapi request sense is needed)
+	/*
+	 * Mark qc as inactive to prevent the port interrupt handler from
+	 * completing the command twice later, before the error handler is
+	 * called.
 	 */
 	qc->flags &= ~ATA_QCFLAG_ACTIVE;
 	ap->qc_active &= ~(1ULL << qc->tag);
-- 
2.46.0


  parent reply	other threads:[~2024-09-06  1:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06  1:58 [PATCH v5 0/9] Code cleanup and memory usage reduction Damien Le Moal
2024-09-06  1:58 ` [PATCH v5 1/9] ata: libata: Cleanup libata-transport Damien Le Moal
2024-09-06  1:58 ` [PATCH v5 2/9] ata: libata-scsi: Improve ata_scsi_handle_link_detach() Damien Le Moal
2024-09-06  8:32   ` Niklas Cassel
2024-09-06  1:58 ` Damien Le Moal [this message]
2024-09-06  1:58 ` [PATCH v5 4/9] ata: libata: Move sata_down_spd_limit() to libata-sata.c Damien Le Moal
2024-09-06  1:58 ` [PATCH v5 5/9] ata: libata: Move sata_std_hardreset() definition " Damien Le Moal
2024-09-06  1:58 ` [PATCH v5 6/9] ata: libata: Rename ata_eh_read_sense_success_ncq_log() Damien Le Moal
2024-09-06  1:58 ` [PATCH v5 7/9] ata: libata: Move sector_buf from struct ata_port to struct ata_device Damien Le Moal
2024-09-06  1:58 ` [PATCH v5 8/9] ata: libata: Introduce ata_dev_free_resources Damien Le Moal
2024-09-06  8:41   ` Niklas Cassel
2024-09-06  1:58 ` [PATCH v5 9/9] ata: libata: Improve CDL resource management Damien Le Moal
2024-09-06  8:51   ` Niklas Cassel
2024-09-06 10:21     ` 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=20240906015847.229539-4-dlemoal@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=cassel@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).