aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Borntraeger <borntraeger@de.ibm.com>2016-08-04 04:24:30 -0400
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2016-08-08 09:41:31 -0400
commite2efc424549eb66d227dfe6d073d1789a24bc698 (patch)
tree1c95439c4a7f1696fbcaf1a753ccb68e62137b47
parent134a24cd895c5d138d639a0741ad27e389cd4562 (diff)
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: db7f5eef3dc0 ("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>
-rw-r--r--arch/s390/lib/string.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/arch/s390/lib/string.c b/arch/s390/lib/string.c
index e390bbb16443..48352bffbc92 100644
--- a/arch/s390/lib/string.c
+++ b/arch/s390/lib/string.c
@@ -237,11 +237,10 @@ char * strrchr(const char * s, int c)
237EXPORT_SYMBOL(strrchr); 237EXPORT_SYMBOL(strrchr);
238 238
239static inline int clcle(const char *s1, unsigned long l1, 239static inline int clcle(const char *s1, unsigned long l1,
240 const char *s2, unsigned long l2, 240 const char *s2, unsigned long l2)
241 int *diff)
242{ 241{
243 register unsigned long r2 asm("2") = (unsigned long) s1; 242 register unsigned long r2 asm("2") = (unsigned long) s1;
244 register unsigned long r3 asm("3") = (unsigned long) l2; 243 register unsigned long r3 asm("3") = (unsigned long) l1;
245 register unsigned long r4 asm("4") = (unsigned long) s2; 244 register unsigned long r4 asm("4") = (unsigned long) s2;
246 register unsigned long r5 asm("5") = (unsigned long) l2; 245 register unsigned long r5 asm("5") = (unsigned long) l2;
247 int cc; 246 int cc;
@@ -252,7 +251,6 @@ static inline int clcle(const char *s1, unsigned long l1,
252 " srl %0,28" 251 " srl %0,28"
253 : "=&d" (cc), "+a" (r2), "+a" (r3), 252 : "=&d" (cc), "+a" (r2), "+a" (r3),
254 "+a" (r4), "+a" (r5) : : "cc"); 253 "+a" (r4), "+a" (r5) : : "cc");
255 *diff = *(char *)r2 - *(char *)r4;
256 return cc; 254 return cc;
257} 255}
258 256
@@ -270,9 +268,9 @@ char * strstr(const char * s1,const char * s2)
270 return (char *) s1; 268 return (char *) s1;
271 l1 = __strend(s1) - s1; 269 l1 = __strend(s1) - s1;
272 while (l1-- >= l2) { 270 while (l1-- >= l2) {
273 int cc, dummy; 271 int cc;
274 272
275 cc = clcle(s1, l1, s2, l2, &dummy); 273 cc = clcle(s1, l2, s2, l2);
276 if (!cc) 274 if (!cc)
277 return (char *) s1; 275 return (char *) s1;
278 s1++; 276 s1++;
@@ -313,11 +311,11 @@ EXPORT_SYMBOL(memchr);
313 */ 311 */
314int memcmp(const void *cs, const void *ct, size_t n) 312int memcmp(const void *cs, const void *ct, size_t n)
315{ 313{
316 int ret, diff; 314 int ret;
317 315
318 ret = clcle(cs, n, ct, n, &diff); 316 ret = clcle(cs, n, ct, n);
319 if (ret) 317 if (ret)
320 ret = diff; 318 ret = ret == 1 ? -1 : 1;
321 return ret; 319 return ret;
322} 320}
323EXPORT_SYMBOL(memcmp); 321EXPORT_SYMBOL(memcmp);