linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: avs: qcom-cpr: Avoid clang -Wsometimes-uninitialized in cpr_scale
@ 2020-01-30  1:41 Nathan Chancellor
  2020-01-31  0:02 ` Kevin Hilman
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2020-01-30  1:41 UTC (permalink / raw)
  To: Niklas Cassel
  Cc: Andy Gross, Bjorn Andersson, Kevin Hilman, Nishanth Menon,
	Rafael J. Wysocki, linux-pm, linux-arm-msm, linux-kernel,
	clang-built-linux, Nathan Chancellor

Clang warns (trimmed for brevity):

../drivers/power/avs/qcom-cpr.c:570:13: warning: variable 'reg_mask' is
used uninitialized whenever 'if' condition is false
[-Wsometimes-uninitialized]

../drivers/power/avs/qcom-cpr.c:520:13: warning: variable 'new_uV' is
used uninitialized whenever 'if' condition is false
[-Wsometimes-uninitialized]

Due to the fact that Clang's static analysis happens before any
optimization passes are taken into account, it cannot see that both
branches in the if statement must be taken because dir cannot be
something other than UP or DOWN due to the check at the top of this
function. Change the else if condition to else to fix this false
positive.

Fixes: bf6910abf548 ("power: avs: Add support for CPR (Core Power Reduction)")
Link: https://github.com/ClangBuiltLinux/linux/issues/840
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 drivers/power/avs/qcom-cpr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/power/avs/qcom-cpr.c b/drivers/power/avs/qcom-cpr.c
index 9192fb747653..e8831e4aee05 100644
--- a/drivers/power/avs/qcom-cpr.c
+++ b/drivers/power/avs/qcom-cpr.c
@@ -517,7 +517,7 @@ static int cpr_scale(struct cpr_drv *drv, enum voltage_change_dir dir)
 		dev_dbg(drv->dev,
 			"UP: -> new_uV: %d last_uV: %d perf state: %u\n",
 			new_uV, last_uV, cpr_get_cur_perf_state(drv));
-	} else if (dir == DOWN) {
+	} else {
 		if (desc->clamp_timer_interval &&
 		    error_steps < desc->down_threshold) {
 			/*
@@ -567,7 +567,7 @@ static int cpr_scale(struct cpr_drv *drv, enum voltage_change_dir dir)
 		/* Disable auto nack down */
 		reg_mask = RBCPR_CTL_SW_AUTO_CONT_NACK_DN_EN;
 		val = 0;
-	} else if (dir == DOWN) {
+	} else {
 		/* Restore default threshold for UP */
 		reg_mask = RBCPR_CTL_UP_THRESHOLD_MASK;
 		reg_mask <<= RBCPR_CTL_UP_THRESHOLD_SHIFT;
-- 
2.25.0


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

* Re: [PATCH] power: avs: qcom-cpr: Avoid clang -Wsometimes-uninitialized in cpr_scale
  2020-01-30  1:41 [PATCH] power: avs: qcom-cpr: Avoid clang -Wsometimes-uninitialized in cpr_scale Nathan Chancellor
@ 2020-01-31  0:02 ` Kevin Hilman
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Hilman @ 2020-01-31  0:02 UTC (permalink / raw)
  To: Nathan Chancellor, Niklas Cassel
  Cc: Andy Gross, Bjorn Andersson, Kevin Hilman, Nishanth Menon,
	Rafael J. Wysocki, linux-pm, linux-arm-msm, linux-kernel,
	clang-built-linux, Nathan Chancellor

Nathan Chancellor <natechancellor@gmail.com> writes:

> Clang warns (trimmed for brevity):
>
> ../drivers/power/avs/qcom-cpr.c:570:13: warning: variable 'reg_mask' is
> used uninitialized whenever 'if' condition is false
> [-Wsometimes-uninitialized]
>
> ../drivers/power/avs/qcom-cpr.c:520:13: warning: variable 'new_uV' is
> used uninitialized whenever 'if' condition is false
> [-Wsometimes-uninitialized]
>
> Due to the fact that Clang's static analysis happens before any
> optimization passes are taken into account, it cannot see that both
> branches in the if statement must be taken because dir cannot be
> something other than UP or DOWN due to the check at the top of this
> function. Change the else if condition to else to fix this false
> positive.
>
> Fixes: bf6910abf548 ("power: avs: Add support for CPR (Core Power Reduction)")
> Link: https://github.com/ClangBuiltLinux/linux/issues/840
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Acked-by: Kevin Hilman <khilman@baylibre.com>

Rafael, feel free to queue directly.

Kevin

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

end of thread, other threads:[~2020-01-31  0:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-30  1:41 [PATCH] power: avs: qcom-cpr: Avoid clang -Wsometimes-uninitialized in cpr_scale Nathan Chancellor
2020-01-31  0:02 ` Kevin Hilman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).