Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bootconfig: Share the checksum function with tools

Move the checksum calculation function into the header for sharing it
with tools/bootconfig.

Link: https://lkml.kernel.org/r/162262197470.264090.16325743685807878807.stgit@devnote2

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (VMware)
99f4f5d6 0ff2bb7d

+23 -24
+20
include/linux/bootconfig.h
··· 16 16 #define BOOTCONFIG_ALIGN (1 << BOOTCONFIG_ALIGN_SHIFT) 17 17 #define BOOTCONFIG_ALIGN_MASK (BOOTCONFIG_ALIGN - 1) 18 18 19 + /** 20 + * xbc_calc_checksum() - Calculate checksum of bootconfig 21 + * @data: Bootconfig data. 22 + * @size: The size of the bootconfig data. 23 + * 24 + * Calculate the checksum value of the bootconfig data. 25 + * The checksum will be used with the BOOTCONFIG_MAGIC and the size for 26 + * embedding the bootconfig in the initrd image. 27 + */ 28 + static inline __init u32 xbc_calc_checksum(void *data, u32 size) 29 + { 30 + unsigned char *p = data; 31 + u32 ret = 0; 32 + 33 + while (size--) 34 + ret += *p++; 35 + 36 + return ret; 37 + } 38 + 19 39 /* XBC tree node */ 20 40 struct xbc_node { 21 41 u16 next;
+1 -11
init/main.c
··· 386 386 return new_cmdline; 387 387 } 388 388 389 - static u32 boot_config_checksum(unsigned char *p, u32 size) 390 - { 391 - u32 ret = 0; 392 - 393 - while (size--) 394 - ret += *p++; 395 - 396 - return ret; 397 - } 398 - 399 389 static int __init bootconfig_params(char *param, char *val, 400 390 const char *unused, void *arg) 401 391 { ··· 429 439 return; 430 440 } 431 441 432 - if (boot_config_checksum((unsigned char *)data, size) != csum) { 442 + if (xbc_calc_checksum(data, size) != csum) { 433 443 pr_err("bootconfig checksum failed\n"); 434 444 return; 435 445 }
+2 -13
tools/bootconfig/main.c
··· 126 126 } 127 127 } 128 128 129 - /* Simple real checksum */ 130 - static int checksum(unsigned char *buf, int len) 131 - { 132 - int i, sum = 0; 133 - 134 - for (i = 0; i < len; i++) 135 - sum += buf[i]; 136 - 137 - return sum; 138 - } 139 - 140 129 #define PAGE_SIZE 4096 141 130 142 131 static int load_xbc_fd(int fd, char **buf, int size) ··· 221 232 return ret; 222 233 223 234 /* Wrong Checksum */ 224 - rcsum = checksum((unsigned char *)*buf, size); 235 + rcsum = xbc_calc_checksum(*buf, size); 225 236 if (csum != rcsum) { 226 237 pr_err("checksum error: %d != %d\n", csum, rcsum); 227 238 return -EINVAL; ··· 370 381 return ret; 371 382 } 372 383 size = strlen(buf) + 1; 373 - csum = checksum((unsigned char *)buf, size); 384 + csum = xbc_calc_checksum(buf, size); 374 385 375 386 /* Backup the bootconfig data */ 376 387 data = calloc(size + BOOTCONFIG_ALIGN +