Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [PATCH] cpufreq/amd-pstate: Avoid shadowing ret in amd_pstate_ut_check_driver()
@ 2025-05-12 21:28 Nathan Chancellor
  2025-05-13 16:14 ` Mario Limonciello
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2025-05-12 21:28 UTC (permalink / raw)
  To: Huang Rui, Gautham R. Shenoy, Mario Limonciello, Perry Yuan,
	Rafael J. Wysocki, Viresh Kumar, Swapnil Sapkal
  Cc: linux-pm, linux-kernel, llvm, kernel test robot,
	Nathan Chancellor

Clang warns (or errors with CONFIG_WERROR=y):

  drivers/cpufreq/amd-pstate-ut.c:262:6: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized]
    262 |         if (ret)
        |             ^~~

ret is declared at the top of the function and in the for loop so the
initialization of ret is local to the loop. Remove the declaration in
the for loop so that ret is always used initialized.

Fixes: d26d16438bc5 ("amd-pstate-ut: Reset amd-pstate driver mode after running selftests")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202505072226.g2QclhaR-lkp@intel.com/
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/cpufreq/amd-pstate-ut.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/amd-pstate-ut.c b/drivers/cpufreq/amd-pstate-ut.c
index 30835d0e4994..65f9d2bae2d3 100644
--- a/drivers/cpufreq/amd-pstate-ut.c
+++ b/drivers/cpufreq/amd-pstate-ut.c
@@ -246,7 +246,7 @@ static int amd_pstate_ut_check_driver(u32 index)
 	int ret;
 
 	for (mode1 = AMD_PSTATE_DISABLE; mode1 < AMD_PSTATE_MAX; mode1++) {
-		int ret = amd_pstate_set_mode(mode1);
+		ret = amd_pstate_set_mode(mode1);
 		if (ret)
 			return ret;
 		for (mode2 = AMD_PSTATE_DISABLE; mode2 < AMD_PSTATE_MAX; mode2++) {

---
base-commit: b01fc4eca73cbd7946181255a95dbe64ff83bc5f
change-id: 20250512-amd-pstate-ut-uninit-ret-46a23a195687

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cpufreq/amd-pstate: Avoid shadowing ret in amd_pstate_ut_check_driver()
  2025-05-12 21:28 [PATCH] cpufreq/amd-pstate: Avoid shadowing ret in amd_pstate_ut_check_driver() Nathan Chancellor
@ 2025-05-13 16:14 ` Mario Limonciello
  0 siblings, 0 replies; 2+ messages in thread
From: Mario Limonciello @ 2025-05-13 16:14 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: linux-pm, linux-kernel, llvm, kernel test robot, Huang Rui,
	Gautham R. Shenoy, Perry Yuan, Rafael J. Wysocki, Viresh Kumar,
	Swapnil Sapkal

On 5/12/2025 4:28 PM, Nathan Chancellor wrote:
> Clang warns (or errors with CONFIG_WERROR=y):
> 
>    drivers/cpufreq/amd-pstate-ut.c:262:6: error: variable 'ret' is uninitialized when used here [-Werror,-Wuninitialized]
>      262 |         if (ret)
>          |             ^~~
> 
> ret is declared at the top of the function and in the for loop so the
> initialization of ret is local to the loop. Remove the declaration in
> the for loop so that ret is always used initialized.
> 
> Fixes: d26d16438bc5 ("amd-pstate-ut: Reset amd-pstate driver mode after running selftests")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202505072226.g2QclhaR-lkp@intel.com/
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>   drivers/cpufreq/amd-pstate-ut.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate-ut.c b/drivers/cpufreq/amd-pstate-ut.c
> index 30835d0e4994..65f9d2bae2d3 100644
> --- a/drivers/cpufreq/amd-pstate-ut.c
> +++ b/drivers/cpufreq/amd-pstate-ut.c
> @@ -246,7 +246,7 @@ static int amd_pstate_ut_check_driver(u32 index)
>   	int ret;
>   
>   	for (mode1 = AMD_PSTATE_DISABLE; mode1 < AMD_PSTATE_MAX; mode1++) {
> -		int ret = amd_pstate_set_mode(mode1);
> +		ret = amd_pstate_set_mode(mode1);
>   		if (ret)
>   			return ret;
>   		for (mode2 = AMD_PSTATE_DISABLE; mode2 < AMD_PSTATE_MAX; mode2++) {
> 
> ---
> base-commit: b01fc4eca73cbd7946181255a95dbe64ff83bc5f
> change-id: 20250512-amd-pstate-ut-uninit-ret-46a23a195687
> 
> Best regards,

Much appreciated.

Acked-by: Mario Limonciello <mario.limonciello@amd.com>

Applied to superm1/bleeding-edge.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-13 16:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-12 21:28 [PATCH] cpufreq/amd-pstate: Avoid shadowing ret in amd_pstate_ut_check_driver() Nathan Chancellor
2025-05-13 16:14 ` Mario Limonciello

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox