Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libata: only call ->done once all per-tag ressources are released

When calling ->done before releasing resources we could run into a
race where the SCSI midlayer sends another command and races with
the resources beeing manipulated. For libata this can't currently
happen as synchronization happens at a higher level, but I'd still
like to fix it to future proof libata and to avoid copy & paste
into SCSI drivers where this pattern has led to reproducible crashes.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Christoph Hellwig and committed by
Tejun Heo
2aa8f5d6 25c7ce7f

+13 -9
+13 -9
drivers/ata/libata-scsi.c
··· 1757 1757 return 1; 1758 1758 } 1759 1759 1760 + static void ata_qc_done(struct ata_queued_cmd *qc) 1761 + { 1762 + struct scsi_cmnd *cmd = qc->scsicmd; 1763 + void (*done)(struct scsi_cmnd *) = qc->scsidone; 1764 + 1765 + ata_qc_free(qc); 1766 + done(cmd); 1767 + } 1768 + 1760 1769 static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) 1761 1770 { 1762 1771 struct ata_port *ap = qc->ap; ··· 1793 1784 if (need_sense && !ap->ops->error_handler) 1794 1785 ata_dump_status(ap->print_id, &qc->result_tf); 1795 1786 1796 - qc->scsidone(cmd); 1797 - 1798 - ata_qc_free(qc); 1787 + ata_qc_done(qc); 1799 1788 } 1800 1789 1801 1790 /** ··· 2595 2588 ata_gen_passthru_sense(qc); 2596 2589 } 2597 2590 2598 - qc->scsidone(qc->scsicmd); 2599 - ata_qc_free(qc); 2591 + ata_qc_done(qc); 2600 2592 } 2601 2593 2602 2594 /* is it pointless to prefer PIO for "safety reasons"? */ ··· 2690 2684 qc->dev->sdev->locked = 0; 2691 2685 2692 2686 qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; 2693 - qc->scsidone(cmd); 2694 - ata_qc_free(qc); 2687 + ata_qc_done(qc); 2695 2688 return; 2696 2689 } 2697 2690 ··· 2734 2729 cmd->result = SAM_STAT_GOOD; 2735 2730 } 2736 2731 2737 - qc->scsidone(cmd); 2738 - ata_qc_free(qc); 2732 + ata_qc_done(qc); 2739 2733 } 2740 2734 /** 2741 2735 * atapi_xlat - Initialize PACKET taskfile