mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-23 18:07:03 +00:00
s390/lib: fix memcmp and strstr
if two string compare equal the clcle instruction will update the
string addresses to point _after_ the string. This might already
be on a different page, so we should not use these pointer to
calculate the difference as in that case the calculation of the
difference can cause oopses.
The return value of memcmp does not need the difference, we
can just reuse the condition code and return for CC=1 (All bytes
compared, first operand low) -1 and for CC=2 (All bytes compared,
first operand high) +1
strstr also does not need the diff.
While fixing this, make the common function clcle "correct on its
own" by using l1 instead of l2 for the first length. strstr will
call this with l2 for both strings.
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Fixes: db7f5eef3d
("s390/lib: use basic blocks for inline assemblies")
Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
parent
134a24cd89
commit
e2efc42454
@ -237,11 +237,10 @@ char * strrchr(const char * s, int c)
|
||||
EXPORT_SYMBOL(strrchr);
|
||||
|
||||
static inline int clcle(const char *s1, unsigned long l1,
|
||||
const char *s2, unsigned long l2,
|
||||
int *diff)
|
||||
const char *s2, unsigned long l2)
|
||||
{
|
||||
register unsigned long r2 asm("2") = (unsigned long) s1;
|
||||
register unsigned long r3 asm("3") = (unsigned long) l2;
|
||||
register unsigned long r3 asm("3") = (unsigned long) l1;
|
||||
register unsigned long r4 asm("4") = (unsigned long) s2;
|
||||
register unsigned long r5 asm("5") = (unsigned long) l2;
|
||||
int cc;
|
||||
@ -252,7 +251,6 @@ static inline int clcle(const char *s1, unsigned long l1,
|
||||
" srl %0,28"
|
||||
: "=&d" (cc), "+a" (r2), "+a" (r3),
|
||||
"+a" (r4), "+a" (r5) : : "cc");
|
||||
*diff = *(char *)r2 - *(char *)r4;
|
||||
return cc;
|
||||
}
|
||||
|
||||
@ -270,9 +268,9 @@ char * strstr(const char * s1,const char * s2)
|
||||
return (char *) s1;
|
||||
l1 = __strend(s1) - s1;
|
||||
while (l1-- >= l2) {
|
||||
int cc, dummy;
|
||||
int cc;
|
||||
|
||||
cc = clcle(s1, l1, s2, l2, &dummy);
|
||||
cc = clcle(s1, l2, s2, l2);
|
||||
if (!cc)
|
||||
return (char *) s1;
|
||||
s1++;
|
||||
@ -313,11 +311,11 @@ EXPORT_SYMBOL(memchr);
|
||||
*/
|
||||
int memcmp(const void *cs, const void *ct, size_t n)
|
||||
{
|
||||
int ret, diff;
|
||||
int ret;
|
||||
|
||||
ret = clcle(cs, n, ct, n, &diff);
|
||||
ret = clcle(cs, n, ct, n);
|
||||
if (ret)
|
||||
ret = diff;
|
||||
ret = ret == 1 ? -1 : 1;
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(memcmp);
|
||||
|
Loading…
Reference in New Issue
Block a user