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

[xen staging] earlycpio: lib-ify earlycpio.c



commit f6cd299be9d344e94e914e2a7f522bcfb40204a6
Author:     Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
AuthorDate: Wed Jan 21 16:47:55 2026 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Thu Jan 22 19:42:36 2026 +0000

    earlycpio: lib-ify earlycpio.c
    
    It's only used for microcode loading on x86. By lib-ifying it, it will be
    discarded automatically by the linker when CONFIG_MICROCODE_LOADING=n.
    
    Update the path in exclude-list.json, as the code is still not clean.
    
    Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
    Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 docs/misra/exclude-list.json |   8 +--
 xen/common/Makefile          |   2 +-
 xen/common/earlycpio.c       | 145 -------------------------------------------
 xen/lib/Makefile             |   1 +
 xen/lib/earlycpio.c          | 145 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 151 insertions(+), 150 deletions(-)

diff --git a/docs/misra/exclude-list.json b/docs/misra/exclude-list.json
index 388397dd3b..2b874dfd3b 100644
--- a/docs/misra/exclude-list.json
+++ b/docs/misra/exclude-list.json
@@ -121,10 +121,6 @@
             "rel_path": "common/bunzip2.c",
             "comment": "Imported from Linux, ignore for now"
         },
-        {
-            "rel_path": "common/earlycpio.c",
-            "comment": "Imported from Linux, ignore for now"
-        },
         {
             "rel_path": "common/gzip/*",
             "comment": "Imported from Linux, ignore for now"
@@ -225,6 +221,10 @@
             "rel_path": "include/xen/decompress.h",
             "comment": "Imported from Linux, ignore for now"
         },
+        {
+            "rel_path": "lib/earlycpio.c",
+            "comment": "Imported from Linux, ignore for now"
+        },
         {
             "rel_path": "lib/find-next-bit.c",
             "comment": "Imported from Linux, ignore for now"
diff --git a/xen/common/Makefile b/xen/common/Makefile
index 92c97d641e..4fc0c15088 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -65,7 +65,7 @@ obj-y += wait.o
 obj-bin-y += warning.init.o
 obj-y += xmalloc_tlsf.o
 
-obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo 
unlz4 unzstd earlycpio,$(n).init.o)
+obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo 
unlz4 unzstd,$(n).init.o)
 
 obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o memory.o multicall.o 
xlat.o)
 
