Skip to contentSkip to conversation

drm/amdgpu: check return status before using stable_pstate

PATCH Applied [email protected] 2 participants 2 messages Feb 14, 2022

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

PATCH 1/1 drm/amdgpu: check return status before using stable_pstate

From: Tom Rix <[email protected]>

Clang static analysis reports this problem amdgpu_ctx.c:616:26: warning: Assigned value is garbage
or undefined

  args->out.pstate.flags = stable_pstate;
                         ^ ~~~~~~~~~~~~~

amdgpu_ctx_stable_pstate can fail without setting
stable_pstate. So check.

Fixes 8cda7a4f96e4 ("drm/amdgpu/UAPI: add new CTX OP to get/set stable pstates")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -1
index 1c72f6095f08..f522b52725e4 100644
@@ -613,7 +613,8 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
 		if (args->in.flags)
 			return -EINVAL;
 		r = amdgpu_ctx_stable_pstate(adev, fpriv, id, false, &stable_pstate);
-		args->out.pstate.flags = stable_pstate;
+		if (!r)
+			args->out.pstate.flags = stable_pstate;
 		break;
 	case AMDGPU_CTX_OP_SET_STABLE_PSTATE:
 		if (args->in.flags & ~AMDGPU_CTX_STABLE_PSTATE_FLAGS_MASK)
Signature · 1 line
2.26.3
Applied
#1 lore raw

Applied. Thanks!

Alex

Quoted 34 lines · On Mon, Feb 14, 2022 at 1:22 PM <[email protected]> wrote:

From: Tom Rix <[email protected]>

Clang static analysis reports this problem amdgpu_ctx.c:616:26: warning: Assigned value is garbage
or undefined

  args->out.pstate.flags = stable_pstate;
                         ^ ~~~~~~~~~~~~~

amdgpu_ctx_stable_pstate can fail without setting
stable_pstate. So check.

Fixes 8cda7a4f96e4 ("drm/amdgpu/UAPI: add new CTX OP to get/set stable pstates")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -2
index 1c72f6095f08..f522b52725e4 100644
@@ -613,7 +613,8 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
                if (args->in.flags)
                        return -EINVAL;
                r = amdgpu_ctx_stable_pstate(adev, fpriv, id, false, &stable_pstate);
-               args->out.pstate.flags = stable_pstate;
+               if (!r)
+                       args->out.pstate.flags = stable_pstate;
                break;
        case AMDGPU_CTX_OP_SET_STABLE_PSTATE:
                if (args->in.flags & ~AMDGPU_CTX_STABLE_PSTATE_FLAGS_MASK)
--

2.26.3