OSDN Git Service

lib/test_string.c: avoid masking memset16/32/64 failures
authorPeter Rosin <peda@axentia.se>
Tue, 16 Jul 2019 23:27:18 +0000 (16:27 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 17 Jul 2019 02:23:22 +0000 (19:23 -0700)
If a memsetXX implementation is completely broken and fails in the first
iteration, when i, j, and k are all zero, the failure is masked as zero
is returned.  Failing in the first iteration is perhaps the most likely
failure, so this makes the tests pretty much useless.  Avoid the
situation by always setting a random unused bit in the result on
failure.

Link: http://lkml.kernel.org/r/20190506124634.6807-3-peda@axentia.se
Fixes: 03270c13c5ff ("lib/string.c: add testcases for memset16/32/64")
Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/test_string.c

index bf8def0..b5117ae 100644 (file)
@@ -36,7 +36,7 @@ static __init int memset16_selftest(void)
 fail:
        kfree(p);
        if (i < 256)
-               return (i << 24) | (j << 16) | k;
+               return (i << 24) | (j << 16) | k | 0x8000;
        return 0;
 }
 
@@ -72,7 +72,7 @@ static __init int memset32_selftest(void)
 fail:
        kfree(p);
        if (i < 256)
-               return (i << 24) | (j << 16) | k;
+               return (i << 24) | (j << 16) | k | 0x8000;
        return 0;
 }
 
@@ -108,7 +108,7 @@ static __init int memset64_selftest(void)
 fail:
        kfree(p);
        if (i < 256)
-               return (i << 24) | (j << 16) | k;
+               return (i << 24) | (j << 16) | k | 0x8000;
        return 0;
 }