boot: introduce smbios_raw_info_get_cached() to cache populated SMBIOS raw info

Then, drop cache in smbios_info_populate().
No functional change, just refactoring and preparation for later commit.
This commit is contained in:
Yu Watanabe
2024-12-17 01:25:27 +09:00
committed by anonymix007
parent f28cedfa31
commit 7c4e351861
3 changed files with 18 additions and 6 deletions

View File

@@ -58,13 +58,10 @@ typedef struct SmbiosInfo {
} SmbiosInfo;
static void smbios_info_populate(SmbiosInfo *ret_info) {
static RawSmbiosInfo raw = {};
static bool raw_info_populated = false;
assert(ret_info);
if (!raw_info_populated) {
smbios_raw_info_populate(&raw);
raw_info_populated = true;
}
RawSmbiosInfo raw;
smbios_raw_info_get_cached(&raw);
ret_info->smbios_fields[CHID_SMBIOS_MANUFACTURER] = smbios_to_hashable_string(raw.manufacturer);
ret_info->smbios_fields[CHID_SMBIOS_PRODUCT_NAME] = smbios_to_hashable_string(raw.product_name);

View File

@@ -259,3 +259,17 @@ void smbios_raw_info_populate(RawSmbiosInfo *ret_info) {
ret_info->baseboard_product = NULL;
}
}
void smbios_raw_info_get_cached(RawSmbiosInfo *ret_info) {
static RawSmbiosInfo info = {};
static bool cached = false;
assert(ret_info);
if (!cached) {
smbios_raw_info_populate(&info);
cached = true;
}
*ret_info = info;
}

View File

@@ -17,3 +17,4 @@ typedef struct RawSmbiosInfo {
} RawSmbiosInfo;
void smbios_raw_info_populate(RawSmbiosInfo *ret_info);
void smbios_raw_info_get_cached(RawSmbiosInfo *ret_info);