On 4/29/20 10:41 AM, Sascha Hauer wrote: > 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. Oh. Looks like a false positive. cppcheck thinks we could reach __constant_swab32, which is a macro, but it's only reachable for constant expressions, which are always side-effect free. Please dismiss. I'll send a v2 with corrected reasoning in the commit message. Cheers Ahmad > > 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