[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CADnq5_NGiM+Bs_AwBC5GUOv2Dx11_fvaqJXtQZKR_drVy68O8w@mail.gmail.com>
Date: Mon, 8 Jul 2019 12:03:09 -0400
From: Alex Deucher <alexdeucher@...il.com>
To: Arnd Bergmann <arnd@...db.de>
Cc: Rex Zhu <rex.zhu@....com>, Evan Quan <evan.quan@....com>,
Alex Deucher <alexander.deucher@....com>,
Christian König <christian.koenig@....com>,
"David (ChunMing) Zhou" <David1.Zhou@....com>,
David Airlie <airlied@...ux.ie>,
Daniel Vetter <daniel@...ll.ch>,
Chengming Gui <Jack.Gui@....com>,
Kevin Wang <kevin1.wang@....com>,
LKML <linux-kernel@...r.kernel.org>,
amd-gfx list <amd-gfx@...ts.freedesktop.org>,
Huang Rui <ray.huang@....com>,
Maling list - DRI developers
<dri-devel@...ts.freedesktop.org>, Likun Gao <Likun.Gao@....com>,
Hawking Zhang <Hawking.Zhang@....com>
Subject: Re: [PATCH 2/2] drm/amd/powerplay: vega20: fix uninitialized variable use
On Mon, Jul 8, 2019 at 10:08 AM Arnd Bergmann <arnd@...db.de> wrote:
>
> If smu_get_current_rpm() fails, we can't use the output,
> as that may be uninitialized:
>
> drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c:3023:8: error: variable 'current_rpm' is used uninitialized whenever '?:' condition is false [-Werror,-Wsometimes-uninitialized]
> ret = smu_get_current_rpm(smu, ¤t_rpm);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/gpu/drm/amd/amdgpu/../powerplay/inc/amdgpu_smu.h:735:3: note: expanded from macro 'smu_get_current_rpm'
> ((smu)->funcs->get_current_rpm ? (smu)->funcs->get_current_rpm((smu), (speed)) : 0)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c:3024:12: note: uninitialized use occurs here
> percent = current_rpm * 100 / pptable->FanMaximumRpm;
> ^~~~~~~~~~~
> drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c:3023:8: note: remove the '?:' if its condition is always true
> ret = smu_get_current_rpm(smu, ¤t_rpm);
> ^
> drivers/gpu/drm/amd/amdgpu/../powerplay/inc/amdgpu_smu.h:735:3: note: expanded from macro 'smu_get_current_rpm'
> ((smu)->funcs->get_current_rpm ? (smu)->funcs->get_current_rpm((smu), (speed)) : 0)
> ^
> drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c:3020:22: note: initialize the variable 'current_rpm' to silence this warning
> uint32_t current_rpm;
>
> Propagate the error code in that case.
>
> Fixes: ee0db82027ee ("drm/amd/powerplay: move PPTable_t uses into asic level")
> Signed-off-by: Arnd Bergmann <arnd@...db.de>
Applied. thanks!
Alex
> ---
> drivers/gpu/drm/amd/powerplay/vega20_ppt.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
> index 9ce3f1c8ae0f..20d477f8dc84 100644
> --- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
> +++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
> @@ -3021,10 +3021,13 @@ static int vega20_get_fan_speed_percent(struct smu_context *smu,
> PPTable_t *pptable = smu->smu_table.driver_pptable;
>
> ret = smu_get_current_rpm(smu, ¤t_rpm);
> + if (ret)
> + return ret;
> +
> percent = current_rpm * 100 / pptable->FanMaximumRpm;
> *speed = percent > 100 ? 100 : percent;
>
> - return ret;
> + return 0;
> }
>
> static int vega20_get_gpu_power(struct smu_context *smu, uint32_t *value)
> --
> 2.20.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@...ts.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Powered by blists - more mailing lists