Skip to contentSkip to conversation

drm/amdgpu/userq: use pm_runtime_resume_and_get and fix err handling

PATCH In review Sunil Khatri 2 participants 2 messages Apr 11 – Apr 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu/userq: use pm_runtime_resume_and_get and fix err handling

Use pm_runtime_resume_and_get instead of pm_runtime_get_sync as it return error but put the reference in the function itself.

In goto statements we need to drop the pm reference too.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +8 -5
index 0163fba4cf74..2981f4a3c457 100644
@@ -738,10 +738,9 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	if (r)
 		return r;
 
-	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
+	r = pm_runtime_resume_and_get(adev_to_drm(adev)->dev);
 	if (r < 0) {
-		drm_file_err(uq_mgr->file, "pm_runtime_get_sync() failed for userqueue create\n");
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+		drm_file_err(uq_mgr->file, "pm_runtime_resume_and_get() failed for userqueue create\n");
 		return r;
 	}
 
@@ -749,13 +748,15 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	if (!uq_funcs) {
 		drm_file_err(uq_mgr->file, "Usermode queue is not supported for this IP (%u)\n",
 			     args->in.ip_type);
-		return -EINVAL;
+		r = -EINVAL;
+		goto err_pm_runtime;
 	}
 
 	queue = kzalloc(sizeof(struct amdgpu_usermode_queue), GFP_KERNEL);
 	if (!queue) {
 		drm_file_err(uq_mgr->file, "Failed to allocate memory for queue\n");
-		return -ENOMEM;
+		r = -ENOMEM;
+		goto err_pm_runtime;
 	}
 
 	INIT_LIST_HEAD(&queue->userq_va_list);
@@ -869,6 +870,8 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	amdgpu_bo_unreserve(fpriv->vm.root.bo);
 free_queue:
 	kfree(queue);
+err_pm_runtime:
+	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
 	return r;
 }
 
Signature · 1 line
2.34.1
#1 lore raw

Ignore. Added in the series.

Quoted 54 lines · Sunil Khatri

Use pm_runtime_resume_and_get instead of pm_runtime_get_sync as it return error but put the reference in the function itself.

In goto statements we need to drop the pm reference too.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +8 -5
index 0163fba4cf74..2981f4a3c457 100644
@@ -738,10 +738,9 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	if (r)
  		return r;
 
-	r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
+	r = pm_runtime_resume_and_get(adev_to_drm(adev)->dev);
  	if (r < 0) {
-		drm_file_err(uq_mgr->file, "pm_runtime_get_sync() failed for userqueue create\n");
-		pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
+		drm_file_err(uq_mgr->file, "pm_runtime_resume_and_get() failed for userqueue create\n");
  		return r;
  	}
 
@@ -749,13 +748,15 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	if (!uq_funcs) {
  		drm_file_err(uq_mgr->file, "Usermode queue is not supported for this IP (%u)\n",
  			     args->in.ip_type);
-		return -EINVAL;
+		r = -EINVAL;
+		goto err_pm_runtime;
  	}
 
  	queue = kzalloc(sizeof(struct amdgpu_usermode_queue), GFP_KERNEL);
  	if (!queue) {
  		drm_file_err(uq_mgr->file, "Failed to allocate memory for queue\n");
-		return -ENOMEM;
+		r = -ENOMEM;
+		goto err_pm_runtime;
  	}
 
  	INIT_LIST_HEAD(&queue->userq_va_list);
@@ -869,6 +870,8 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	amdgpu_bo_unreserve(fpriv->vm.root.bo);
  free_queue:
  	kfree(queue);
+err_pm_runtime:
+	pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
  	return r;
  }