Skip to content

Commit 7cbff57

Browse files
KyoungrulKimmartinkpetersen
authored andcommitted
scsi: ufs: core: Remove SCSI host only if added
If host tries to remove ufshcd driver from a UFS device it would cause a kernel panic if ufshcd_async_scan fails during ufshcd_probe_hba before adding a SCSI host with scsi_add_host and MCQ is enabled since SCSI host has been defered after MCQ configuration introduced by commit 0cab402 ("scsi: ufs: core: Defer adding host to SCSI if MCQ is supported"). To guarantee that SCSI host is removed only if it has been added, set the scsi_host_added flag to true after adding a SCSI host and check whether it is set or not before removing it. Signed-off-by: Kyoungrul Kim <[email protected]> Signed-off-by: Minwoo Im <[email protected]> Link: https://lore.kernel.org/r/20240627085104epcms2p5897a3870ea5c6416aa44f94df6c543d7@epcms2p5 Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent ed7dac8 commit 7cbff57

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10216,7 +10216,8 @@ void ufshcd_remove(struct ufs_hba *hba)
1021610216
blk_mq_destroy_queue(hba->tmf_queue);
1021710217
blk_put_queue(hba->tmf_queue);
1021810218
blk_mq_free_tag_set(&hba->tmf_tag_set);
10219-
scsi_remove_host(hba->host);
10219+
if (hba->scsi_host_added)
10220+
scsi_remove_host(hba->host);
1022010221
/* disable interrupts */
1022110222
ufshcd_disable_intr(hba, hba->intr_mask);
1022210223
ufshcd_hba_stop(hba);
@@ -10495,6 +10496,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
1049510496
dev_err(hba->dev, "scsi_add_host failed\n");
1049610497
goto out_disable;
1049710498
}
10499+
hba->scsi_host_added = true;
1049810500
}
1049910501

1050010502
hba->tmf_tag_set = (struct blk_mq_tag_set) {
@@ -10577,7 +10579,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
1057710579
free_tmf_tag_set:
1057810580
blk_mq_free_tag_set(&hba->tmf_tag_set);
1057910581
out_remove_scsi_host:
10580-
scsi_remove_host(hba->host);
10582+
if (hba->scsi_host_added)
10583+
scsi_remove_host(hba->host);
1058110584
out_disable:
1058210585
hba->is_irq_enabled = false;
1058310586
ufshcd_hba_exit(hba);

0 commit comments

Comments
 (0)