Merge tag 'mm-stable-2023-02-20-13-37' of git://git.kernel.org/pub/scm/linux/kernel...
[sfrench/cifs-2.6.git] / mm / util.c
index b56c92fb910fc6d82d18fd6d8f30f4c8f45cb65b..b8ed9dbc7fd55b4dea595e64718315e939fd9bb3 100644 (file)
--- a/mm/util.c
+++ b/mm/util.c
@@ -120,7 +120,8 @@ EXPORT_SYMBOL(kstrndup);
  * @len: memory region length
  * @gfp: GFP mask to use
  *
- * Return: newly allocated copy of @src or %NULL in case of error
+ * Return: newly allocated copy of @src or %NULL in case of error,
+ * result is physically contiguous. Use kfree() to free.
  */
 void *kmemdup(const void *src, size_t len, gfp_t gfp)
 {
@@ -133,6 +134,27 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
 }
 EXPORT_SYMBOL(kmemdup);
 
+/**
+ * kvmemdup - duplicate region of memory
+ *
+ * @src: memory region to duplicate
+ * @len: memory region length
+ * @gfp: GFP mask to use
+ *
+ * Return: newly allocated copy of @src or %NULL in case of error,
+ * result may be not physically contiguous. Use kvfree() to free.
+ */
+void *kvmemdup(const void *src, size_t len, gfp_t gfp)
+{
+       void *p;
+
+       p = kvmalloc(len, gfp);
+       if (p)
+               memcpy(p, src, len);
+       return p;
+}
+EXPORT_SYMBOL(kvmemdup);
+
 /**
  * kmemdup_nul - Create a NUL-terminated string from unterminated data
  * @s: The data to stringify
@@ -945,7 +967,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
        if (percpu_counter_read_positive(&vm_committed_as) < allowed)
                return 0;
 error:
-       pr_warn_ratelimited("%s: pid: %d, comm: %s, no enough memory for the allocation\n",
+       pr_warn_ratelimited("%s: pid: %d, comm: %s, not enough memory for the allocation\n",
                            __func__, current->pid, current->comm);
        vm_unacct_memory(pages);