[PATCH] drm/amdgpu: fix potential null dereference
Alex Deucher
alexdeucher at gmail.com
Wed Mar 2 15:39:08 UTC 2022
On Wed, Mar 2, 2022 at 10:01 AM Christian König
<ckoenig.leichtzumerken at gmail.com> wrote:
>
> Looks like my response never made it through.
>
> This change and the existing check is nonsense. The caller makes sure
> that ctx is never NULL here.
>
> So the check should probably just be dropped entirely.
agreed and dropped. Weiguo care to send a patch to drop the checks?
Alex
>
> Regards,
> Christian.
>
> Am 02.03.22 um 15:21 schrieb Alex Deucher:
> > Applied. Thanks!
> >
> > Alex
> >
> > On Wed, Mar 2, 2022 at 3:56 AM Weiguo Li <liwg06 at foxmail.com> wrote:
> >> "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 <liwg06 at foxmail.com>
> >> ---
> >> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 6 ++++--
> >> 1 file changed, 4 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> >> index f522b52725e4..b4f035ce44bc 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> >> @@ -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) {
> >> --
> >> 2.25.1
> >>
>
More information about the amd-gfx
mailing list