Skip to content

Commit 7c08461

Browse files
committed
m68k: remove broken strcmp implementation
The m68 hand-written assembler version of strcmp() has always been broken: it returns the difference between the first non-matching byte done as a 8-bit subtraction. That is _almost_ right, but is broken for the overflow case. The strcmp() function should indeed return the sign of the difference between the first byte that differs, but the subtraction needs to be done in a wider type than 'char'. Otherwise the ordering isn't actually stable. This went unnoticed for basically forever, because nobody ever cares about non-US-ASCII orderings in the kernel (in fact, most users only care about "exact match or not"), so overflows don't really happen in practice, even if it was very very wrong. But that mostly unnoticeable bug becomes very noticeable by the recent change to make 'char' be unsigned in the kernel across all architectures (commit 3bc753c: "kbuild: treat char as always unsigned"). Because the code not only did the subtraction in the wrong type width, it also used 'char' to then make the compiler expand the result from an 8-bit difference to the 'int' return value. So now with an unsigned char that incorrect arithmetic width was then not even sign-expanded, and always returned just a positive integer. We could re-instate the old broken code by just turning the 'char' into 'signed char' as has been done elsewhere where people depended on the signedness of 'char', but since the whole function was broken to begin with, and we have a non-broken default fallback implementation, let's just remove this broken function entirely. Reported-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Cc: Jason Donenfeld <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Rasmus Villemoes <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 609d3bc commit 7c08461

File tree

1 file changed

+0
-20
lines changed

1 file changed

+0
-20
lines changed

arch/m68k/include/asm/string.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,6 @@ static inline char *strncpy(char *dest, const char *src, size_t n)
3838
return xdest;
3939
}
4040

41-
#ifndef CONFIG_COLDFIRE
42-
#define __HAVE_ARCH_STRCMP
43-
static inline int strcmp(const char *cs, const char *ct)
44-
{
45-
char res;
46-
47-
asm ("\n"
48-
"1: move.b (%0)+,%2\n" /* get *cs */
49-
" cmp.b (%1)+,%2\n" /* compare a byte */
50-
" jne 2f\n" /* not equal, break out */
51-
" tst.b %2\n" /* at end of cs? */
52-
" jne 1b\n" /* no, keep going */
53-
" jra 3f\n" /* strings are equal */
54-
"2: sub.b -(%1),%2\n" /* *cs - *ct */
55-
"3:"
56-
: "+a" (cs), "+a" (ct), "=d" (res));
57-
return res;
58-
}
59-
#endif /* CONFIG_COLDFIRE */
60-
6141
#define __HAVE_ARCH_MEMMOVE
6242
extern void *memmove(void *, const void *, __kernel_size_t);
6343

0 commit comments

Comments
 (0)