Skip to content

Commit 5bb52d9

Browse files
committed
ata: libata: Improve __ata_qc_complete()
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 <[email protected]> Reviewed-by: Niklas Cassel <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]>
1 parent a169515 commit 5bb52d9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/ata/libata-core.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4829,8 +4829,9 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
48294829
struct ata_port *ap;
48304830
struct ata_link *link;
48314831

4832-
WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
4833-
WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
4832+
if (WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE)))
4833+
return;
4834+
48344835
ap = qc->ap;
48354836
link = qc->dev->link;
48364837

@@ -4852,9 +4853,10 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
48524853
ap->excl_link == link))
48534854
ap->excl_link = NULL;
48544855

4855-
/* atapi: mark qc as inactive to prevent the interrupt handler
4856-
* from completing the command twice later, before the error handler
4857-
* is called. (when rc != 0 and atapi request sense is needed)
4856+
/*
4857+
* Mark qc as inactive to prevent the port interrupt handler from
4858+
* completing the command twice later, before the error handler is
4859+
* called.
48584860
*/
48594861
qc->flags &= ~ATA_QCFLAG_ACTIVE;
48604862
ap->qc_active &= ~(1ULL << qc->tag);

0 commit comments

Comments
 (0)