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 10:26:27AM +0200, Ahmad Fatoum wrote:
> On 4/29/20 10:00 AM, Sascha Hauer wrote:
> > 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.
> 
> Typo, sorry. arch needs to define __arch_swab32 (no p at the end).
> 
> of_read_number -> be32_to_cpu -> __be32_to_cpu -> __swab32 -> __fswab32
> 
> then
> 
> static inline __attribute_const__ __u32 __fswab32(__u32 val)
> {
> #ifdef __arch_swab32
>         return __arch_swab32(val);
> #else
>         return ___constant_swab32(val);
> #endif
> }
> 
> where ___constant_swab32 is the macro that evaluates the argument
> multiple times.

__fswab32 is a function, for the caller it doesn't matter how often
___constant_swab32 evaluates its argument.

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