Skip to contentSkip to conversation

of: refactor of_read_number for clarity

PATCH Applied Ahmad Fatoum 2 participants 2 messages Apr 29, 2020 – May 4, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 of: refactor of_read_number for clarity

While the code is correct, less sophisticated static analyzers (and users operating them..) trip over it, because they don't see that the be32_to_cpu argument is evaluated multiple times only if it's constant. Moving the side effect out:

- Lets us avoid the false positive
- Aligns us with what Linux does
- Makes the code IMO a bit clearer

Do so.

---
v2 -> v3:
fix full stop at end of commit subject (Roland)
v1 -> v2:
fix inaccurate commit message (Sascha)

---
 include/of.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/of.h +2 -2
index 85d55f9b57dc..08bbeaf4d21b 100644
@@ -79,8 +79,8 @@ struct fdt_header *of_get_fixed_tree(struct device_node *node);
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
 	u64 r = 0;
-	while (size--)
-		r = (r << 32) | be32_to_cpu(*(cell++));
+	for (; size--; cell++)
+		r = (r << 32) | be32_to_cpu(*cell);
 	return r;
 }
 
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#1 lore raw
Quoted 5 lines · Ahmad Fatoum

While the code is correct, less sophisticated static analyzers (and users operating them..) trip over it, because they don't see that the be32_to_cpu argument is evaluated multiple times only if it's constant. Moving the side effect out:

Quoted 7 lines

- Lets us avoid the false positive
- Aligns us with what Linux does
- Makes the code IMO a bit clearer

Do so.

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox