]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Jan 2026 10:18:35 +0000 (11:18 +0100)
commit d7f1b4bdc7108be1b178e1617b5f45c8918e88d7 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/firmware/efi/cper.c

index 7f89a9fb2ecad62f2221d8e14d9a6ec3f4191f77..16b27fe9608fd681a366ff1987d71286b397f8dc 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);