From 643cef3a9c2a883bb5c0e86f734453c8739cd015 Mon Sep 17 00:00:00 2001
From: Heiko Stuebner <heiko.stuebner@vrull.eu>
Date: Thu, 23 Feb 2023 12:04:19 +0100
Subject: [PATCH] RISC-V: fix strncmp for shorter 2nd strings

The strncmp implementation didn't handle the case correctly when the second
string was a lot shorter than the first one, so the 0-byte detection didn't
trigger for the 1st string.

To fix this look for 0-bytes in each block of the second string as well and
jump to the tail processing in that case, similar to how its done for the
first string.

Reported-by: Reported-by: Guenter Roeck <linux@roeck-us.net>
Fixes: b6fcdb191e36 ("RISC-V: add zbb support to string functions")
Signed-off-by: Heiko Stuebner <heiko.stuebner@vrull.eu>
---
 arch/riscv/lib/strncmp.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/riscv/lib/strncmp.S b/arch/riscv/lib/strncmp.S
index ee49595075be..e047a3ab8233 100644
--- a/arch/riscv/lib/strncmp.S
+++ b/arch/riscv/lib/strncmp.S
@@ -83,6 +83,8 @@ strncmp_zbb:
 	REG_L	t1, 0(a1)
 	orc.b	t3, t0
 	bne	t3, t5, 2f
+	orc.b	t3, t1
+	bne	t3, t5, 2f
 	addi	a0, a0, SZREG
 	addi	a1, a1, SZREG
 	beq	t0, t1, 1b
-- 
2.39.0

