]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - lib/string.c
iov_iter: optimize page_copy_sane()
[mirror_ubuntu-bionic-kernel.git] / lib / string.c
index 5e8d410a93df5eb569e15815782be2027ec69d6e..288b827e95285e9c11e89cf4abe7ed9b1531d171 100644 (file)
@@ -865,6 +865,26 @@ __visible int memcmp(const void *cs, const void *ct, size_t count)
 EXPORT_SYMBOL(memcmp);
 #endif
 
+#ifndef __HAVE_ARCH_BCMP
+/**
+ * bcmp - returns 0 if and only if the buffers have identical contents.
+ * @a: pointer to first buffer.
+ * @b: pointer to second buffer.
+ * @len: size of buffers.
+ *
+ * The sign or magnitude of a non-zero return value has no particular
+ * meaning, and architectures may implement their own more efficient bcmp(). So
+ * while this particular implementation is a simple (tail) call to memcmp, do
+ * not rely on anything but whether the return value is zero or non-zero.
+ */
+#undef bcmp
+int bcmp(const void *a, const void *b, size_t len)
+{
+       return memcmp(a, b, len);
+}
+EXPORT_SYMBOL(bcmp);
+#endif
+
 #ifndef __HAVE_ARCH_MEMSCAN
 /**
  * memscan - Find a character in an area of memory.
@@ -1052,144 +1072,3 @@ void fortify_panic(const char *name)
        BUG();
 }
 EXPORT_SYMBOL(fortify_panic);
-
-#ifdef CONFIG_STRING_SELFTEST
-#include <linux/slab.h>
-#include <linux/module.h>
-
-static __init int memset16_selftest(void)
-{
-       unsigned i, j, k;
-       u16 v, *p;
-
-       p = kmalloc(256 * 2 * 2, GFP_KERNEL);
-       if (!p)
-               return -1;
-
-       for (i = 0; i < 256; i++) {
-               for (j = 0; j < 256; j++) {
-                       memset(p, 0xa1, 256 * 2 * sizeof(v));
-                       memset16(p + i, 0xb1b2, j);
-                       for (k = 0; k < 512; k++) {
-                               v = p[k];
-                               if (k < i) {
-                                       if (v != 0xa1a1)
-                                               goto fail;
-                               } else if (k < i + j) {
-                                       if (v != 0xb1b2)
-                                               goto fail;
-                               } else {
-                                       if (v != 0xa1a1)
-                                               goto fail;
-                               }
-                       }
-               }
-       }
-
-fail:
-       kfree(p);
-       if (i < 256)
-               return (i << 24) | (j << 16) | k;
-       return 0;
-}
-
-static __init int memset32_selftest(void)
-{
-       unsigned i, j, k;
-       u32 v, *p;
-
-       p = kmalloc(256 * 2 * 4, GFP_KERNEL);
-       if (!p)
-               return -1;
-
-       for (i = 0; i < 256; i++) {
-               for (j = 0; j < 256; j++) {
-                       memset(p, 0xa1, 256 * 2 * sizeof(v));
-                       memset32(p + i, 0xb1b2b3b4, j);
-                       for (k = 0; k < 512; k++) {
-                               v = p[k];
-                               if (k < i) {
-                                       if (v != 0xa1a1a1a1)
-                                               goto fail;
-                               } else if (k < i + j) {
-                                       if (v != 0xb1b2b3b4)
-                                               goto fail;
-                               } else {
-                                       if (v != 0xa1a1a1a1)
-                                               goto fail;
-                               }
-                       }
-               }
-       }
-
-fail:
-       kfree(p);
-       if (i < 256)
-               return (i << 24) | (j << 16) | k;
-       return 0;
-}
-
-static __init int memset64_selftest(void)
-{
-       unsigned i, j, k;
-       u64 v, *p;
-
-       p = kmalloc(256 * 2 * 8, GFP_KERNEL);
-       if (!p)
-               return -1;
-
-       for (i = 0; i < 256; i++) {
-               for (j = 0; j < 256; j++) {
-                       memset(p, 0xa1, 256 * 2 * sizeof(v));
-                       memset64(p + i, 0xb1b2b3b4b5b6b7b8ULL, j);
-                       for (k = 0; k < 512; k++) {
-                               v = p[k];
-                               if (k < i) {
-                                       if (v != 0xa1a1a1a1a1a1a1a1ULL)
-                                               goto fail;
-                               } else if (k < i + j) {
-                                       if (v != 0xb1b2b3b4b5b6b7b8ULL)
-                                               goto fail;
-                               } else {
-                                       if (v != 0xa1a1a1a1a1a1a1a1ULL)
-                                               goto fail;
-                               }
-                       }
-               }
-       }
-
-fail:
-       kfree(p);
-       if (i < 256)
-               return (i << 24) | (j << 16) | k;
-       return 0;
-}
-
-static __init int string_selftest_init(void)
-{
-       int test, subtest;
-
-       test = 1;
-       subtest = memset16_selftest();
-       if (subtest)
-               goto fail;
-
-       test = 2;
-       subtest = memset32_selftest();
-       if (subtest)
-               goto fail;
-
-       test = 3;
-       subtest = memset64_selftest();
-       if (subtest)
-               goto fail;
-
-       pr_info("String selftests succeeded\n");
-       return 0;
-fail:
-       pr_crit("String selftest failure %d.%08x\n", test, subtest);
-       return 0;
-}
-
-module_init(string_selftest_init);
-#endif /* CONFIG_STRING_SELFTEST */