From 2829628cf3cd4b1f3d18070dd45494c34e36362c Mon Sep 17 00:00:00 2001 From: William Liu Date: Tue, 29 Apr 2025 21:35:44 +0800 Subject: [PATCH] Fix missing newline in sysfs file When using cat command to read /sys/class/kxo/kxo/kxo_state file, the output (e.g., "1 1 0") did not include a newline, causing the terminal prompt to appear on the same line (e.g., "1 1 0user@Ubuntu:~$"). This truncation issue is diagnosed by examining kxo_state_show, which uses snprintf with a format string "%c %c %c\n". The size parameter of snprintf set to 6 included the null terminator \0 as the last character, leaving only 5 bytes for the desired output (e.g., "1 0 0\n"), thus the newline symbol \n was truncated by null terminator. This commit resolves the issue by increasing the size parameter of snprintf from 6 to 7, ensuring the output includes the newline. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index e98bb90..fb23a0b 100644 --- a/main.c +++ b/main.c @@ -48,7 +48,7 @@ static ssize_t kxo_state_show(struct device *dev, char *buf) { read_lock(&attr_obj.lock); - int ret = snprintf(buf, 6, "%c %c %c\n", attr_obj.display, attr_obj.resume, + int ret = snprintf(buf, 7, "%c %c %c\n", attr_obj.display, attr_obj.resume, attr_obj.end); read_unlock(&attr_obj.lock); return ret;