Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

m68k: Implement ndelay() as an inline function to force type checking/casting

ndelay() is supposed to take an unsigned long, but if you define
ndelay() as a macro and the caller pass an unsigned long long instead
of an unsigned long, the unsigned long long to unsigned long cast is
not done and we end up with an "undefined reference to `__udivdi3'"
error at link time.

Fix that by making ndelay() an inline function and then defining dummy
ndelay() macro that redirects to the ndelay() function (it's how most
archs do to implement ndelay()).

Fixes: c8ee038bd148 ("m68k: Implement ndelay() based on the existing udelay() logic")
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
[geert: Remove comment now it is no longer a macro]
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

authored by

Boris Brezillon and committed by
Geert Uytterhoeven
d8441ba8 d49cbe73

+8 -3
+8 -3
arch/m68k/include/asm/delay.h
··· 49 49 * The simpler m68k and ColdFire processors do not have a 32*32->64 50 50 * multiply instruction. So we need to handle them a little differently. 51 51 * We use a bit of shifting and a single 32*32->32 multiply to get close. 52 - * This is a macro so that the const version can factor out the first 53 - * multiply and shift. 54 52 */ 55 53 #define HZSCALE (268435456 / (1000000 / HZ)) 56 54 ··· 113 115 */ 114 116 #define HZSCALE (268435456 / (1000000 / HZ)) 115 117 116 - #define ndelay(n) __delay(DIV_ROUND_UP((n) * ((((HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6), 1000)) 118 + static inline void ndelay(unsigned long nsec) 119 + { 120 + __delay(DIV_ROUND_UP(nsec * 121 + ((((HZSCALE) >> 11) * 122 + (loops_per_jiffy >> 11)) >> 6), 123 + 1000)); 124 + } 125 + #define ndelay(n) ndelay(n) 117 126 118 127 #endif /* defined(_M68K_DELAY_H) */