From: Takashi Iwai <tiwai@suse.de>
Subject: [PATCH] ata: Fix racy link clearance
Date: Wed, 14 Nov 2018 15:40:50 +0100
Message-id: <20181114144050.12630-1-tiwai@suse.de>
Patch-mainline: Submitted, linux-ide ML
References: bsc#1107866
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 | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -1267,23 +1267,26 @@ void ata_sff_flush_pio_task(struct ata_p
*/
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);
}
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) {