Re: [PATCH 2/2] of: fix side effect in macro expansion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 29, 2020 at 08:40:40AM +0200, Ahmad Fatoum wrote:
> 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.

I'm not sure if the reasoning is correct. That would mean that
of_read_number() doesn't work on ARM, but I can assure it actually does.

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
> ---
>  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);

That said, the implementation looks way better with this patch.

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



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux