Skip to contentSkip to conversation

drm/amd/powerplay: Zero initialize some variables

PATCH Applied Nathan Chancellor 3 participants 3 messages Aug 4, 2019 – Aug 6, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/powerplay: Zero initialize some variables

Clang warns (only Navi warning shown but Arcturus warns as well):

drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1534:4: warning:
variable 'asic_default_power_limit' is used uninitialized whenever '?:' condition is false [-Wsometimes-uninitialized]

                        smu_read_smc_arg(smu, &asic_default_power_limit);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/../powerplay/inc/amdgpu_smu.h:588:3: note:
expanded from macro 'smu_read_smc_arg'
        ((smu)->funcs->read_smc_arg? (smu)->funcs->read_smc_arg((smu), (arg)) : 0)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1550:30: note:
uninitialized use occurs here
                smu->default_power_limit = asic_default_power_limit;
                                           ^~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1534:4: note:
remove the '?:' if its condition is always true
                        smu_read_smc_arg(smu, &asic_default_power_limit);
                        ^
drivers/gpu/drm/amd/amdgpu/../powerplay/inc/amdgpu_smu.h:588:3: note:
expanded from macro 'smu_read_smc_arg'
        ((smu)->funcs->read_smc_arg? (smu)->funcs->read_smc_arg((smu), (arg)) : 0)
         ^
drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1517:35: note:
initialize the variable 'asic_default_power_limit' to silence this
warning
        uint32_t asic_default_power_limit;
                                         ^
                                          = 0

1 warning generated.

As the code is currently written, if read_smc_arg were ever NULL, arg would fail to be initialized but the code would continue executing as normal because the return value would just be zero.

There are a few different possible solutions to resolve this class of warnings which have appeared in these drivers before:

1. Assume the function pointer will never be NULL and eliminate the wrapper macros.

2. Have the wrapper macros initialize arg when the function pointer is NULL.

3. Have the wrapper macros return an error code instead of 0 when the function pointer is NULL so that the callsites can properly bail out before arg can be used.

4. Initialize arg at the top of its function.

Number four is the path of least resistance right now as every other change will be driver wide so do that here. I only make the comment now as food for thought.

Fixes b4af964e75c4 ("drm/amd/powerplay: make power limit retrieval as asic specific")
---
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 2 +-
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -1
index 215f7173fca8..b92eded7374f 100644
@@ -1326,7 +1326,7 @@ static int arcturus_get_power_limit(struct smu_context *smu,
 				     bool asic_default)
 {
 	PPTable_t *pptable = smu->smu_table.driver_pptable;
-	uint32_t asic_default_power_limit;
+	uint32_t asic_default_power_limit = 0;
 	int ret = 0;
 	int power_src;
 
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -1
index 106352a4fb82..d844bc8411aa 100644
@@ -1514,7 +1514,7 @@ static int navi10_get_power_limit(struct smu_context *smu,
 				     bool asic_default)
 {
 	PPTable_t *pptable = smu->smu_table.driver_pptable;
-	uint32_t asic_default_power_limit;
+	uint32_t asic_default_power_limit = 0;
 	int ret = 0;
 	int power_src;
 
Signature · 1 line
2.23.0.rc1
#1 lore raw

Thanks Nathan. The patch is reviewed-by: Evan Quan <[email protected]>

Quoted 109 lines

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: Monday, August 05, 2019 4:37 AM
To: Quan, Evan <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, David(ChunMing) <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Nathan Chancellor <[email protected]>
Subject: [PATCH] drm/amd/powerplay: Zero initialize some variables

Clang warns (only Navi warning shown but Arcturus warns as well):

drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1534:4: warning:
variable 'asic_default_power_limit' is used uninitialized whenever '?:' condition is false [-Wsometimes-uninitialized]

                        smu_read_smc_arg(smu, &asic_default_power_limit);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/../powerplay/inc/amdgpu_smu.h:588:3:
note:
expanded from macro 'smu_read_smc_arg'
        ((smu)->funcs->read_smc_arg? (smu)->funcs->read_smc_arg((smu),
(arg)) : 0)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1550:30: note:
uninitialized use occurs here
                smu->default_power_limit = asic_default_power_limit;
                                           ^~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1534:4: note:
remove the '?:' if its condition is always true
                        smu_read_smc_arg(smu, &asic_default_power_limit);
                        ^
drivers/gpu/drm/amd/amdgpu/../powerplay/inc/amdgpu_smu.h:588:3:
note:
expanded from macro 'smu_read_smc_arg'
        ((smu)->funcs->read_smc_arg? (smu)->funcs->read_smc_arg((smu),
(arg)) : 0)
         ^
drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1517:35: note:
initialize the variable 'asic_default_power_limit' to silence this warning
        uint32_t asic_default_power_limit;
                                         ^
                                          = 0

1 warning generated.

As the code is currently written, if read_smc_arg were ever NULL, arg would fail to be initialized but the code would continue executing as normal because the return value would just be zero.

There are a few different possible solutions to resolve this class of warnings which have appeared in these drivers before:

1. Assume the function pointer will never be NULL and eliminate the wrapper macros.

2. Have the wrapper macros initialize arg when the function pointer is NULL.

3. Have the wrapper macros return an error code instead of 0 when the function pointer is NULL so that the callsites can properly bail out before arg can be used.

4. Initialize arg at the top of its function.

Number four is the path of least resistance right now as every other change will be driver wide so do that here. I only make the comment now as food for thought.

Fixes b4af964e75c4 ("drm/amd/powerplay: make power limit retrieval as

asic specific")

---
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 2 +-
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -1
index 215f7173fca8..b92eded7374f 100644
@@ -1326,7 +1326,7 @@ static int arcturus_get_power_limit(struct
 smu_context *smu,
 				     bool asic_default)
 {
 	PPTable_t *pptable = smu->smu_table.driver_pptable;
-	uint32_t asic_default_power_limit;
+	uint32_t asic_default_power_limit = 0;
 	int ret = 0;
 	int power_src;
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -2
index 106352a4fb82..d844bc8411aa 100644
@@ -1514,7 +1514,7 @@ static int navi10_get_power_limit(struct
 smu_context *smu,
 				     bool asic_default)
 {
 	PPTable_t *pptable = smu->smu_table.driver_pptable;
-	uint32_t asic_default_power_limit;
+	uint32_t asic_default_power_limit = 0;
 	int ret = 0;
 	int power_src;
 
--
Quoted 1 line

2.23.0.rc1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Applied
#2 lore raw

Applied. Thanks!

Alex

Quoted 111 lines · Evan

Thanks Nathan. The patch is reviewed-by: Evan Quan <[email protected]>

Quoted 108 lines

-----Original Message-----
From: Nathan Chancellor <[email protected]>
Sent: Monday, August 05, 2019 4:37 AM
To: Quan, Evan <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, David(ChunMing) <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; Nathan Chancellor <[email protected]>
Subject: [PATCH] drm/amd/powerplay: Zero initialize some variables

Clang warns (only Navi warning shown but Arcturus warns as well):

drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1534:4: warning:
variable 'asic_default_power_limit' is used uninitialized whenever '?:' condition is false [-Wsometimes-uninitialized]

                        smu_read_smc_arg(smu, &asic_default_power_limit);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/../powerplay/inc/amdgpu_smu.h:588:3:
note:
expanded from macro 'smu_read_smc_arg'
        ((smu)->funcs->read_smc_arg? (smu)->funcs->read_smc_arg((smu),
(arg)) : 0)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1550:30: note:
uninitialized use occurs here
                smu->default_power_limit = asic_default_power_limit;
                                           ^~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1534:4: note:
remove the '?:' if its condition is always true
                        smu_read_smc_arg(smu, &asic_default_power_limit);
                        ^
drivers/gpu/drm/amd/amdgpu/../powerplay/inc/amdgpu_smu.h:588:3:
note:
expanded from macro 'smu_read_smc_arg'
        ((smu)->funcs->read_smc_arg? (smu)->funcs->read_smc_arg((smu),
(arg)) : 0)
         ^
drivers/gpu/drm/amd/amdgpu/../powerplay/navi10_ppt.c:1517:35: note:
initialize the variable 'asic_default_power_limit' to silence this warning
        uint32_t asic_default_power_limit;
                                         ^
                                          = 0

1 warning generated.

As the code is currently written, if read_smc_arg were ever NULL, arg would fail to be initialized but the code would continue executing as normal because the return value would just be zero.

There are a few different possible solutions to resolve this class of warnings which have appeared in these drivers before:

1. Assume the function pointer will never be NULL and eliminate the wrapper macros.

2. Have the wrapper macros initialize arg when the function pointer is NULL.

3. Have the wrapper macros return an error code instead of 0 when the function pointer is NULL so that the callsites can properly bail out before arg can be used.

4. Initialize arg at the top of its function.

Number four is the path of least resistance right now as every other change will be driver wide so do that here. I only make the comment now as food for thought.

Fixes b4af964e75c4 ("drm/amd/powerplay: make power limit retrieval as

asic specific")

---
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 2 +-
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -1
index 215f7173fca8..b92eded7374f 100644
@@ -1326,7 +1326,7 @@ static int arcturus_get_power_limit(struct
 smu_context *smu,
                                   bool asic_default)
 {
      PPTable_t *pptable = smu->smu_table.driver_pptable;
-     uint32_t asic_default_power_limit;
+     uint32_t asic_default_power_limit = 0;
      int ret = 0;
      int power_src;
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -1
index 106352a4fb82..d844bc8411aa 100644
@@ -1514,7 +1514,7 @@ static int navi10_get_power_limit(struct
 smu_context *smu,
                                   bool asic_default)
 {
      PPTable_t *pptable = smu->smu_table.driver_pptable;
-     uint32_t asic_default_power_limit;
+     uint32_t asic_default_power_limit = 0;
      int ret = 0;
      int power_src;
Quoted 7 lines
Quoted 2 lines

--
2.23.0.rc1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx