linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ata: Fix racy link clearance
@ 2018-11-14 14:40 Takashi Iwai
  0 siblings, 0 replies; only message in thread
From: Takashi Iwai @ 2018-11-14 14:40 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-ide, linux-kernel

The ap->sff_pio_task_link gets cleared in a racy way in
ata_sff_flush_pio_task().  This may lead to BUG_ON() check in the
work, and screw up the whole system.

Along with it, replace BUG_ON() with WARN_ON() and let the work quit
gracefully.  It's no end of the world, after all.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 drivers/ata/libata-sff.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index c5ea0fc635e5..28ef46ef656d 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -1271,9 +1271,8 @@ void ata_sff_flush_pio_task(struct ata_port *ap)
 	 */
 	spin_lock_irq(ap->lock);
 	ap->hsm_task_state = HSM_ST_IDLE;
-	spin_unlock_irq(ap->lock);
-
 	ap->sff_pio_task_link = NULL;
+	spin_unlock_irq(ap->lock);
 
 	if (ata_msg_ctl(ap))
 		ata_port_dbg(ap, "%s: EXIT\n", __func__);
@@ -1283,14 +1282,17 @@ static void ata_sff_pio_task(struct work_struct *work)
 {
 	struct ata_port *ap =
 		container_of(work, struct ata_port, sff_pio_task.work);
-	struct ata_link *link = ap->sff_pio_task_link;
+	struct ata_link *link;
 	struct ata_queued_cmd *qc;
 	u8 status;
 	int poll_next;
 
 	spin_lock_irq(ap->lock);
 
-	BUG_ON(ap->sff_pio_task_link == NULL);
+	link = ap->sff_pio_task_link;
+	if (WARN_ON(!link))
+		goto out_unlock;
+
 	/* qc can be NULL if timeout occurred */
 	qc = ata_qc_from_tag(ap, link->active_tag);
 	if (!qc) {
-- 
2.19.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-11-14 14:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 14:40 [PATCH] ata: Fix racy link clearance Takashi Iwai

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).