drm/amd/powerplay: Zero initialize freq in smu_v11_0_get_current_clk_freq
authorNathan Chancellor <natechancellor@gmail.com>
Thu, 4 Jul 2019 05:52:15 +0000 (22:52 -0700)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 8 Jul 2019 18:56:11 +0000 (13:56 -0500)
clang warns (trimmed for brevity):

drivers/gpu/drm/amd/amdgpu/../powerplay/smu_v11_0.c:1098:10: warning:
variable 'freq' is used uninitialized whenever '?:' condition is false
[-Wsometimes-uninitialized]
                ret =  smu_get_current_clk_freq_by_table(smu, clk_id, &freq);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If get_current_clk_freq_by_table is ever NULL, freq will fail to be
properly initialized. Zero initialize it to avoid using uninitialized
stack values.

smu_get_current_clk_freq_by_table expands to a ternary operator
conditional on smu->funcs->get_current_clk_freq_by_table being not NULL.
When this is false, freq will be uninitialized. Zero initialize freq to
avoid using random stack values if that ever happens.

Fixes: e36182490dec ("drm/amd/powerplay: fix dpm freq unit error (10KHz -> Mhz)")
Link: https://github.com/ClangBuiltLinux/linux/issues/585
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/powerplay/smu_v11_0.c

index d73e665271601d18b0f3dbd02d10fbef98b484e9..a87b86ae2cc5605ece331ffbb1776019eae87f8b 100644 (file)
@@ -1089,7 +1089,7 @@ static int smu_v11_0_get_current_clk_freq(struct smu_context *smu,
                                          uint32_t *value)
 {
        int ret = 0;
-       uint32_t freq;
+       uint32_t freq = 0;
 
        if (clk_id >= SMU_CLK_COUNT || !value)
                return -EINVAL;