On Fri, May 15, 2026 at 5:49 PM Mario Limonciello
<[email protected]> wrote:
>
> [Why]
> amdgpu_pmops_runtime_suspend() runs almost the same code  that
> amdgpu_pmops_runtime_idle() runs. That is there is pointless code
> duplication.
>
> [How]
> Move amdgpu_pmops_runtime_idle() up, extract common code and then
> call from both functions.  No intended functional changes.
>
> Signed-off-by: Mario Limonciello <[email protected]>

Reviewed-by: Alex Deucher <[email protected]>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 50 ++++++++++++-------------
>  1 file changed, 24 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index b422513fe3793..15a2dddede2a8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -2797,12 +2797,11 @@ static int amdgpu_runtime_idle_check_userq(struct 
> device *dev)
>         return xa_empty(&adev->userq_doorbell_xa) ? 0 : -EBUSY;
>  }
>
> -static int amdgpu_pmops_runtime_suspend(struct device *dev)
> +static int amdgpu_pmops_runtime_checks(struct device *dev)
>  {
> -       struct pci_dev *pdev = to_pci_dev(dev);
> -       struct drm_device *drm_dev = pci_get_drvdata(pdev);
> +       struct drm_device *drm_dev = dev_get_drvdata(dev);
>         struct amdgpu_device *adev = drm_to_adev(drm_dev);
> -       int ret, i;
> +       int ret;
>
>         if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
>                 pm_runtime_forbid(dev);
> @@ -2812,7 +2811,27 @@ static int amdgpu_pmops_runtime_suspend(struct device 
> *dev)
>         ret = amdgpu_runtime_idle_check_display(dev);
>         if (ret)
>                 return ret;
> -       ret = amdgpu_runtime_idle_check_userq(dev);
> +
> +       return amdgpu_runtime_idle_check_userq(dev);
> +}
> +
> +static int amdgpu_pmops_runtime_idle(struct device *dev)
> +{
> +       int ret;
> +
> +       ret = amdgpu_pmops_runtime_checks(dev);
> +       pm_runtime_autosuspend(dev);
> +       return ret;
> +}
> +
> +static int amdgpu_pmops_runtime_suspend(struct device *dev)
> +{
> +       struct pci_dev *pdev = to_pci_dev(dev);
> +       struct drm_device *drm_dev = pci_get_drvdata(pdev);
> +       struct amdgpu_device *adev = drm_to_adev(drm_dev);
> +       int ret, i;
> +
> +       ret = amdgpu_pmops_runtime_checks(dev);
>         if (ret)
>                 return ret;
>
> @@ -2924,27 +2943,6 @@ static int amdgpu_pmops_runtime_resume(struct device 
> *dev)
>         return 0;
>  }
>
> -static int amdgpu_pmops_runtime_idle(struct device *dev)
> -{
> -       struct drm_device *drm_dev = dev_get_drvdata(dev);
> -       struct amdgpu_device *adev = drm_to_adev(drm_dev);
> -       int ret;
> -
> -       if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) {
> -               pm_runtime_forbid(dev);
> -               return -EBUSY;
> -       }
> -
> -       ret = amdgpu_runtime_idle_check_display(dev);
> -       if (ret)
> -               goto done;
> -
> -       ret = amdgpu_runtime_idle_check_userq(dev);
> -done:
> -       pm_runtime_autosuspend(dev);
> -       return ret;
> -}
> -
>  static int amdgpu_drm_release(struct inode *inode, struct file *filp)
>  {
>         struct drm_file *file_priv = filp->private_data;
> --
> 2.43.0
>

Reply via email to