lkml.org 
[lkml]   [2015]   [May]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [tip:x86/cpu] x86/cpu: Strip any /proc/ cpuinfo model name field whitespace
From
Date
On Wed, 2015-05-27 at 07:16 -0700, tip-bot for Prarit Bhargava wrote:

> x86/cpu: Strip any /proc/cpuinfo model name field whitespace
[]
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> @@ -431,18 +430,10 @@ static void get_model_name(struct cpuinfo_x86 *c)
> c->x86_model_id[48] = 0;
>
> /*
> - * Intel chips right-justify this string for some dumb reason;
> - * undo that brain damage:
> + * Remove leading whitespace on Intel processors and trailing
> + * whitespace on AMD processors.
> */
> - p = q = &c->x86_model_id[0];
> - while (*p == ' ')
> - p++;
> - if (p != q) {
> - while (*p)
> - *q++ = *p++;
> - while (q <= &c->x86_model_id[48])
> - *q++ = '\0'; /* Zero-pad the rest */
> - }
> + memmove(c->x86_model_id, strim(c->x86_model_id), 48);

This code can memmove from beyond the x86_model_id field.

If the id was a single right justified char, to avoid overrunning
the field, it'd be safer moving only the actual string and
terminating 0 though this code is sub-optimal:

memmove(c->x86_model_id, strim(c->x86_model_id),
strlen(strim(c->x86_model_id) + 1);

Maybe:
char *model = strim(c->x86_model_id);
memmove(c->x86_model_id, model, strlen(model) + 1);



\
 
 \ /
  Last update: 2015-05-27 19:41    [W:0.118 / U:0.676 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site