Blame SOURCES/dmidecode-use-common-function-to-get-SMBIOS-version.patch

4f8197
From db2e8e195c15ed0e56e6652c1b59fdd487d4fbb9 Mon Sep 17 00:00:00 2001
4f8197
From: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
4f8197
Date: Thu, 15 Jan 2015 01:14:43 +0200
4f8197
Subject: [PATCH 1/4] dmidecode: use common function to get SMBIOS version
4f8197
4f8197
Move SMBIOS version code in separate function as it's more readable
4f8197
and can be used by others when it's required.
4f8197
In paticular, it can be used when dmi sysfs support is added.
4f8197
4f8197
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
4f8197
---
4f8197
 dmidecode.c | 59 +++++++++++++++++++++++++++++++++++++----------------------
4f8197
 1 file changed, 37 insertions(+), 22 deletions(-)
4f8197
4f8197
diff --git a/dmidecode.c b/dmidecode.c
4f8197
index a5304a7..c4b4fd1 100644
4f8197
--- a/dmidecode.c
4f8197
+++ b/dmidecode.c
4f8197
@@ -4277,6 +4277,42 @@ static void dmi_decode(const struct dmi_header *h, u16 ver)
4f8197
 	printf("\n");
4f8197
 }
4f8197
 
4f8197
+/**
4f8197
+ * get_smbios_version - get SMBIOS version
4f8197
+ * @smbios: pointer on SMBIOS entry point table
4f8197
+ *
4f8197
+ * Returns SMBIOS version
4f8197
+ */
4f8197
+static u16 get_smbios_version(unsigned char *smbios)
4f8197
+{
4f8197
+	u16 ver;
4f8197
+
4f8197
+	ver = (smbios[0x06] << 8) + smbios[0x07];
4f8197
+
4f8197
+	/* Some BIOS report weird SMBIOS version, fix that up */
4f8197
+	switch (ver) {
4f8197
+	case 0x021F:
4f8197
+	case 0x0221:
4f8197
+		if (!(opt.flags & FLAG_QUIET))
4f8197
+			printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
4f8197
+			       ver & 0xFF, 3);
4f8197
+		ver = 0x0203;
4f8197
+		break;
4f8197
+	case 0x0233:
4f8197
+		if (!(opt.flags & FLAG_QUIET))
4f8197
+			printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
4f8197
+			       51, 6);
4f8197
+		ver = 0x0206;
4f8197
+		break;
4f8197
+	}
4f8197
+
4f8197
+	if (!(opt.flags & FLAG_QUIET))
4f8197
+		printf("SMBIOS %u.%u present.\n",
4f8197
+		       ver >> 8, ver & 0xFF);
4f8197
+
4f8197
+	return ver;
4f8197
+}
4f8197
+
4f8197
 static void to_dmi_header(struct dmi_header *h, u8 *data)
4f8197
 {
4f8197
 	h->type = data[0];
4f8197
@@ -4453,7 +4489,6 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
4f8197
 	free(buf);
4f8197
 }
4f8197
 
4f8197
-
4f8197
 /*
4f8197
  * Build a crafted entry point with table address hard-coded to 32,
4f8197
  * as this is where we will put it in the output file. We adjust the
4f8197
@@ -4477,27 +4512,7 @@ static int smbios_decode(u8 *buf, const char *devmem)
4f8197
 	 || !checksum(buf + 0x10, 0x0F))
4f8197
 		return 0;
4f8197
 
4f8197
-	ver = (buf[0x06] << 8) + buf[0x07];
4f8197
-	/* Some BIOS report weird SMBIOS version, fix that up */
4f8197
-	switch (ver)
4f8197
-	{
4f8197
-		case 0x021F:
4f8197
-		case 0x0221:
4f8197
-			if (!(opt.flags & FLAG_QUIET))
4f8197
-				printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
4f8197
-				       ver & 0xFF, 3);
4f8197
-			ver = 0x0203;
4f8197
-			break;
4f8197
-		case 0x0233:
4f8197
-			if (!(opt.flags & FLAG_QUIET))
4f8197
-				printf("SMBIOS version fixup (2.%d -> 2.%d).\n",
4f8197
-				       51, 6);
4f8197
-			ver = 0x0206;
4f8197
-			break;
4f8197
-	}
4f8197
-	if (!(opt.flags & FLAG_QUIET))
4f8197
-		printf("SMBIOS %u.%u present.\n",
4f8197
-			ver >> 8, ver & 0xFF);
4f8197
+	ver = get_smbios_version(buf);
4f8197
 
4f8197
 	dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C),
4f8197
 		ver, devmem);
4f8197
-- 
4f8197
1.9.3
4f8197