Commit d7f1b4bd authored by Morduan Zang's avatar Morduan Zang Committed by Ard Biesheuvel
Browse files

efi/cper: Fix cper_bits_to_str buffer handling and return value



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: a976d790 ("efi/cper: Add a new helper function to print bitmasks")
Signed-off-by: default avatarMorduan Zang <zhangdandan@uniontech.com>
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
parent 85829b80
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);