ACK: [RFC,PATCH 2/7 v2] fwts: Only run firmware detection once
Colin Ian King
colin.king at canonical.com
Thu May 1 08:10:37 UTC 2014
On 28/04/14 02:35, Jeremy Kerr wrote:
> Store the discovered value in a static var, and return this value on
> subsequent invocations of fwts_firmware_detect.
>
> Signed-off-by: Jeremy Kerr <jk at ozlabs.org>
>
> ---
> src/lib/include/fwts_firmware.h | 2 +-
> src/lib/src/fwts_firmware.c | 19 +++++++++++++++----
> 2 files changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/src/lib/include/fwts_firmware.h b/src/lib/include/fwts_firmware.h
> index ee3880d..265ef4d 100644
> --- a/src/lib/include/fwts_firmware.h
> +++ b/src/lib/include/fwts_firmware.h
> @@ -21,7 +21,7 @@
>
> #include <stdbool.h>
>
> -enum {
> +enum firmware_type {
> FWTS_FIRMWARE_UNKNOWN = 0,
> FWTS_FIRMWARE_BIOS = 1,
> FWTS_FIRMWARE_UEFI = 2,
> diff --git a/src/lib/src/fwts_firmware.c b/src/lib/src/fwts_firmware.c
> index bf080a7..4b59cef 100644
> --- a/src/lib/src/fwts_firmware.c
> +++ b/src/lib/src/fwts_firmware.c
> @@ -23,6 +23,9 @@
>
> #include "fwts.h"
>
> +static enum firmware_type firmware_type;
> +static bool firmware_type_valid;
> +
> /*
> * fwts_memory_map_entry_compare()
> * callback used to sort memory_map entries on start address
> @@ -31,10 +34,18 @@ int fwts_firmware_detect(void)
> {
> struct stat statbuf;
>
> - if (stat("/sys/firmware/efi", &statbuf))
> - return FWTS_FIRMWARE_BIOS; /* No UEFI, Assume BIOS */
> - else
> - return FWTS_FIRMWARE_UEFI;
> + if (firmware_type_valid)
> + return firmware_type;
> +
> + if (stat("/sys/firmware/efi", &statbuf)) {
> + /* No UEFI, Assume BIOS */
> + firmware_type = FWTS_FIRMWARE_BIOS;
> + } else {
> + firmware_type = FWTS_FIRMWARE_UEFI;
> + }
> +
> + firmware_type_valid = true;
> + return firmware_type;
> }
>
> int fwts_firmware_features(void)
>
Acked-by: Colin Ian King <colin.king at canonical.com>
More information about the fwts-devel
mailing list