From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Devin Moore <devinmoore@google.com>
Subject: [PATCH v3 6/6] bootconfig: Share the checksum function with tools
Date: Wed, 2 Jun 2021 15:25:17 +0900 [thread overview]
Message-ID: <162261511700.255316.7845877611885532107.stgit@devnote2> (raw)
In-Reply-To: <162261506232.255316.12147562546699211199.stgit@devnote2>
Move the checksum calculation function into the header for sharing it
with tools/bootconfig.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
tools/bootconfig/main.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h
index e49043ac77c9..6bdd94cff4e2 100644
--- a/include/linux/bootconfig.h
+++ b/include/linux/bootconfig.h
@@ -16,6 +16,26 @@
#define BOOTCONFIG_ALIGN (1 << BOOTCONFIG_ALIGN_SHIFT)
#define BOOTCONFIG_ALIGN_MASK (BOOTCONFIG_ALIGN - 1)
+/**
+ * xbc_calc_checksum() - Calculate checksum of bootconfig
+ * @data: Bootconfig data.
+ * @size: The size of the bootconfig data.
+ *
+ * Calculate the checksum value of the bootconfig data.
+ * The checksum will be used with the BOOTCONFIG_MAGIC and the size for
+ * embedding the bootconfig in the initrd image.
+ */
+static inline __init u32 xbc_calc_checksum(void *data, u32 size)
+{
+ unsigned char *p = data;
+ u32 ret = 0;
+
+ while (size--)
+ ret += *p++;
+
+ return ret;
+}
+
/* XBC tree node */
struct xbc_node {
u16 next;
diff --git a/init/main.c b/init/main.c
index eb01e121d2f1..43914e675421 100644
--- a/init/main.c
+++ b/init/main.c
@@ -386,16 +386,6 @@ static char * __init xbc_make_cmdline(const char *key)
return new_cmdline;
}
-static u32 boot_config_checksum(unsigned char *p, u32 size)
-{
- u32 ret = 0;
-
- while (size--)
- ret += *p++;
-
- return ret;
-}
-
static int __init bootconfig_params(char *param, char *val,
const char *unused, void *arg)
{
@@ -439,7 +429,7 @@ static void __init setup_boot_config(void)
return;
}
- if (boot_config_checksum((unsigned char *)data, size) != csum) {
+ if (xbc_calc_checksum(data, size) != csum) {
pr_err("bootconfig checksum failed\n");
return;
}
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 5441b254eb7c..9e2c6eedacb1 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -128,17 +128,6 @@ static void xbc_show_list(void)
}
}
-/* Simple real checksum */
-static int checksum(unsigned char *buf, int len)
-{
- int i, sum = 0;
-
- for (i = 0; i < len; i++)
- sum += buf[i];
-
- return sum;
-}
-
#define PAGE_SIZE 4096
static int load_xbc_fd(int fd, char **buf, int size)
@@ -234,7 +223,7 @@ static int load_xbc_from_initrd(int fd, char **buf)
return ret;
/* Wrong Checksum */
- rcsum = checksum((unsigned char *)*buf, size);
+ rcsum = xbc_calc_checksum(*buf, size);
if (csum != rcsum) {
pr_err("checksum error: %d != %d\n", csum, rcsum);
return -EINVAL;
@@ -383,7 +372,7 @@ static int apply_xbc(const char *path, const char *xbc_path)
return ret;
}
size = strlen(buf) + 1;
- csum = checksum((unsigned char *)buf, size);
+ csum = xbc_calc_checksum(buf, size);
/* Backup the bootconfig data */
data = calloc(size + BOOTCONFIG_ALIGN +
next prev parent reply other threads:[~2021-06-02 6:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-02 6:24 [PATCH v3 0/6] bootconfig: Add mixed subkeys and value under the same key Masami Hiramatsu
2021-06-02 6:24 ` [PATCH v3 1/6] tools/bootconfig: Fix a build error accroding to undefined fallthrough Masami Hiramatsu
2021-06-02 6:24 ` [PATCH v3 2/6] bootconfig: Change array value to use child node Masami Hiramatsu
2021-06-02 6:24 ` [PATCH v3 3/6] bootconfig: Support mixing a value and subkeys under a key Masami Hiramatsu
2021-06-02 6:24 ` [PATCH v3 4/6] tools/bootconfig: Support mixed value and subkey test cases Masami Hiramatsu
2021-06-02 6:25 ` [PATCH v3 5/6] docs: bootconfig: Update for mixing value and subkeys Masami Hiramatsu
2021-06-02 6:25 ` Masami Hiramatsu [this message]
2021-06-02 7:45 ` [PATCH v3 0/6] bootconfig: Add mixed subkeys and value under the same key Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=162261511700.255316.7845877611885532107.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=devinmoore@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox