From 5be0a16dd05dbc75cb939c97ad7bd9dcc9b5f31a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 11 Mar 2026 20:53:32 +1000 Subject: [PATCH] tools: fix swapped fread arguments causing DMI modalias to always be "unknown" fread(buf, sizeof(buf), 1, dmi) reads one block of 2048 bytes, returning the number of complete blocks (0 or 1). Since DMI modalias files are always shorter than 2048 bytes, fread returns 0 even when data was successfully read into buf. The 'if (n > 0)' check then always fails and the DMI string stays as "unknown". Swap the size and nmemb arguments so fread returns the number of bytes read instead. Fixes: 0ecd08c13439 ("tools: use __attribute__(cleanup)") Co-Authored-by: Claude Code (cherry picked from commit c8c1c07a2a022903a6ee834e318497b1afb839b9) Part-of: --- tools/libinput-record.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 792943d0..58b399cf 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -1404,7 +1404,7 @@ print_system_header(FILE *fp) _autofree_ char *dmistr = strdup("unknown"); // if (dmi) { char buf[2048] = "unknown"; - size_t n = fread(buf, sizeof(buf), 1, dmi); // NOLINT: unix.Stream + size_t n = fread(buf, 1, sizeof(buf), dmi); // NOLINT: unix.Stream if (n > 0) { free(dmistr); dmistr = strndup(buf, n - 1);