[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dmidecode] [PATCH 1/7] dmidecode: Make dmi_slot_bus_width() reusable
From: |
Jean Delvare |
Subject: |
[dmidecode] [PATCH 1/7] dmidecode: Make dmi_slot_bus_width() reusable |
Date: |
Mon, 30 May 2022 14:13:08 +0200 |
Let dmi_slot_bus_width() return its value without a trailing space,
so that this function can be reused in a different context.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
dmidecode.c | 52 ++++++++++++++++++++++++++++++++++------------------
1 file changed, 34 insertions(+), 18 deletions(-)
--- dmidecode.orig/dmidecode.c 2022-05-25 11:58:11.556656203 +0200
+++ dmidecode/dmidecode.c 2022-05-25 12:03:30.874776814 +0200
@@ -2074,31 +2074,49 @@ static const char *dmi_slot_type(u8 code
return out_of_spec;
}
-static const char *dmi_slot_bus_width(u8 code)
+/* If hide_unknown is set, return NULL instead of "Other" or "Unknown" */
+static const char *dmi_slot_bus_width(u8 code, int hide_unknown)
{
/* 7.10.2 */
static const char *width[] = {
- "", /* 0x01, "Other" */
- "", /* "Unknown" */
- "8-bit ",
- "16-bit ",
- "32-bit ",
- "64-bit ",
- "128-bit ",
- "x1 ",
- "x2 ",
- "x4 ",
- "x8 ",
- "x12 ",
- "x16 ",
- "x32 " /* 0x0E */
+ "Other", /* 0x01 */
+ "Unknown",
+ "8-bit",
+ "16-bit",
+ "32-bit",
+ "64-bit",
+ "128-bit",
+ "x1",
+ "x2",
+ "x4",
+ "x8",
+ "x12",
+ "x16",
+ "x32" /* 0x0E */
};
if (code >= 0x01 && code <= 0x0E)
+ {
+ if (code <= 0x02 && hide_unknown)
+ return NULL;
return width[code - 0x01];
+ }
return out_of_spec;
}
+static void dmi_slot_type_with_width(u8 type, u8 width)
+{
+ const char *type_str, *width_str;
+
+ type_str = dmi_slot_type(type);
+ width_str = dmi_slot_bus_width(width, 1);
+
+ if (width_str)
+ pr_attr("Type", "%s %s", width_str, type_str);
+ else
+ pr_attr("Type", "%s", type_str);
+}
+
static const char *dmi_slot_current_usage(u8 code)
{
/* 7.10.3 */
@@ -4405,9 +4423,7 @@ static void dmi_decode(const struct dmi_
if (h->length < 0x0C) break;
pr_attr("Designation", "%s",
dmi_string(h, data[0x04]));
- pr_attr("Type", "%s%s",
- dmi_slot_bus_width(data[0x06]),
- dmi_slot_type(data[0x05]));
+ dmi_slot_type_with_width(data[0x05], data[0x06]);
pr_attr("Current Usage", "%s",
dmi_slot_current_usage(data[0x07]));
pr_attr("Length", "%s",
--
Jean Delvare
SUSE L3 Support
- [dmidecode] [PATCH 0/7] dmidecode: Add support for SMBIOS 3.5.0, Jean Delvare, 2022/05/30
- [dmidecode] [PATCH 1/7] dmidecode: Make dmi_slot_bus_width() reusable,
Jean Delvare <=
- [dmidecode] [PATCH 2/7] dmidecode: Add missing bits from SMBIOS 3.4.0 specification, Jean Delvare, 2022/05/30
- [dmidecode] [PATCH 3/7] dmidecode: Add new fields and enumerated values from SMBIOS 3.5.0, Jean Delvare, 2022/05/30
- [dmidecode] [PATCH 4/7] dmidecode: Add support for type 45 records (Firmware Inventory Information), Jean Delvare, 2022/05/30
- [dmidecode] [PATCH 5/7] dmidecode: Enumerate the new struct types, Jean Delvare, 2022/05/30
- [dmidecode] [PATCH 6/7] dmidecode: Drop outdated references, Jean Delvare, 2022/05/30
- [dmidecode] [PATCH 7/7] dmidecode: Set supported version to 3.5.0, Jean Delvare, 2022/05/30