drm/amdgpu: fix potential null dereference
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix potential null dereference
"ctx" is dereferenced but null checked later. Swap their positions to avoid potential null dereference.
Found using a Coccinelle script:
https://coccinelle.gitlabpages.inria.fr/website/rules/mini_null_ref.cocci
Signed-off-by Weiguo Li <[email protected]>
--- 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
@@ -258,11 +258,12 @@ 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);
@@ -289,12 +290,13 @@ 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) {
Signature · 1 line
2.25.1