Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755782AbbFBInX (ORCPT ); Tue, 2 Jun 2015 04:43:23 -0400 Received: from terminus.zytor.com ([198.137.202.10]:46099 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755334AbbFBInP (ORCPT ); Tue, 2 Jun 2015 04:43:15 -0400 Date: Tue, 2 Jun 2015 01:42:34 -0700 From: tip-bot for Borislav Petkov Message-ID: Cc: mingo@kernel.org, dvlasenk@redhat.com, brgerst@gmail.com, fenghua.yu@intel.com, tglx@linutronix.de, bp@suse.de, peterz@infradead.org, luto@amacapital.net, linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com, torvalds@linux-foundation.org, hpa@zytor.com, imammedo@redhat.com Reply-To: imammedo@redhat.com, torvalds@linux-foundation.org, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, bp@suse.de, linux-kernel@vger.kernel.org, luto@amacapital.net, mingo@kernel.org, dvlasenk@redhat.com, tglx@linutronix.de, fenghua.yu@intel.com, brgerst@gmail.com In-Reply-To: <1432050210-32036-1-git-send-email-prarit@redhat.com> References: <1432050210-32036-1-git-send-email-prarit@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cpu] x86/cpu: Trim model ID whitespace Git-Commit-ID: ee098e1aed67715f0ce4651813d0c33ab3a56e0b X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3724 Lines: 112 Commit-ID: ee098e1aed67715f0ce4651813d0c33ab3a56e0b Gitweb: http://git.kernel.org/tip/ee098e1aed67715f0ce4651813d0c33ab3a56e0b Author: Borislav Petkov AuthorDate: Mon, 1 Jun 2015 12:06:57 +0200 Committer: Ingo Molnar CommitDate: Tue, 2 Jun 2015 10:38:11 +0200 x86/cpu: Trim model ID whitespace We did try trimming whitespace surrounding the 'model name' field in /proc/cpuinfo since reportedly some userspace uses it in string comparisons and there were discrepancies: [thetango@prarit ~]# grep "^model name" /proc/cpuinfo | uniq -c | sed 's/\ /_/g' ______1_model_name :_AMD_Opteron(TM)_Processor_6272 _____63_model_name :_AMD_Opteron(TM)_Processor_6272_________________ However, there were issues with overlapping buffers, string sizes and non-byte-sized copies in the previous proposed solutions; see Link tags below for the whole farce. So, instead of diddling with this more, let's simply extend what was there originally with trimming any present trailing whitespace. Final result is really simple and obvious. Testing with the most insane model IDs qemu can generate, looks good: .model_id = " My funny model ID CPU ", ______4_model_name :_My_funny_model_ID_CPU .model_id = "My funny model ID CPU ", ______4_model_name :_My_funny_model_ID_CPU .model_id = " My funny model ID CPU", ______4_model_name :_My_funny_model_ID_CPU .model_id = " ", ______4_model_name :__ .model_id = "", ______4_model_name :_15/02 Signed-off-by: Borislav Petkov Cc: Andy Lutomirski Cc: Brian Gerst Cc: Dave Hansen Cc: Denys Vlasenko Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Igor Mammedov Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1432050210-32036-1-git-send-email-prarit@redhat.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/cpu/common.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 41a8e9c..351197c 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -419,6 +420,7 @@ static const struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {}; static void get_model_name(struct cpuinfo_x86 *c) { unsigned int *v; + char *p, *q, *s; if (c->extended_cpuid_level < 0x80000004) return; @@ -429,11 +431,21 @@ static void get_model_name(struct cpuinfo_x86 *c) cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]); c->x86_model_id[48] = 0; - /* - * Remove leading whitespace on Intel processors and trailing - * whitespace on AMD processors. - */ - memmove(c->x86_model_id, strim(c->x86_model_id), 48); + /* Trim whitespace */ + p = q = s = &c->x86_model_id[0]; + + while (*p == ' ') + p++; + + while (*p) { + /* Note the last non-whitespace index */ + if (!isspace(*p)) + s = q; + + *q++ = *p++; + } + + *(s + 1) = '\0'; } void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/