[Concept,04/25] smbios: Update smbios_get_header() to return a void *

Message ID 20250903133639.3235920-5-sjg@u-boot.org
State New
Headers
Series Selection of devicetree using CHIDs |

Commit Message

Simon Glass Sept. 3, 2025, 1:36 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Since each table starts with a header, it isn't very useful to have a
separate pointer for the (generic) header and another for the whole
table. Also, casting is a bit of a pain.

Update smbios_get_header() so that it returns a const void * so that it
is possible to directly assign it to the appropriate SMBIOS table's
pointer.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 board/coreboot/coreboot/sysinfo.c | 31 ++++++++++++++-----------------
 include/smbios.h                  |  9 ++++-----
 lib/smbios-parser.c               | 13 +++++--------
 3 files changed, 23 insertions(+), 30 deletions(-)
  

Patch

diff --git a/board/coreboot/coreboot/sysinfo.c b/board/coreboot/coreboot/sysinfo.c
index 2fb68cbfa92..f431d271a1c 100644
--- a/board/coreboot/coreboot/sysinfo.c
+++ b/board/coreboot/coreboot/sysinfo.c
@@ -12,10 +12,8 @@ 
 #include <asm/cb_sysinfo.h>
 
 struct cb_sysinfo_priv {
-	const struct smbios_header *bios;
-	const struct smbios_header *system;
-	const struct smbios_type0 *t0;
-	const struct smbios_type1 *t1;
+	const struct smbios_type0 *bios;
+	const struct smbios_type1 *system;
 };
 
 static int cb_get_str(struct udevice *dev, int id, size_t size, char *val)
@@ -25,23 +23,24 @@  static int cb_get_str(struct udevice *dev, int id, size_t size, char *val)
 
 	switch (id) {
 	case SYSID_BOARD_MODEL:
-		if (priv->t1)
-			str = smbios_string(priv->system,
-					    priv->t1->product_name);
+		if (priv->system)
+			str = smbios_string(&priv->system->hdr,
+					    priv->system->product_name);
 		break;
 	case SYSID_BOARD_MANUFACTURER:
-		if (priv->t1)
-			str = smbios_string(priv->system,
-					    priv->t1->manufacturer);
+		if (priv->system)
+			str = smbios_string(&priv->system->hdr,
+					    priv->system->manufacturer);
 		break;
 	case SYSID_PRIOR_STAGE_VERSION:
-		if (priv->t0)
-			str = smbios_string(priv->bios, priv->t0->bios_ver);
+		if (priv->bios)
+			str = smbios_string(&priv->bios->hdr,
+					    priv->bios->bios_ver);
 		break;
 	case SYSID_PRIOR_STAGE_DATE:
-		if (priv->t0)
-			str = smbios_string(priv->bios,
-					    priv->t0->bios_release_date);
+		if (priv->bios)
+			str = smbios_string(&priv->bios->hdr,
+					    priv->bios->bios_release_date);
 		break;
 	}
 	if (!str)
@@ -64,8 +63,6 @@  static int cb_detect(struct udevice *dev)
 
 	priv->bios = smbios_get_header(&info, SMBIOS_BIOS_INFORMATION);
 	priv->system = smbios_get_header(&info, SMBIOS_SYSTEM_INFORMATION);
-	priv->t0 = (struct smbios_type0 *)priv->bios;
-	priv->t1 = (struct smbios_type1 *)priv->system;
 
 	return 0;
 }
diff --git a/include/smbios.h b/include/smbios.h
index 1bae4d99b05..96202f9a1c8 100644
--- a/include/smbios.h
+++ b/include/smbios.h
@@ -369,12 +369,11 @@  const struct smbios_entry *smbios_entry(u64 address, u32 size);
 /**
  * smbios_get_header() - Search for an SMBIOS header type
  *
- * @entry:     pointer to the first entry
- * @type:      SMBIOS type
- * @return:    NULL or a valid pointer to a struct smbios_header
+ * @info: SMBIOS info
+ * @type: SMBIOS type
+ * @return: NULL or a valid pointer to a struct smbios_header
  */
-const struct smbios_header *smbios_get_header(const struct smbios_info *info,
-					      int type);
+const void *smbios_get_header(const struct smbios_info *info, int type);
 
 /**
  * smbios_string() - Return string from SMBIOS
diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c
index d8dc25da6ce..abb301ecf7e 100644
--- a/lib/smbios-parser.c
+++ b/lib/smbios-parser.c
@@ -62,8 +62,7 @@  const struct smbios_entry *smbios_entry(u64 address, u32 size)
 	return entry;
 }
 
-const struct smbios_header *smbios_get_header(const struct smbios_info *info,
-					      int type)
+const void *smbios_get_header(const struct smbios_info *info, int type)
 {
 	struct smbios_header *header;
 
@@ -107,9 +106,8 @@  char *smbios_string(const struct smbios_header *header, int index)
 
 int smbios_update_version_full(void *smbios_tab, const char *new_version)
 {
-	const struct smbios_header *hdr;
+	const struct smbios_type0 *bios;
 	struct smbios_info info;
-	struct smbios_type0 *bios;
 	uint old_len, len;
 	char *ptr;
 	int ret;
@@ -119,11 +117,10 @@  int smbios_update_version_full(void *smbios_tab, const char *new_version)
 		return log_msg_ret("tab", -ENOENT);
 
 	log_info("Updating SMBIOS table at %p\n", smbios_tab);
-	hdr = smbios_get_header(&info, SMBIOS_BIOS_INFORMATION);
-	if (!hdr)
+	bios = smbios_get_header(&info, SMBIOS_BIOS_INFORMATION);
+	if (!bios)
 		return log_msg_ret("tab", -ENOENT);
-	bios = (struct smbios_type0 *)hdr;
-	ptr = smbios_string(hdr, bios->bios_ver);
+	ptr = smbios_string(&bios->hdr, bios->bios_ver);
 	if (!ptr)
 		return log_msg_ret("str", -ENOMEDIUM);