mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v3] of: refactor of_read_number for clarity
@ 2020-04-29 10:58 Ahmad Fatoum
  2020-05-04  5:44 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2020-04-29 10: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>
---
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(-)

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] 2+ messages in thread

* Re: [PATCH v3] of: refactor of_read_number for clarity
  2020-04-29 10:58 [PATCH v3] of: refactor of_read_number for clarity Ahmad Fatoum
@ 2020-05-04  5:44 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-05-04  5:44 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Wed, Apr 29, 2020 at 12:58:04PM +0200, Ahmad Fatoum wrote:
> 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>

Applied, thanks

Sascha

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-05-04  5:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29 10:58 [PATCH v3] of: refactor of_read_number for clarity Ahmad Fatoum
2020-05-04  5:44 ` Sascha Hauer

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