diff --git a/xen/common/earlycpio.c b/xen/common/earlycpio.c
deleted file mode 100644
index 6c76307c25..0000000000
--- a/xen/common/earlycpio.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/* ----------------------------------------------------------------------- *
- *
- *   Copyright 2012 Intel Corporation; author H. Peter Anvin
- *
- *   This file is part of the Linux kernel, and is made available
- *   under the terms of the GNU General Public License version 2, as
- *   published by the Free Software Foundation.
- *
- *   This program is distributed in the hope it will be useful, but
- *   WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *   General Public License for more details.
- *
- * ----------------------------------------------------------------------- */
-
-/*
- * earlycpio.c
- *
- * Find a specific cpio member; must precede any compressed content.
- * This is used to locate data items in the initramfs used by the
- * kernel itself during early boot (before the main initramfs is
- * decompressed.)  It is the responsibility of the initramfs creator
- * to ensure that these items are uncompressed at the head of the
- * blob.  Depending on the boot loader or package tool that may be a
- * separate file or part of the same file.
- */
-
-#include <xen/init.h>
-#include <xen/lib.h>
-#include <xen/string.h>
-#include <xen/earlycpio.h>
-
-#define ALIGN(x, a) ((x + (a) - 1) & ~((a) - 1))
-#define PTR_ALIGN(p, a)         ((typeof(p))ALIGN((unsigned long)(p), (a)))
-
-enum cpio_fields {
-       C_MAGIC,
-       C_INO,
-       C_MODE,
-       C_UID,
-       C_GID,
-       C_NLINK,
-       C_MTIME,
-       C_FILESIZE,
-       C_MAJ,
-       C_MIN,
-       C_RMAJ,
-       C_RMIN,
-       C_NAMESIZE,
-       C_CHKSUM,
-       C_NFIELDS
-};
-
-/**
- * cpio_data find_cpio_data - Search for files in an uncompressed cpio
- * @path:       The directory to search for, including a slash at the end
- * @data:       Pointer to the the cpio archive or a header inside
- * @len:        Remaining length of the cpio based on data pointer
- *
- * @return:     struct cpio_data containing the address, length and
- *              filename (with the directory path cut off) of the found file.
- *              If you search for a filename and not for files in a directory,
- *              pass the absolute path of the filename in the cpio and make 
sure
- *              the match returned an empty filename string.
- */
-
-struct cpio_data __init find_cpio_data(const char *path, void *data, size_t 
len)
-{
-       const size_t cpio_header_len = 8*C_NFIELDS - 2;
-       struct cpio_data cd = { NULL, 0, "" };
-       const char *p, *dptr, *nptr;
-       unsigned int ch[C_NFIELDS], *chp, v;
-       unsigned char c, x;
-       size_t mypathsize = strlen(path);
-       int i, j;
-
-       p = data;
-
-       while (len > cpio_header_len) {
-               if (!*p) {
-                       /* All cpio headers need to be 4-byte aligned */
-                       p += 4;
-                       len -= 4;
-                       continue;
-               }
-
-               j = 6;          /* The magic field is only 6 characters */
-               chp = ch;
-               for (i = C_NFIELDS; i; i--) {
-                       v = 0;
-                       while (j--) {
-                               v <<= 4;
-                               c = *p++;
-
-                               x = c - '0';
-                               if (x < 10) {
-                                       v += x;
-                                       continue;
-                               }
-
-                               x = (c | 0x20) - 'a';
-                               if (x < 6) {
-                                       v += x + 10;
-                                       continue;
-                               }
-
-                               goto quit; /* Invalid hexadecimal */
-                       }
-                       *chp++ = v;
-                       j = 8;  /* All other fields are 8 characters */
-               }
-
-               if ((ch[C_MAGIC] - 0x070701) > 1)
-                       goto quit; /* Invalid magic */
-
-               len -= cpio_header_len;
-
-               dptr = PTR_ALIGN(p + ch[C_NAMESIZE], 4);
-               nptr = PTR_ALIGN(dptr + ch[C_FILESIZE], 4);
-
-               if (nptr > p + len || dptr < p || nptr < dptr)
-                       goto quit; /* Buffer overrun */
-
-               if ((ch[C_MODE] & 0170000) == 0100000 &&
-                   ch[C_NAMESIZE] >= mypathsize &&
-                   !memcmp(p, path, mypathsize)) {
-                       if (ch[C_NAMESIZE] - mypathsize >= MAX_CPIO_FILE_NAME) {
-                               printk(
-                               "File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",
-                               p, MAX_CPIO_FILE_NAME);
-                       }
-                       strlcpy(cd.name, p + mypathsize, MAX_CPIO_FILE_NAME);
-
-                       cd.data = (void *)dptr;
-                       cd.size = ch[C_FILESIZE];
-                       return cd; /* Found it! */
-               }
-               len -= (nptr - p);
-               p = nptr;
-       }
-
-quit:
-       return cd;
-}
-
diff --git a/xen/lib/Makefile b/xen/lib/Makefile
index efca830d92..3b0137902c 100644
--- a/xen/lib/Makefile
+++ b/xen/lib/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/
 lib-y += bsearch.o
 lib-y += ctors.o
 lib-y += ctype.o
+lib-y += earlycpio.init.o
 lib-y += find-next-bit.o
 lib-y += generic-ffsl.o
 lib-y += generic-flsl.o
