[PATCH v4 3/6] drm/amdgpu: always clear stable_pstate_ctx in amdgpu_ctx_fini

From: Pierre-Eric Pelloux-Prayer

Date: Mon Nov 09 2026 - 12:23:15 EST


Even if the hardware is not available we should clear the pointer when
the owning context is destroyed, otherwise nobody will be able to
use this feature again.

Reported-by: Sashiko-bot <sashiko-bot@xxxxxxxxxx>
Closes: https://sashiko.dev/#/patchset/20261029152000.22001-1-pierre-eric.pelloux-prayer@xxxxxxx?part=5
Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@xxxxxxx>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 25b1cf7dc988..2b318ccc9aa6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -426,15 +426,15 @@ void amdgpu_ctx_fini(struct kref *ref)
}
}

- if (drm_dev_enter(adev_to_drm(adev), &idx)) {
- mutex_lock(&adev->pm.stable_pstate_ctx_lock);
- if (adev->pm.stable_pstate_ctx == ctx) {
+ mutex_lock(&adev->pm.stable_pstate_ctx_lock);
+ if (adev->pm.stable_pstate_ctx == ctx) {
+ if (drm_dev_enter(adev_to_drm(adev), &idx)) {
__amdgpu_ctx_set_stable_pstate(ctx, ctx->stable_pstate);
- adev->pm.stable_pstate_ctx = NULL;
+ drm_dev_exit(idx);
}
- mutex_unlock(&adev->pm.stable_pstate_ctx_lock);
- drm_dev_exit(idx);
+ adev->pm.stable_pstate_ctx = NULL;
}
+ mutex_unlock(&adev->pm.stable_pstate_ctx_lock);

kfree(ctx);
}
--
2.43.0