mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] of: refactor of_read_number for clarity.
@ 2020-04-29  8:58 Ahmad Fatoum
  0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2020-04-29  8:58 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 include/of.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/of.h b/include/of.h
index 85d55f9b57dc..08bbeaf4d21b 100644
--- a/include/of.h
+++ b/include/of.h
@@ -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;
 }
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-29  8:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29  8:58 [PATCH v2] of: refactor of_read_number for clarity Ahmad Fatoum

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