Skip to contentSkip to conversation

drm/amdgpu: Validate return value of pm_runtime_get_sync

PATCH Superseded Sunil Khatri 3 participants 5 messages Mar 4, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Validate return value of pm_runtime_get_sync

An invalid return value 'r' of the pm_runtime_get_sync is r < 0 so fix the return value and add proper logging of failure and exit cleanly.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +4 -1
index 3a71d01b54c9..6babadeec268 100644
@@ -289,8 +289,11 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 	queue->userq_prop = userq_props;
 
 	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
-	if (r)
+	if (r < 0) {
+		DRM_ERROR("Failed to increment ref count of device pm_runtime \n");
+		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 		goto free_mqd;
+	}
 
 	r = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, userq_props);
 	if (r) {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines · Sunil Khatri

An invalid return value 'r' of the pm_runtime_get_sync is r < 0 so fix the return value and add proper logging of failure and exit cleanly.

You have an extra space between "failure" and "and".

Quoted 11 lines
---
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -0
index 3a71d01b54c9..6babadeec268 100644

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, · line 293

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -1
@@ -289,8 +289,11 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
  	queue->userq_prop = userq_props;
 
  	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
-	if (r)
+	if (r < 0) {
+		DRM_ERROR("Failed to increment ref count of device pm_runtime \n");

For new code can you please use drm_err() instead of DRM_ERROR()?

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -0
+		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
  		goto free_mqd;
+	}
 
  	r = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, userq_props);
  	if (r) {
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Tuesday, March 4, 2025 11:27 PM
To: Khatri, Sunil <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] drm/amdgpu: Validate return value of pm_runtime_get_sync

Quoted 2 lines · Sunil Khatri

An invalid return value 'r' of the pm_runtime_get_sync is r < 0 so fix the return value and add proper logging of failure and exit cleanly.

You have an extra space between "failure" and "and". Noted.

Quoted 12 lines
---
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -0
index 3a71d01b54c9..6babadeec268 100644

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, · line 293

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -1
@@ -289,8 +289,11 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
      queue->userq_prop = userq_props;
 
      r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
-     if (r)
+     if (r < 0) {
+             DRM_ERROR("Failed to increment ref count of device pm_runtime \n");

For new code can you please use drm_err() instead of DRM_ERROR()?
I see drm_err is not used anywhere in amdgpu driver but display is using it. I think it would be better if I take it in a different patch to change instead. Does that sounds ok ?

Regards
Sunil Khatri

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -0
+             pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
              goto free_mqd;
+     }
 
      r = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, userq_props);
      if (r) {
#3 lore raw
Quoted 3 lines · Sunil

For new code can you please use drm_err() instead of DRM_ERROR()?
I see drm_err is not used anywhere in amdgpu driver but display is using it. I think it would be better if I take it in a different patch to change instead. Does that sounds ok ?

DRM_ERROR() doesn't give any information on a multi-GPU system which GPU had the problem. drm_err() does. So it's the preferred macro for errors.

Up to Alex and Christian if they take this as is or spin it, but I think it's a very simple change.

Quoted 10 lines

Regards
Sunil Khatri

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -0
+             pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
               goto free_mqd;
+     }
 
       r = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, userq_props);
       if (r) {
#4 lore raw
Quoted 11 lines · Mario Limonciello
Quoted 3 lines · Sunil

For new code can you please use drm_err() instead of DRM_ERROR()?
I see drm_err is not used anywhere in amdgpu driver but display is using it. I think it would be better if I take it in a different patch to change instead. Does that sounds ok ?

DRM_ERROR() doesn't give any information on a multi-GPU system which GPU had the problem. drm_err() does. So it's the preferred macro for errors.

Up to Alex and Christian if they take this as is or spin it, but I think it's a very simple change.

Please use the dev_err() or drm_err() variants. We mostly use the dev variants outside of the display code.

Alex

Quoted 12 lines
Quoted 11 lines

Regards
Sunil Khatri

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -0
+             pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
               goto free_mqd;
+     }
 
       r = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, userq_props);
       if (r) {