Skip to content

Commit

Permalink
scsi: ufs: Avoid runtime suspend possibly being blocked forever
Browse files Browse the repository at this point in the history
UFS runtime suspend can be triggered after pm_runtime_enable() is invoked
in ufshcd_pltfrm_init(). However if the first runtime suspend is triggered
before binding ufs_hba structure to ufs device structure via
platform_set_drvdata(), then UFS runtime suspend will be no longer
triggered in the future because its dev->power.runtime_error was set in the
first triggering and does not have any chance to be cleared.

To be more clear, dev->power.runtime_error is set if hba is NULL in
ufshcd_runtime_suspend() which returns -EINVAL to rpm_callback() where
dev->power.runtime_error is set as -EINVAL. In this case, any future
rpm_suspend() for UFS device fails because rpm_check_suspend_allowed()
fails due to non-zero
dev->power.runtime_error.

To resolve this issue, make sure the first UFS runtime suspend get valid
"hba" in ufshcd_runtime_suspend(): Enable UFS runtime PM only after hba is
successfully bound to UFS device structure.

Fixes: 6269473 ([SCSI] ufs: Add runtime PM support for UFS host controller driver)
Cc: stable@vger.kernel.org
Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Stanley Chu authored and Martin K. Petersen committed Jun 19, 2019
1 parent 8cf4c54 commit 24e2e7a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions drivers/scsi/ufs/ufshcd-pltfrm.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,24 +430,21 @@ int ufshcd_pltfrm_init(struct platform_device *pdev,
goto dealloc_host;
}

pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);

ufshcd_init_lanes_per_dir(hba);

err = ufshcd_init(hba, mmio_base, irq);
if (err) {
dev_err(dev, "Initialization failed\n");
goto out_disable_rpm;
goto dealloc_host;
}

platform_set_drvdata(pdev, hba);

pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);

return 0;

out_disable_rpm:
pm_runtime_disable(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
dealloc_host:
ufshcd_dealloc_host(hba);
out:
Expand Down

0 comments on commit 24e2e7a

Please sign in to comment.