linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Delvare <jdelvare@suse.de>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	linux-pci@vger.kernel.org,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	linux-acpi@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org
Subject: Re: [PATCH v2 1/4] firmware: dmi_scan: Introduce the dmi_get_bios_year() helper
Date: Tue, 13 Mar 2018 11:33:13 +0100	[thread overview]
Message-ID: <20180313113313.612d66c6@endymion> (raw)
In-Reply-To: <20180301180220.11333-2-andriy.shevchenko@linux.intel.com>

Hi Andy,

On Thu,  1 Mar 2018 20:02:17 +0200, Andy Shevchenko wrote:
> The pattern to only extract the year portion of date is used in
> several places and more users may come.
> 
> By using this helper they may create slightly cleaner code.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/firmware/dmi_scan.c | 11 +++++++++++
>  include/linux/dmi.h         |  2 ++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
> index 6ce299926196..616ec17cc802 100644
> --- a/drivers/firmware/dmi_scan.c
> +++ b/drivers/firmware/dmi_scan.c
> @@ -1015,6 +1015,17 @@ bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
>  }
>  EXPORT_SYMBOL(dmi_get_date);
>  
> +int dmi_get_bios_year(void)
> +{
> +	bool exists;
> +	int year;
> +
> +	exists = dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL);
> +
> +	return exists ? year : -ENODATA;

If the DMI field exists but year can't be parsed, "exists" is true but
"year" is 0. From the caller's perspective, it is the same as if the
field did not exist (year is not available in both cases), but the
function returns 0 in one case and -ENODATA in the other. Don't you
think that:

	return year ? year : -ENODATA;

would serve the caller better?

> +}
> +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 46e151172d95..6a86d8db16d9 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;
> @@ -133,6 +134,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

Looks good otherwise.

Reviewed-by: Jean Delvare <jdelvare@suse.de>

-- 
Jean Delvare
SUSE L3 Support

  parent reply	other threads:[~2018-03-13 10:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01 18:02 [PATCH v2 0/4] x86, dmi: introduce and use dmi_get_bios_year() Andy Shevchenko
2018-03-01 18:02 ` [PATCH v2 1/4] firmware: dmi_scan: Introduce the dmi_get_bios_year() helper Andy Shevchenko
2018-03-02 14:05   ` Lukas Wunner
2018-03-02 14:21     ` Andy Shevchenko
2018-03-13 10:33   ` Jean Delvare [this message]
2018-03-01 18:02 ` [PATCH v2 2/4] x86/PCI: Simplify code by using the new " Andy Shevchenko
2018-03-13 10:45   ` Jean Delvare
2018-03-01 18:02 ` [PATCH v2 3/4] ACPI / sleep: " Andy Shevchenko
2018-03-01 18:02 ` [PATCH v2 4/4] PCI: " Andy Shevchenko
2018-03-02 11:10 ` [PATCH v2 0/4] x86, dmi: introduce and use dmi_get_bios_year() Rafael J. Wysocki
2018-03-05 13:24   ` Andy Shevchenko
2018-03-06 15:12     ` Rafael J. Wysocki
2018-03-12  8:52       ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180313113313.612d66c6@endymion \
    --to=jdelvare@suse.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=hpa@zytor.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).