From patchwork Tue Mar 20 18:07:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 10297711 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CEA88600F6 for ; Tue, 20 Mar 2018 18:16:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C029228CDB for ; Tue, 20 Mar 2018 18:16:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4EC129219; Tue, 20 Mar 2018 18:16:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4558729066 for ; Tue, 20 Mar 2018 18:16:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751317AbeCTSQu (ORCPT ); Tue, 20 Mar 2018 14:16:50 -0400 Received: from mga11.intel.com ([192.55.52.93]:51720 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751269AbeCTSQu (ORCPT ); Tue, 20 Mar 2018 14:16:50 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2018 11:08:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,336,1517904000"; d="scan'208";a="29715884" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 20 Mar 2018 11:08:01 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 268A646; Tue, 20 Mar 2018 20:08:01 +0200 (EET) From: Andy Shevchenko To: Bjorn Helgaas , linux-pci@vger.kernel.org, "Rafael J . Wysocki" , linux-acpi@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , x86@kernel.org, Jean Delvare , Lukas Wunner Cc: Andy Shevchenko Subject: [PATCH v4 1/2] firmware: dmi_scan: Uninline dmi_get_bios_year() helper Date: Tue, 20 Mar 2018 20:07:59 +0200 Message-Id: <20180320180800.63179-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180320180800.63179-1-andriy.shevchenko@linux.intel.com> References: <20180320180800.63179-1-andriy.shevchenko@linux.intel.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Uninline dmi_get_bios_year() which, in particular, allows us to optimize it in the future. While doing this, convert the function to return an error code when BIOS date is not present or not parsable, or CONFIG_DMI=n. Additionally, during the move, add a bit of documentation. Fixes: 492a1abd61e4 ("dmi: Introduce the dmi_get_bios_year() helper function") Suggested-by: Bjorn Helgaas Suggested-by: Rafael J. Wysocki Reviewed-by: Jean Delvare Reviewed-by: Rafael J. Wysocki Signed-off-by: Andy Shevchenko --- drivers/firmware/dmi_scan.c | 20 ++++++++++++++++++++ include/linux/dmi.h | 11 ++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index ae4f1b181c23..bfb6ce6abc83 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -1040,6 +1040,26 @@ bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp) } EXPORT_SYMBOL(dmi_get_date); +/** + * dmi_get_bios_year - get a year out of DMI_BIOS_DATE field + * + * Returns year on success, -ENXIO if DMI is not selected, + * or a different negative error code if DMI field is not present + * or not parsable. + */ +int dmi_get_bios_year(void) +{ + bool exists; + int year; + + exists = dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL); + if (!exists) + return -ENODATA; + + return year ? year : -ERANGE; +} +EXPORT_SYMBOL(dmi_get_bios_year); + /** * dmi_walk - Walk the DMI table and get called back for every record * @decode: Callback function diff --git a/include/linux/dmi.h b/include/linux/dmi.h index b5b8c26b04fb..c46fdb36700b 100644 --- a/include/linux/dmi.h +++ b/include/linux/dmi.h @@ -106,6 +106,7 @@ extern void dmi_scan_machine(void); extern void dmi_memdev_walk(void); extern void dmi_set_dump_stack_arch_desc(void); extern bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp); +extern int dmi_get_bios_year(void); extern int dmi_name_in_vendors(const char *str); extern int dmi_name_in_serial(const char *str); extern int dmi_available; @@ -134,6 +135,7 @@ static inline bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp) *dayp = 0; return false; } +static inline int dmi_get_bios_year(void) { return -ENXIO; } static inline int dmi_name_in_vendors(const char *s) { return 0; } static inline int dmi_name_in_serial(const char *s) { return 0; } #define dmi_available 0 @@ -149,13 +151,4 @@ static inline const struct dmi_system_id * #endif -static inline int dmi_get_bios_year(void) -{ - int year; - - dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL); - - return year; -} - #endif /* __DMI_H__ */