From c3950959f42857d3de5bca01fe3f4a85f31545c5 Mon Sep 17 00:00:00 2001 From: Tiezhu Yang Date: Fri, 15 Jul 2022 18:05:14 +0800 Subject: kexec-tools: Remove duplicate ultoa() definitions and redefine it There exist duplicate ultoa() definitions in many archs, remove them, and also redefine ultoa() in kexec/kexec.h to make it more readable. Signed-off-by: Tiezhu Yang Signed-off-by: Simon Horman --- kexec/arch/i386/crashdump-x86.c | 19 ------------------- kexec/arch/mips/crashdump-mips.c | 19 ------------------- kexec/arch/mips/kexec-elf-mips.c | 19 ------------------- kexec/arch/ppc64/crashdump-ppc64.c | 19 ------------------- kexec/arch/sh/crashdump-sh.c | 19 ------------------- kexec/kexec.h | 16 ++++++++++++++++ 6 files changed, 16 insertions(+), 95 deletions(-) diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c index 9826f6d1..df1f24cb 100644 --- a/kexec/arch/i386/crashdump-x86.c +++ b/kexec/arch/i386/crashdump-x86.c @@ -601,25 +601,6 @@ static int delete_memmap(struct memory_range *memmap_p, int *nr_memmap, return 0; } -/* Converts unsigned long to ascii string. */ -static void ultoa(unsigned long i, char *str) -{ - int j = 0, k; - char tmp; - - do { - str[j++] = i % 10 + '0'; - } while ((i /=10) > 0); - str[j] = '\0'; - - /* Reverse the string. */ - for (j = 0, k = strlen(str) - 1; j < k; j++, k--) { - tmp = str[k]; - str[k] = str[j]; - str[j] = tmp; - } -} - static void cmdline_add_memmap_internal(char *cmdline, unsigned long startk, unsigned long endk, int type) { diff --git a/kexec/arch/mips/crashdump-mips.c b/kexec/arch/mips/crashdump-mips.c index d9f45158..00f43358 100644 --- a/kexec/arch/mips/crashdump-mips.c +++ b/kexec/arch/mips/crashdump-mips.c @@ -224,25 +224,6 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges) return 0; } -/* Converts unsigned long to ascii string. */ -static void ultoa(unsigned long i, char *str) -{ - int j = 0, k; - char tmp; - - do { - str[j++] = i % 10 + '0'; - } while ((i /= 10) > 0); - str[j] = '\0'; - - /* Reverse the string. */ - for (j = 0, k = strlen(str) - 1; j < k; j++, k--) { - tmp = str[k]; - str[k] = str[j]; - str[j] = tmp; - } -} - /* Adds the appropriate mem= options to command line, indicating the * memory region the new kernel can use to boot into. */ static int cmdline_add_mem(char *cmdline, unsigned long addr, diff --git a/kexec/arch/mips/kexec-elf-mips.c b/kexec/arch/mips/kexec-elf-mips.c index 31f4c478..230d806f 100644 --- a/kexec/arch/mips/kexec-elf-mips.c +++ b/kexec/arch/mips/kexec-elf-mips.c @@ -40,25 +40,6 @@ static const int probe_debug = 0; #define CMDLINE_PREFIX "kexec " static char cmdline_buf[COMMAND_LINE_SIZE] = CMDLINE_PREFIX; -/* Converts unsigned long to ascii string. */ -static void ultoa(unsigned long i, char *str) -{ - int j = 0, k; - char tmp; - - do { - str[j++] = i % 10 + '0'; - } while ((i /= 10) > 0); - str[j] = '\0'; - - /* Reverse the string. */ - for (j = 0, k = strlen(str) - 1; j < k; j++, k--) { - tmp = str[k]; - str[k] = str[j]; - str[j] = tmp; - } -} - /* Adds initrd parameters to command line. */ static int cmdline_add_initrd(char *cmdline, unsigned long addr, char *new_para) { diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c index 91f95210..6d47898a 100644 --- a/kexec/arch/ppc64/crashdump-ppc64.c +++ b/kexec/arch/ppc64/crashdump-ppc64.c @@ -436,25 +436,6 @@ err: return -1; } -/* Converts unsigned long to ascii string. */ -static void ultoa(uint64_t i, char *str) -{ - int j = 0, k; - char tmp; - - do { - str[j++] = i % 10 + '0'; - } while ((i /=10) > 0); - str[j] = '\0'; - - /* Reverse the string. */ - for (j = 0, k = strlen(str) - 1; j < k; j++, k--) { - tmp = str[k]; - str[k] = str[j]; - str[j] = tmp; - } -} - static int add_cmdline_param(char *cmdline, uint64_t addr, char *cmdstr, char *byte) { diff --git a/kexec/arch/sh/crashdump-sh.c b/kexec/arch/sh/crashdump-sh.c index aa25dea3..36e9aaf2 100644 --- a/kexec/arch/sh/crashdump-sh.c +++ b/kexec/arch/sh/crashdump-sh.c @@ -90,25 +90,6 @@ static struct crash_elf_info elf_info32 = page_offset: PAGE_OFFSET, }; -/* Converts unsigned long to ascii string. */ -static void ultoa(unsigned long i, char *str) -{ - int j = 0, k; - char tmp; - - do { - str[j++] = i % 10 + '0'; - } while ((i /=10) > 0); - str[j] = '\0'; - - /* Reverse the string. */ - for (j = 0, k = strlen(str) - 1; j < k; j++, k--) { - tmp = str[k]; - str[k] = str[j]; - str[j] = tmp; - } -} - static int add_cmdline_param(char *cmdline, uint64_t addr, char *cmdstr, char *byte) { diff --git a/kexec/kexec.h b/kexec/kexec.h index 0f97a974..8a056447 100644 --- a/kexec/kexec.h +++ b/kexec/kexec.h @@ -329,4 +329,20 @@ int xen_kexec_status(uint64_t kexec_flags); extern unsigned long long get_kernel_sym(const char *text); +/* Converts unsigned long to ascii string. */ +static inline void ultoa(unsigned long val, char *str) +{ + char buf[36]; + int len = 0, pos = 0; + + do { + buf[len++] = val % 10; + val /= 10; + } while (val); + + while (len) + str[pos++] = buf[--len] + '0'; + str[pos] = 0; +} + #endif /* KEXEC_H */ -- cgit 1.2.3-korg