Arm32: correct string.h functions for "int" -> "unsigned char" conversion

Jan Beulich jbeulich at suse.com
Mon May 18 23:44:44 PDT 2026


While Arm64 does so uniformly, for Arm32 only strchr() currently handles
this properly. Add the necessary conversion also to strrchr(), memchr(),
and memset().

As to the placement in memset(): Putting the new insn at the beginning
of the function could perhaps be deemed more "obvious", but the code
reachable without ever making it to the "1" label only ever does byte
stores.

Signed-off-by: Jan Beulich <jbeulich at suse.com>

--- a/arch/arm/lib/memchr.S
+++ b/arch/arm/lib/memchr.S
@@ -12,6 +12,7 @@
 	.text
 	.align	5
 ENTRY(memchr)
+	and	r1, r1, #0xff
 1:	subs	r2, r2, #1
 	bmi	2f
 	ldrb	r3, [r0], #1
--- a/arch/arm/lib/memset.S
+++ b/arch/arm/lib/memset.S
@@ -24,7 +24,8 @@ UNWIND( .fnstart         )
 /*
  * we know that the pointer in ip is aligned to a word boundary.
  */
-1:	orr	r1, r1, r1, lsl #8
+1:	and	r1, r1, #0xff
+	orr	r1, r1, r1, lsl #8
 	orr	r1, r1, r1, lsl #16
 	mov	r3, r1
 7:	cmp	r2, #16
--- a/arch/arm/lib/strrchr.S
+++ b/arch/arm/lib/strrchr.S
@@ -12,6 +12,7 @@
 		.text
 		.align	5
 ENTRY(strrchr)
+		and	r1, r1, #0xff
 		mov	r3, #0
 1:		ldrb	r2, [r0], #1
 		teq	r2, r1



More information about the linux-arm-kernel mailing list