[PATCH] riscv, lib: Fix Zbb strncmp
Björn Töpel
bjorn at kernel.org
Tue Feb 28 11:41:44 PST 2023
Conor Dooley <conor at kernel.org> writes:
> On Tue, Feb 28, 2023 at 07:42:10PM +0100, Björn Töpel wrote:
>> From: Björn Töpel <bjorn at rivosinc.com>
>>
>> The Zbb optimized strncmp has two parts; a fast path that does XLEN/8B
>> per iteration, and a slow that does one byte per iteration.
>>
>> The idea is to compare aligned XLEN chunks for most of strings, and do
>> the remainder tail in the slow path.
>>
>> The Zbb strncmp has two issues in the fast path:
>>
>> Incorrect remainder handling (wrong compare): Assume that the string
>> length is 9. On 64b systems, the fast path should do one iteration,
>> and one iteration in the slow path. Instead, both were done in the
>> fast path, which lead to incorrect results. An example:
>>
>> strncmp("/dev/vda", "/dev/", 5);
>>
>> Correct by changing "bgt" to "bge".
>>
>> Missing NULL checks in the second string: This could lead to incorrect
>> results for:
>>
>> strncmp("/dev/vda", "/dev/vda\0", 8);
>>
>> Correct by adding an additional check.
>>
>> Fixes: b6fcdb191e36 ("RISC-V: add zbb support to string functions")
>> Suggested-by: Heiko Stuebner <heiko.stuebner at vrull.eu>
>> Signed-off-by: Björn Töpel <bjorn at rivosinc.com>
>
> With your new selftest stuff & on a JH7110:
> Tested-by: Conor Dooley <conor.dooley at microchip.com>
> Also, given the reporter, this should be:
> Reported-by: Guenter Roeck <linux at roeck-us.net>
> no?
Indeed. Sorry, Guenter, for missing that!
More information about the linux-riscv
mailing list