All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Alex Deucher <alexdeucher@gmail.com>, Weiguo Li <liwg06@foxmail.com>
Cc: "Deucher, Alexander" <alexander.deucher@amd.com>,
	amd-gfx list <amd-gfx@lists.freedesktop.org>
Subject: Re: [PATCH] drm/amdgpu: fix potential null dereference
Date: Wed, 2 Mar 2022 16:01:27 +0100	[thread overview]
Message-ID: <2cf40fb2-6d0f-660b-c238-a8c97511ab22@gmail.com> (raw)
In-Reply-To: <CADnq5_NOGDTnB+YbN2vLm9mNo1sAn4n=Seowk8vd4wuT5krDow@mail.gmail.com>

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.

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@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@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
>>


  reply	other threads:[~2022-03-02 15:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02  4:35 [PATCH] drm/amdgpu: fix potential null dereference Weiguo Li
2022-03-02 14:21 ` Alex Deucher
2022-03-02 15:01   ` Christian König [this message]
2022-03-02 15:39     ` Alex Deucher
2022-03-02 16:17       ` [PATCH v2] drm/amdgpu: remove redundant null check Weiguo Li
2022-03-02 16:53         ` Christian König
2022-03-02 18:05           ` Alex Deucher
2022-03-02  5:47 [PATCH] drm/amdgpu: fix potential null dereference Weiguo Li
2022-12-29 16:57 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:473 amdgpu_bo_validate_size() error: we previously assumed 'man' could be null (see line 458) kernel test robot
2023-01-04 22:19 ` [PATCH] drm/amdgpu: Fix potential NULL dereference Luben Tuikov
2023-01-05  9:15   ` Christian König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2cf40fb2-6d0f-660b-c238-a8c97511ab22@gmail.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=alexdeucher@gmail.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=liwg06@foxmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.