From patchwork Mon May 23 22:27:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 810332 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4NMTWPM016583 for ; Mon, 23 May 2011 22:29:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757834Ab1EWW3c (ORCPT ); Mon, 23 May 2011 18:29:32 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:42966 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757825Ab1EWW3b (ORCPT ); Mon, 23 May 2011 18:29:31 -0400 Received: from imap1.linux-foundation.org (imap1.linux-foundation.org [140.211.169.55]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p4NMRv8S023305 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 23 May 2011 15:27:57 -0700 Received: from localhost.localdomain (localhost [127.0.0.1]) by imap1.linux-foundation.org (8.13.5.20060308/8.13.5/Debian-3ubuntu1.1) with ESMTP id p4NMRuPp016019; Mon, 23 May 2011 15:27:56 -0700 Message-Id: <201105232227.p4NMRuPp016019@imap1.linux-foundation.org> Subject: [patch 2/2] drivers/firmware/dmi_scan.c: make dmi_name_in_vendors more focused To: jbarnes@virtuousgeek.org Cc: linux-pci@vger.kernel.org, akpm@linux-foundation.org, khali@linux-fr.org, andi@firstfloor.org From: akpm@linux-foundation.org Date: Mon, 23 May 2011 15:27:56 -0700 MIME-Version: 1.0 X-Spam-Status: No, hits=-103.482 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, USER_IN_WHITELIST X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.13 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 23 May 2011 22:29:32 +0000 (UTC) From: Jean Delvare The current implementation of dmi_name_in_vendors() is an invitation to lazy coding and false positives [1]. Searching for a string in 8 know what you're looking for, so you should know where to look. strstr isn't fast, especially when it fails, so we should avoid calling it when it just can't succeed. Looking at the current users of the function, it seems clear to me that they are looking for a system or board vendor name, so let's limit dmi_name_in_vendors to these two DMI fields. This much better matches the function name, BTW. [1] We currently have code looking for short names in DMI data, such as "IBM", "ASUS" or "Acer". I let you guess what will happen the day other vendors ship products named, for example, "SCHREIBMEISTER", "PEGASUS" or "Acerola". Signed-off-by: Jean Delvare Cc: Andi Kleen Cc: Jesse Barnes Signed-off-by: Andrew Morton --- drivers/firmware/dmi_scan.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff -puN drivers/firmware/dmi_scan.c~drivers-firmware-dmi_scanc-make-dmi_name_in_vendors-more-focused drivers/firmware/dmi_scan.c --- a/drivers/firmware/dmi_scan.c~drivers-firmware-dmi_scanc-make-dmi_name_in_vendors-more-focused +++ a/drivers/firmware/dmi_scan.c @@ -585,14 +585,12 @@ int dmi_name_in_serial(const char *str) } /** - * dmi_name_in_vendors - Check if string is anywhere in the DMI vendor information. + * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name * @str: Case sensitive Name */ int dmi_name_in_vendors(const char *str) { - static int fields[] = { DMI_BIOS_VENDOR, DMI_BIOS_VERSION, DMI_SYS_VENDOR, - DMI_PRODUCT_NAME, DMI_PRODUCT_VERSION, DMI_BOARD_VENDOR, - DMI_BOARD_NAME, DMI_BOARD_VERSION, DMI_NONE }; + static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE }; int i; for (i = 0; fields[i] != DMI_NONE; i++) { int f = fields[i];