[PATCH] dmi: Adjust the format of EC versions to match edk2 and Windows

From: Sean Rhodes
Date: Fri Feb 23 2024 - 10:02:23 EST


Currently, Linux displays the raw bytes for EC firmware versions, which can
lead to confusion due to formatting mismatches with other platforms like edk2
and Windows.

These platforms format EC versions as `%d.%02d`, ensuring that the minor
version is zero-padded to two digits. This discrepancy becomes particularly
noticeable with version numbers where the minor version could be
misinterpreted, such as interpreting `1.02` as `1.2`, which does not clearly
distinguish it from `1.20`.

To align Linux's presentation of EC firmware versions with these platforms
and to minimize confusion, this commit adjusts the format to `%d.%02d`,
matching the convention used by edk2 and Windows.

Cc: Jean Delvare <jdelvare@xxxxxxxx>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
---
drivers/firmware/dmi-id.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
index 5f3a3e913d28..5bb921c4f62d 100644
--- a/drivers/firmware/dmi-id.c
+++ b/drivers/firmware/dmi-id.c
@@ -114,12 +114,20 @@ static ssize_t get_modalias(char *buffer, size_t buffer_size)
if (!c)
continue;

- t = kmalloc(strlen(c) + 1, GFP_KERNEL);
- if (!t)
- break;
- ascii_filter(t, c);
- l = scnprintf(p, left, ":%s%s", f->prefix, t);
- kfree(t);
+ if (f->field == DMI_EC_FIRMWARE_RELEASE) {
+ int major, minor;
+ if (sscanf(c, "%d.%d", &major, &minor) == 2)
+ l = scnprintf(p, left, ":%s%d.%02d", f->prefix, major, minor);
+ else
+ l = scnprintf(p, left, ":%s%s", f->prefix, c);
+ } else {
+ t = kmalloc(strlen(c) + 1, GFP_KERNEL);
+ if (!t)
+ break;
+ ascii_filter(t, c);
+ l = scnprintf(p, left, ":%s%s", f->prefix, t);
+ kfree(t);
+ }

p += l;
left -= l;
--
2.40.1