Skip to contentSkip to conversation

amdgpu: assign adev after null check

PATCH In review Qing Wang 2 participants 2 messages Feb 15, 2022

Subsystems (2)
lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 amdgpu: assign adev after null check

From: Wang Qing <[email protected]>

adev should be assigned after a null check

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +4 -2
index 2c929fa..da114f7
@@ -259,12 +259,13 @@ static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
 static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
 					u32 *stable_pstate)
 {
-	struct amdgpu_device *adev = ctx->adev;
+	struct amdgpu_device *adev;
 	enum amd_dpm_forced_level current_level;
 
 	if (!ctx)
 		return -EINVAL;
 
+	adev = ctx->adev;
 	current_level = amdgpu_dpm_get_performance_level(adev);
 
 	switch (current_level) {
@@ -290,13 +291,14 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
 static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
 					u32 stable_pstate)
 {
-	struct amdgpu_device *adev = ctx->adev;
+	struct amdgpu_device *adev;
 	enum amd_dpm_forced_level level;
 	int r;
 
 	if (!ctx)
 		return -EINVAL;
 
+	adev = ctx->adev;
 	mutex_lock(&adev->pm.stable_pstate_ctx_lock);
 	if (adev->pm.stable_pstate_ctx && adev->pm.stable_pstate_ctx != ctx) {
 		r = -EBUSY;
Signature · 1 line
2.7.4
maintainer
#1 lore raw

Am 15.02.22 um 02:59 schrieb Qing Wang:

Quoted 3 lines

From: Wang Qing <[email protected]>

adev should be assigned after a null check

I would rather remove the NULL check altogether.

The caller is supposed to make sure that the context is valid and even if it isn't that's not a recoverable error here.

Regards,
Christian.

Quoted 41 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +4 -2
index 2c929fa..da114f7
@@ -259,12 +259,13 @@ static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity)
  static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
  					u32 *stable_pstate)
  {
-	struct amdgpu_device *adev = ctx->adev;
+	struct amdgpu_device *adev;
  	enum amd_dpm_forced_level current_level;
 
  	if (!ctx)
  		return -EINVAL;
 
+	adev = ctx->adev;
  	current_level = amdgpu_dpm_get_performance_level(adev);
 
  	switch (current_level) {
@@ -290,13 +291,14 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx,
  static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx,
  					u32 stable_pstate)
  {
-	struct amdgpu_device *adev = ctx->adev;
+	struct amdgpu_device *adev;
  	enum amd_dpm_forced_level level;
  	int r;
 
  	if (!ctx)
  		return -EINVAL;
 
+	adev = ctx->adev;
  	mutex_lock(&adev->pm.stable_pstate_ctx_lock);
  	if (adev->pm.stable_pstate_ctx && adev->pm.stable_pstate_ctx != ctx) {
  		r = -EBUSY;