1 From 24e2e7a19f7e4b83d0d5189040d997bce3596473 Mon Sep 17 00:00:00 2001
2 From: Stanley Chu <stanley.chu@mediatek.com>
3 Date: Wed, 12 Jun 2019 23:19:05 +0800
4 Subject: scsi: ufs: Avoid runtime suspend possibly being blocked forever
6 From: Stanley Chu <stanley.chu@mediatek.com>
8 commit 24e2e7a19f7e4b83d0d5189040d997bce3596473 upstream.
10 UFS runtime suspend can be triggered after pm_runtime_enable() is invoked
11 in ufshcd_pltfrm_init(). However if the first runtime suspend is triggered
12 before binding ufs_hba structure to ufs device structure via
13 platform_set_drvdata(), then UFS runtime suspend will be no longer
14 triggered in the future because its dev->power.runtime_error was set in the
15 first triggering and does not have any chance to be cleared.
17 To be more clear, dev->power.runtime_error is set if hba is NULL in
18 ufshcd_runtime_suspend() which returns -EINVAL to rpm_callback() where
19 dev->power.runtime_error is set as -EINVAL. In this case, any future
20 rpm_suspend() for UFS device fails because rpm_check_suspend_allowed()
22 dev->power.runtime_error.
24 To resolve this issue, make sure the first UFS runtime suspend get valid
25 "hba" in ufshcd_runtime_suspend(): Enable UFS runtime PM only after hba is
26 successfully bound to UFS device structure.
28 Fixes: 62694735ca95 ([SCSI] ufs: Add runtime PM support for UFS host controller driver)
29 Cc: stable@vger.kernel.org
30 Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
31 Reviewed-by: Avri Altman <avri.altman@wdc.com>
32 Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
33 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
36 drivers/scsi/ufs/ufshcd-pltfrm.c | 11 ++++-------
37 1 file changed, 4 insertions(+), 7 deletions(-)
39 --- a/drivers/scsi/ufs/ufshcd-pltfrm.c
40 +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
41 @@ -340,24 +340,21 @@ int ufshcd_pltfrm_init(struct platform_d
45 - pm_runtime_set_active(&pdev->dev);
46 - pm_runtime_enable(&pdev->dev);
48 ufshcd_init_lanes_per_dir(hba);
50 err = ufshcd_init(hba, mmio_base, irq);
52 dev_err(dev, "Initialization failed\n");
53 - goto out_disable_rpm;
57 platform_set_drvdata(pdev, hba);
59 + pm_runtime_set_active(&pdev->dev);
60 + pm_runtime_enable(&pdev->dev);
65 - pm_runtime_disable(&pdev->dev);
66 - pm_runtime_set_suspended(&pdev->dev);
68 ufshcd_dealloc_host(hba);