[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] common: move safe_copy_string_from_guest() to lib/



commit cdc0feca657328ac173a560d19a0dcc400c8f8ef
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Thu Apr 2 08:49:58 2026 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Apr 2 08:49:58 2026 +0200

    common: move safe_copy_string_from_guest() to lib/
    
    This function is unreachable on x86 when XSM_FLASK=n, and it is another
    good candidate to put in an archive.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
---
 xen/common/Makefile    |  1 -
 xen/common/guestcopy.c | 30 ------------------------------
 xen/lib/Makefile       |  1 +
 xen/lib/guest-strcpy.c | 30 ++++++++++++++++++++++++++++++
 4 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/xen/common/Makefile b/xen/common/Makefile
index dac8b711cd..6018e25614 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -16,7 +16,6 @@ obj-y += event_2l.o
 obj-y += event_channel.o
 obj-$(CONFIG_EVTCHN_FIFO) += event_fifo.o
 obj-$(CONFIG_GRANT_TABLE) += grant_table.o
-obj-y += guestcopy.o
 obj-y += gzip/
 obj-$(CONFIG_HYPFS) += hypfs.o
 obj-$(CONFIG_IOREQ_SERVER) += ioreq.o
diff --git a/xen/common/guestcopy.c b/xen/common/guestcopy.c
deleted file mode 100644
index 6d38eefedd..0000000000
--- a/xen/common/guestcopy.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <xen/lib.h>
-#include <xen/guest_access.h>
-#include <xen/err.h>
-
-/*
- * The function copies a string from the guest and adds a NUL to
- * make sure the string is correctly terminated.
- */
-char *safe_copy_string_from_guest(XEN_GUEST_HANDLE(char) u_buf,
-                                  size_t size, size_t max_size)
-{
-    char *tmp;
-
-    if ( size > max_size )
-        return ERR_PTR(-ENOBUFS);
-
-    /* Add an extra +1 to append \0 */
-    tmp = xmalloc_array(char, size + 1);
-    if ( !tmp )
-        return ERR_PTR(-ENOMEM);
-
-    if ( copy_from_guest(tmp, u_buf, size) )
-    {
-        xfree(tmp);
-        return ERR_PTR(-EFAULT);
-    }
-    tmp[size] = '\0';
-
-    return tmp;
-}
diff --git a/xen/lib/Makefile b/xen/lib/Makefile
index dcef1610b2..933f6d96fb 100644
--- a/xen/lib/Makefile
+++ b/xen/lib/Makefile
@@ -6,6 +6,7 @@ lib-y += find-next-bit.o
 lib-y += generic-ffsl.o
 lib-y += generic-flsl.o
 lib-y += generic-hweightl.o
+lib-y += guest-strcpy.o
 lib-y += list-sort.o
 lib-y += memchr.o
 lib-y += memchr_inv.o
diff --git a/xen/lib/guest-strcpy.c b/xen/lib/guest-strcpy.c
new file mode 100644
index 0000000000..6d38eefedd
--- /dev/null
+++ b/xen/lib/guest-strcpy.c
@@ -0,0 +1,30 @@
+#include <xen/lib.h>
+#include <xen/guest_access.h>
+#include <xen/err.h>
+
+/*
+ * The function copies a string from the guest and adds a NUL to
+ * make sure the string is correctly terminated.
+ */
+char *safe_copy_string_from_guest(XEN_GUEST_HANDLE(char) u_buf,
+                                  size_t size, size_t max_size)
+{
+    char *tmp;
+
+    if ( size > max_size )
+        return ERR_PTR(-ENOBUFS);
+
+    /* Add an extra +1 to append \0 */
+    tmp = xmalloc_array(char, size + 1);
+    if ( !tmp )
+        return ERR_PTR(-ENOMEM);
+
+    if ( copy_from_guest(tmp, u_buf, size) )
+    {
+        xfree(tmp);
+        return ERR_PTR(-EFAULT);
+    }
+    tmp[size] = '\0';
+
+    return tmp;
+}
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.