summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2022-06-15 13:35:25 +0200
committerJean Delvare <jdelvare@suse.de>2022-06-15 13:35:25 +0200
commitf1874a58d981593f4a754fc63b4ca1410a590078 (patch)
tree2baa397545a539e8b99efa216775977c004afed8
parentcdab638dabb7ebd7fef23a2daf14e4a650a2ea80 (diff)
downloaddmidecode-git-f1874a58d981593f4a754fc63b4ca1410a590078.tar.gz
dmidecode: Make dmi_slot_bus_width() reusable
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>
-rw-r--r--dmidecode.c52
1 files changed, 34 insertions, 18 deletions
diff --git a/dmidecode.c b/dmidecode.c
index 73e455f..cd29caa 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -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_header *h, u16 ver)
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",