diff --git a/xen/lib/earlycpio.c b/xen/lib/earlycpio.c
new file mode 100644
index 0000000000..6c76307c25
--- /dev/null
+++ b/xen/lib/earlycpio.c
@@ -0,0 +1,145 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2012 Intel Corporation; author H. Peter Anvin
+ *
+ *   This file is part of the Linux kernel, and is made available
+ *   under the terms of the GNU General Public License version 2, as
+ *   published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   General Public License for more details.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * earlycpio.c
+ *
+ * Find a specific cpio member; must precede any compressed content.
+ * This is used to locate data items in the initramfs used by the
+ * kernel itself during early boot (before the main initramfs is
+ * decompressed.)  It is the responsibility of the initramfs creator
+ * to ensure that these items are uncompressed at the head of the
+ * blob.  Depending on the boot loader or package tool that may be a
+ * separate file or part of the same file.
+ */
+
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/string.h>
+#include <xen/earlycpio.h>
+
+#define ALIGN(x, a) ((x + (a) - 1) & ~((a) - 1))
+#define PTR_ALIGN(p, a)         ((typeof(p))ALIGN((unsigned long)(p), (a)))
+
+enum cpio_fields {
+       C_MAGIC,
+       C_INO,
+       C_MODE,
+       C_UID,
+       C_GID,
+       C_NLINK,
+       C_MTIME,
+       C_FILESIZE,
+       C_MAJ,
+       C_MIN,
+       C_RMAJ,
+       C_RMIN,
+       C_NAMESIZE,
+       C_CHKSUM,
+       C_NFIELDS
+};
+
+/**
+ * cpio_data find_cpio_data - Search for files in an uncompressed cpio
+ * @path:       The directory to search for, including a slash at the end
+ * @data:       Pointer to the the cpio archive or a header inside
+ * @len:        Remaining length of the cpio based on data pointer
+ *
+ * @return:     struct cpio_data containing the address, length and
+ *              filename (with the directory path cut off) of the found file.
+ *              If you search for a filename and not for files in a directory,
+ *              pass the absolute path of the filename in the cpio and make 
sure
+ *              the match returned an empty filename string.
+ */
+
+struct cpio_data __init find_cpio_data(const char *path, void *data, size_t 
len)
+{
+       const size_t cpio_header_len = 8*C_NFIELDS - 2;
+       struct cpio_data cd = { NULL, 0, "" };
+       const char *p, *dptr, *nptr;
+       unsigned int ch[C_NFIELDS], *chp, v;
+       unsigned char c, x;
+       size_t mypathsize = strlen(path);
+       int i, j;
+
+       p = data;
+
+       while (len > cpio_header_len) {
+               if (!*p) {
+                       /* All cpio headers need to be 4-byte aligned */
+                       p += 4;
+                       len -= 4;
+                       continue;
+               }
+
+               j = 6;          /* The magic field is only 6 characters */
+               chp = ch;
+               for (i = C_NFIELDS; i; i--) {
+                       v = 0;
+                       while (j--) {
+                               v <<= 4;
+                               c = *p++;
+
+                               x = c - '0';
+                               if (x < 10) {
+                                       v += x;
+                                       continue;
+                               }
+
+                               x = (c | 0x20) - 'a';
+                               if (x < 6) {
+                                       v += x + 10;
+                                       continue;
+                               }
+
+                               goto quit; /* Invalid hexadecimal */
+                       }
+                       *chp++ = v;
+                       j = 8;  /* All other fields are 8 characters */
+               }
+
+               if ((ch[C_MAGIC] - 0x070701) > 1)
+                       goto quit; /* Invalid magic */
+
+               len -= cpio_header_len;
+
+               dptr = PTR_ALIGN(p + ch[C_NAMESIZE], 4);
+               nptr = PTR_ALIGN(dptr + ch[C_FILESIZE], 4);
+
+               if (nptr > p + len || dptr < p || nptr < dptr)
+                       goto quit; /* Buffer overrun */
+
+               if ((ch[C_MODE] & 0170000) == 0100000 &&
+                   ch[C_NAMESIZE] >= mypathsize &&
+                   !memcmp(p, path, mypathsize)) {
+                       if (ch[C_NAMESIZE] - mypathsize >= MAX_CPIO_FILE_NAME) {
+                               printk(
+                               "File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",
+                               p, MAX_CPIO_FILE_NAME);
+                       }
+                       strlcpy(cd.name, p + mypathsize, MAX_CPIO_FILE_NAME);
+
+                       cd.data = (void *)dptr;
+                       cd.size = ch[C_FILESIZE];
+                       return cd; /* Found it! */
+               }
+               len -= (nptr - p);
+               p = nptr;
+       }
+
+quit:
+       return cd;
+}
+
--
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®.