Skip to contentSkip to conversation

power: supply: bq256xx: drop always-true inner condition

PATCH Applied Anas Khan 2 participants 2 messages Jul 2 – Jul 20 Power supply

lore
Share & tools
lore

Anas Khan

author
#0 lore raw

PATCH 1/1 power: supply: bq256xx: drop always-true inner condition

In bq256xx_array_parse() the inner "if (val < array[i])" repeats the second half of the enclosing "if (val > array[i - 1] && val < array[i])", so it is always true and the "else return i" arm is dead code. The function performs a round-down table lookup, so returning i - 1 for a value that falls strictly between two entries is the intended result. Collapse the redundant branch into a single "return i - 1;"; no functional change.

---
 drivers/power/supply/bq256xx_charger.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/power/supply/bq256xx_charger.c +2 -6
index 5a6634fde837..e5042582da16 100644
@@ -347,12 +347,8 @@ static int bq256xx_array_parse(int array_size, int val, const int array[])
 		if (val == array[i])
 			return i;
 
-		if (val > array[i - 1] && val < array[i]) {
-			if (val < array[i])
-				return i - 1;
-			else
-				return i;
-		}
+		if (val > array[i - 1] && val < array[i])
+			return i - 1;
 	}
 	return -EINVAL;
 }
Signature · 1 line
2.54.0
#1 lore raw
Quoted 9 lines · Anas Khan

In bq256xx_array_parse() the inner "if (val < array[i])" repeats the second half of the enclosing "if (val > array[i - 1] && val < array[i])", so it is always true and the "else return i" arm is dead code. The function performs a round-down table lookup, so returning i - 1 for a value that falls strictly between two entries is the intended result. Collapse the redundant branch into a single "return i - 1;"; no functional change.

[...]

Applied, thanks!

[1/1] power: supply: bq256xx: drop always-true inner condition

      commit: c41f57bb3b65fe0b2f5f556752dc03ac66b8c5db

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>