mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] of: fix side effect in macro expansion
Date: Wed, 29 Apr 2020 08:40:40 +0200	[thread overview]
Message-ID: <20200429064040.5845-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20200429064040.5845-1-a.fatoum@pengutronix.de>

On little endian platforms that don't define __arch_swab32p, be32_to_cpu
ultimately expands to an expression that evaluates its argument multiple
times. Because of the increment, this is wrong (and UB because of
unsequenced modification).
Hoist the side effect out of the macro argument.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 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.26.2


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

  reply	other threads:[~2020-04-29  6:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29  6:40 [PATCH 1/2] scripts: imd: fix uninitialized variable read Ahmad Fatoum
2020-04-29  6:40 ` Ahmad Fatoum [this message]
2020-04-29  8:00   ` [PATCH 2/2] of: fix side effect in macro expansion Sascha Hauer
2020-04-29  8:26     ` Ahmad Fatoum
2020-04-29  8:41       ` Sascha Hauer
2020-04-29  8:47         ` Ahmad Fatoum
2020-04-29  7:38 ` [PATCH 1/2] scripts: imd: fix uninitialized variable read Sascha Hauer
2020-05-04  7:38   ` Steffen Trumtrar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200429064040.5845-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox