Re: [tip:x86/cpu] x86/cpu: Strip any /proc/ cpuinfo model name field whitespace

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);

--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux