[U-Boot] [PATCH v2 09/33] x86: Replace fill_processor_name() with cpu_get_name()

Bin Meng bmeng.cn at gmail.com
Tue Nov 11 10:42:03 CET 2014


On Tue, Nov 11, 2014 at 9:00 AM, Simon Glass <sjg at chromium.org> wrote:
> This implementation has a 'cpu' prefix and returns a pointer to the string,
> avoiding the need for copying.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
>
> ---
>
> Changes in v2:
> - Add new patch to replace fill_processor_name() with cpu_get_name()
>
>  arch/x86/cpu/cpu.c         | 22 ++++++++++------------
>  arch/x86/include/asm/cpu.h | 11 ++++++++---
>  2 files changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
> index a4e639d..0d75941 100644
> --- a/arch/x86/cpu/cpu.c
> +++ b/arch/x86/cpu/cpu.c
> @@ -491,14 +491,14 @@ const char *cpu_vendor_name(int vendor)
>         return name;
>  }
>
> -void fill_processor_name(char *processor_name)
> +char *cpu_get_name(char *name)
>  {
> +       unsigned int *name_as_ints = (unsigned int *)name;
>         struct cpuid_result regs;
> -       char temp_processor_name[49];
> -       char *processor_name_start;
> -       unsigned int *name_as_ints = (unsigned int *)temp_processor_name;
> +       char *ptr;
>         int i;
>
> +       /* This bit adds up to 48 bytes */
>         for (i = 0; i < 3; i++) {
>                 regs = cpuid(0x80000002 + i);
>                 name_as_ints[i * 4 + 0] = regs.eax;
> @@ -506,19 +506,17 @@ void fill_processor_name(char *processor_name)
>                 name_as_ints[i * 4 + 2] = regs.ecx;
>                 name_as_ints[i * 4 + 3] = regs.edx;
>         }
> -
> -       temp_processor_name[48] = 0;
> +       name[CPU_MAX_NAME_LEN - 1] = '\0';
>
>         /* Skip leading spaces. */
> -       processor_name_start = temp_processor_name;
> -       while (*processor_name_start == ' ')
> -               processor_name_start++;
> +       ptr = name;
> +       while (*ptr == ' ')
> +               ptr++;
>
> -       memset(processor_name, 0, 49);
> -       strcpy(processor_name, processor_name_start);
> +       return ptr;
>  }
>
> -int print_cpuinfo(void)
> +int default_print_cpuinfo(void)
>  {
>         printf("CPU: %s, vendor %s, device %xh\n",
>                cpu_has_64bit() ? "x86_64" : "x86",
> diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
> index 89b748b..c839291 100644
> --- a/arch/x86/include/asm/cpu.h
> +++ b/arch/x86/include/asm/cpu.h
> @@ -179,12 +179,17 @@ int cpu_has_64bit(void);
>   */
>  const char *cpu_vendor_name(int vendor);
>
> +#define CPU_MAX_NAME_LEN       49
> +
>  /**
> - * fill_processor_name() - Get processor name
> + * cpu_get_name() - Get the name of the current cpu
>   *
> - * @processor_name:    Address to hold the processor name string
> + * @name: Place to put name, which must be CPU_MAX_NAME_LEN bytes including
> + * @return pointer to name, which will likely be a few bytes after the start
> + * of @name
> + * \0 terminator
>   */
> -void fill_processor_name(char *processor_name);
> +char *cpu_get_name(char *name);
>
>  /**
>   * cpu_call64() - Jump to a 64-bit Linux kernel (internal function)
> --

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>


More information about the U-Boot mailing list