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

MIPS: Fix inline asm input/output type mismatch in checksum.h used with Clang

Fix the following build error when make M=samples/bpf used with Clang:

CLANG-bpf samples/bpf/sockex2_kern.o
In file included from samples/bpf/sockex2_kern.c:7:
In file included from ./include/uapi/linux/if_tunnel.h:7:
In file included from ./include/linux/ip.h:16:
In file included from ./include/linux/skbuff.h:28:
In file included from ./include/net/checksum.h:22:
./arch/mips/include/asm/checksum.h:161:9: error: unsupported inline asm: input with type 'unsigned long' matching output with type '__wsum' (aka 'unsigned int')
: "0" ((__force unsigned long)daddr),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

This is a known issue on MIPS [1], the changed code can be compiled
successfully by both GCC and Clang.

[1] https://lore.kernel.org/linux-mips/CAG_fn=W0JHf8QyUX==+rQMp8PoULHrsQCa9Htffws31ga8k-iw@mail.gmail.com/

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Tiezhu Yang and committed by
Thomas Bogendoerfer
198688ed e6a52b8f

+4 -2
+4 -2
arch/mips/include/asm/checksum.h
··· 130 130 __u32 len, __u8 proto, 131 131 __wsum sum) 132 132 { 133 + unsigned long tmp = (__force unsigned long)sum; 134 + 133 135 __asm__( 134 136 " .set push # csum_tcpudp_nofold\n" 135 137 " .set noat \n" ··· 159 157 " addu %0, $1 \n" 160 158 #endif 161 159 " .set pop" 162 - : "=r" (sum) 160 + : "=r" (tmp) 163 161 : "0" ((__force unsigned long)daddr), 164 162 "r" ((__force unsigned long)saddr), 165 163 #ifdef __MIPSEL__ ··· 169 167 #endif 170 168 "r" ((__force unsigned long)sum)); 171 169 172 - return sum; 170 + return (__force __wsum)tmp; 173 171 } 174 172 #define csum_tcpudp_nofold csum_tcpudp_nofold 175 173