Skip to contentSkip to conversation

iio: adc: MCP3564: fix warn: unsigned '__x' is never less than zero.

PATCH In review [email protected] 2 participants 2 messages Oct 13, 2023 – Oct 14, 2023

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH v2 1/1 iio: adc: MCP3564: fix warn: unsigned '__x' is never less than zero.

From: Marius Cristea <[email protected]>

The patch 33ec3e5fc1ea: "iio: adc: adding support for MCP3564 ADC" leads to the following Smatch static checker warning:

smatch warnings:
drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls() warn: unsigned '__x' is never less than zero.

vim +/__x +1105 drivers/iio/adc/mcp3564.c

1094
1095 static void mcp3564_fill_scale_tbls(struct mcp3564_state *adc) 1096 {
.....
1103 for (i = 0; i < MCP3564_MAX_PGA; i++) {

   1104                  ref = adc->vref_mv;
 > 1105                  tmp1 = shift_right((u64)ref * NANO, pow);
   1106                  div_u64_rem(tmp1, NANO, &tmp0);

1107
.....
1113 }

Fixes 33ec3e5fc1ea (iio: adc: adding support for MCP3564 ADC)
---
 drivers/iio/adc/mcp3564.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/mcp3564.c +1 -1
index 9ede1a5d5d7b..e3f1de5fcc5a 100644
@@ -1102,7 +1102,7 @@ static void mcp3564_fill_scale_tbls(struct mcp3564_state *adc)
 
 	for (i = 0; i < MCP3564_MAX_PGA; i++) {
 		ref = adc->vref_mv;
-		tmp1 = shift_right((u64)ref * NANO, pow);
+		tmp1 = ((u64)ref * NANO) >> pow;
 		div_u64_rem(tmp1, NANO, &tmp0);
 
 		tmp1 = tmp1 * mcp3564_hwgain_frac[(2 * i) + 1];

base-commit: 5e99f692d4e32e3250ab18d511894ca797407aec

Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 22 lines · On Fri, 13 Oct 2023 16:23:33 +0300 <[email protected]> wrote:

From: Marius Cristea <[email protected]>

The patch 33ec3e5fc1ea: "iio: adc: adding support for MCP3564 ADC" leads to the following Smatch static checker warning:

smatch warnings:
drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls() warn: unsigned '__x' is never less than zero.

vim +/__x +1105 drivers/iio/adc/mcp3564.c

   1094
   1095  static void mcp3564_fill_scale_tbls(struct mcp3564_state *adc)
   1096  {
   .....
   1103          for (i = 0; i < MCP3564_MAX_PGA; i++) {
   1104                  ref = adc->vref_mv;
Quoted 1 line

1105 tmp1 = shift_right((u64)ref * NANO, pow);

   1106                  div_u64_rem(tmp1, NANO, &tmp0);
   1107
   .....
   1113  }
Quoted 4 lines
Fixes 33ec3e5fc1ea (iio: adc: adding support for MCP3564 ADC)

Applied to the togreg branch of iio.git and pushed out as testing briefly for 0-day to take a look.

Thanks,

Jonathan

Quoted 19 lines
---
 drivers/iio/adc/mcp3564.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/mcp3564.c +1 -1
index 9ede1a5d5d7b..e3f1de5fcc5a 100644
@@ -1102,7 +1102,7 @@ static void mcp3564_fill_scale_tbls(struct mcp3564_state *adc)
 
 	for (i = 0; i < MCP3564_MAX_PGA; i++) {
 		ref = adc->vref_mv;
-		tmp1 = shift_right((u64)ref * NANO, pow);
+		tmp1 = ((u64)ref * NANO) >> pow;
 		div_u64_rem(tmp1, NANO, &tmp0);
 
 		tmp1 = tmp1 * mcp3564_hwgain_frac[(2 * i) + 1];

base-commit: 5e99f692d4e32e3250ab18d511894ca797407aec