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

Configure Feed

Select the types of activity you want to include in your feed.

tools/bootconfig: Cleanup bootconfig footer size calculations

There are many same pattern of 8 + BOOTCONFIG_MAGIC_LEN for calculating
the size of bootconfig footer. Use BOOTCONFIG_FOOTER_SIZE macro to
clean up those magic numbers.

Link: https://lore.kernel.org/all/175211425693.2591046.16029516706923643510.stgit@mhiramat.tok.corp.google.com/

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

+11 -8
+11 -8
tools/bootconfig/main.c
··· 16 16 17 17 #define pr_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) 18 18 19 + /* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */ 20 + #define BOOTCONFIG_FOOTER_SIZE \ 21 + (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN) 22 + 19 23 static int xbc_show_value(struct xbc_node *node, bool semicolon) 20 24 { 21 25 const char *val, *eol; ··· 189 185 if (ret < 0) 190 186 return -errno; 191 187 192 - if (stat.st_size < 8 + BOOTCONFIG_MAGIC_LEN) 188 + if (stat.st_size < BOOTCONFIG_FOOTER_SIZE) 193 189 return 0; 194 190 195 191 if (lseek(fd, -BOOTCONFIG_MAGIC_LEN, SEEK_END) < 0) ··· 202 198 if (memcmp(magic, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN) != 0) 203 199 return 0; 204 200 205 - if (lseek(fd, -(8 + BOOTCONFIG_MAGIC_LEN), SEEK_END) < 0) 201 + if (lseek(fd, -BOOTCONFIG_FOOTER_SIZE, SEEK_END) < 0) 206 202 return pr_errno("Failed to lseek for size", -errno); 207 203 208 204 if (read(fd, &size, sizeof(uint32_t)) < 0) ··· 214 210 csum = le32toh(csum); 215 211 216 212 /* Wrong size error */ 217 - if (stat.st_size < size + 8 + BOOTCONFIG_MAGIC_LEN) { 213 + if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) { 218 214 pr_err("bootconfig size is too big\n"); 219 215 return -E2BIG; 220 216 } 221 217 222 - if (lseek(fd, stat.st_size - (size + 8 + BOOTCONFIG_MAGIC_LEN), 218 + if (lseek(fd, stat.st_size - (size + BOOTCONFIG_FOOTER_SIZE), 223 219 SEEK_SET) < 0) 224 220 return pr_errno("Failed to lseek", -errno); 225 221 ··· 350 346 ret = fstat(fd, &stat); 351 347 if (!ret) 352 348 ret = ftruncate(fd, stat.st_size 353 - - size - 8 - BOOTCONFIG_MAGIC_LEN); 349 + - size - BOOTCONFIG_FOOTER_SIZE); 354 350 if (ret) 355 351 ret = -errno; 356 352 } /* Ignore if there is no boot config in initrd */ ··· 380 376 csum = xbc_calc_checksum(buf, size); 381 377 382 378 /* Backup the bootconfig data */ 383 - data = calloc(size + BOOTCONFIG_ALIGN + 384 - sizeof(uint32_t) + sizeof(uint32_t) + BOOTCONFIG_MAGIC_LEN, 1); 379 + data = calloc(size + BOOTCONFIG_ALIGN + BOOTCONFIG_FOOTER_SIZE, 1); 385 380 if (!data) 386 381 return -ENOMEM; 387 382 memcpy(data, buf, size); ··· 428 425 } 429 426 430 427 /* To align up the total size to BOOTCONFIG_ALIGN, get padding size */ 431 - total_size = stat.st_size + size + sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN; 428 + total_size = stat.st_size + size + BOOTCONFIG_FOOTER_SIZE; 432 429 pad = ((total_size + BOOTCONFIG_ALIGN - 1) & (~BOOTCONFIG_ALIGN_MASK)) - total_size; 433 430 size += pad; 434 431