Re: [PATCH] riscv, lib: Fix Zbb strncmp

Conor Dooley
2023-02-28T19:12:57Z

[-- Attachment #1.1: Type: text/plain, Size: 1368 bytes --]

On Tue, Feb 28, 2023 at 07:42:10PM +0100, Björn Töpel wrote:
> From: Björn Töpel <bjorn@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@vrull.eu>
> Signed-off-by: Björn Töpel <bjorn@rivosinc.com>

With your new selftest stuff & on a JH7110:
Tested-by: Conor Dooley <conor.dooley@microchip.com>
Also, given the reporter, this should be:
Reported-by: Guenter Roeck <linux@roeck-us.net>
no?

Thanks,
Conor.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]