File biosdevname-Add-SMBIOS-3.x-support.patch of Package biosdevname

From 8459b891cdbb2d4691bd188ced5a512be8734d10 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Thu, 13 Aug 2020 16:11:06 +0200
Subject: [PATCH 3/3] Add SMBIOS 3.x support

Handle only the path from sysfs for now.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 src/dmidecode/dmidecode.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/dmidecode/dmidecode.c b/src/dmidecode/dmidecode.c
index f4c12694ef13..f478cc58aeb6 100644
--- a/src/dmidecode/dmidecode.c
+++ b/src/dmidecode/dmidecode.c
@@ -236,7 +236,7 @@ static int dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, co
 	int i=0;
 
 	/* Verify SMBIOS version */
-	if (!isvalidsmbios(ver >> 8, ver & 0xFF)) {
+	if (ver && !isvalidsmbios(ver >> 8, ver & 0xFF)) {
 		return 0;
 	}
 
@@ -253,7 +253,7 @@ static int dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, co
 	}
 
 	data=buf;
-	while(i<num && data+4<=buf+len) /* 4 is the length of an SMBIOS structure header */
+	while((!num || i<num) && data+4<=buf+len) /* 4 is the length of an SMBIOS structure header */
 	{
 		u8 *next;
 		struct dmi_header h;
@@ -314,6 +314,14 @@ static int legacy_decode(u8 *buf, const char *devmem, const struct libbiosdevnam
 	return 0;
 }
 
+/* only from sysfs, handle no base offset */
+static int smbios3_decode(u8 *buf, const char *devmem, const struct libbiosdevname_state *state)
+{
+	if (checksum(buf, 0x18))
+		return dmi_table(0, DWORD(buf + 0x0c), 0, 0, devmem, state, 1);
+	return 0;
+}
+
 #define SYSFS_TABLE_SMBIOS	"/sys/firmware/dmi/tables/smbios_entry_point"
 #define SYSFS_TABLE_DMI		"/sys/firmware/dmi/tables/DMI"
 
@@ -330,6 +338,8 @@ static int smibios_decode_from_sysfs(const struct libbiosdevname_state *state)
 	fclose(fp);
 	if (len == 0x1f && memcmp(buf, "_SM_", 4) == 0)
 		return smbios_decode(buf, SYSFS_TABLE_DMI, state, 1);
+	if (len >= 0x18 && memcmp(buf, "_SM3_", 5) == 0)
+		return smbios3_decode(buf, SYSFS_TABLE_DMI, state);
 	return 0;
 }
 
-- 
2.16.4
openSUSE Build Service is sponsored by