]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
efi/cper: Fix cper_bits_to_str buffer handling and return value
authorMorduan Zang <zhangdandan@uniontech.com>
Wed, 14 Jan 2026 05:30:33 +0000 (13:30 +0800)
committerArd Biesheuvel <ardb@kernel.org>
Wed, 14 Jan 2026 10:34:42 +0000 (11:34 +0100)
The return value calculation was incorrect: `return len - buf_size;`
Initially `len = buf_size`, then `len` decreases with each operation.
This results in a negative return value on success.

Fix by returning `buf_size - len` which correctly calculates the actual
number of bytes written.

Fixes: a976d790f494 ("efi/cper: Add a new helper function to print bitmasks")
Signed-off-by: Morduan Zang <zhangdandan@uniontech.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/cper.c

index 0232bd040f61c9b4521ae50ec4b6a1b0bfa5cc19..bd99802cb0cad6845fe72b1af9d955cf454acdb4 100644 (file)
@@ -162,7 +162,7 @@ int cper_bits_to_str(char *buf, int buf_size, unsigned long bits,
                len -= size;
                str += size;
        }
-       return len - buf_size;
+       return buf_size - len;
 }
 EXPORT_SYMBOL_GPL(cper_bits_to_str);