From 639358dd6e2f7e5e9f7e66b828bf043fa3c7bbf2 Mon Sep 17 00:00:00 2001 From: Can Guo Date: Sat, 9 Jan 2021 12:37:40 +0800 Subject: [PATCH] scsi: ufs: Reproduce race condition btw sysfs access and shutdown Reproduce race condition btw sysfs access and shutdown Usage: Signed-off-by: Can Guo diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 92a63ee..a29a490 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -59,6 +59,8 @@ static ssize_t rpm_lvl_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); + BUG_ON(hba->shutting_down); + return sprintf(buf, "%d\n", hba->rpm_lvl); } diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 698e8d2..210fa5c 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -8277,6 +8277,11 @@ int ufshcd_shutdown(struct ufs_hba *hba) { int ret = 0; + hba->shutting_down = true; + pr_err("[DEBUG]%s: UFS SHUTDOWN START\n", __func__); + + usleep_range(10000000, 11000000); + if (!hba->is_powered) goto out; @@ -8294,6 +8299,7 @@ int ufshcd_shutdown(struct ufs_hba *hba) if (ret) dev_err(hba->dev, "%s failed, err %d\n", __func__, ret); /* allow force shutdown even in case of errors */ + pr_err("[DEBUG]%s: UFS SHUTDOWN END\n", __func__); return 0; } EXPORT_SYMBOL(ufshcd_shutdown); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 6ffc08a..3a40d94 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -677,6 +677,7 @@ struct ufs_hba { u16 ee_ctrl_mask; u16 hba_enable_delay_us; bool is_powered; + bool shutting_down; /* Work Queues */ struct work_struct eh_work; -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.