[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 1/1] arm64: Fix strrchr() matching of null terminator


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: "Edgar E. Iglesias" <edgar.iglesias@xxxxxxx>
  • Date: Tue, 19 May 2026 01:43:53 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=t4S/4MTwq6hxCSZMJo8SlPlaAXuhjtvdL1rd4CEbqZM=; b=GuOso1Xw3Y11m5OVgfV8anJPMeNKcHlzupE20XVOmJBK8fDN288Fcmhw7ZP5ymnvHlMGhJ6UY2JhBPISrMjnnXxq4gxcxIZJJi7ctB0pwj1G+uDXX3sCUjWuDLU4mLA5K/7ADxthBPCYwpb5L0RP0u3wMXHdcdd7lrK+taaHWEuYmFc1kertDUN2/Yw2iFylku0i0GZLql+tWpw4nkbkJ097T0Su/Y5WzPqShiT59bsFx+SQoeG/zkS+KZIKx8HWxDmRnRTpkT01PzlU57OJ0N16rMXFoGX1XRh0JyULHmePnc8ppU19FCIc/QTMTGtTKz87tLNjDEX+CZLE5orSWA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pfxRAHLVZpqjun1aOR/Ym5QxUDSLE/1GQFy4g7LrwIYlMsFyU+ZEbA/v1apNzXEJcuUbVXIxzcQmeku/lvyeAChCFGDL6GGbMW+j6i9ICa8ClCpr4p8+35maphTIQrLIDSVT1uEeIZ7CMWko1jsHPyYU1pRERhO3VrQOU15p99LSLFjZhT1v1XocScILuwRNq+ypNZcD/PRA2dirJkW+tyFoVl+kEUglf648lLqXtLgynH6a5M3cqPceTBTZd/bLCtBOo0zqOvVJ4DCkuq1+y4PgN3Jlj/985xFXI4jn2/TzSgn5w0LRAT0OpJhgodZE5M2GAcmDTnxZJ0m3QvwrlA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: sstabellini@xxxxxxxxxx, julien@xxxxxxx, bertrand.marquis@xxxxxxx, michal.orzel@xxxxxxx, Volodymyr_Babchuk@xxxxxxxx, edgar.iglesias@xxxxxxx
  • Delivery-date: Mon, 18 May 2026 23:44:12 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The generic Xen strrchr() implementation returns a pointer to the string
terminator when searching for '\0', matching the standard C semantics.

The ARM64 assembly version stopped as soon as it loaded the terminator and
returned the previous match pointer instead.  This made strrchr("", '\0')
return NULL.

Compare the loaded byte against the requested character before deciding
whether to stop at the terminator, so the terminator itself can be returned
when it is the requested character.

Fixes: 42c4eb6a83 ("xen: arm64: assembly optimised mem* and str*")
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xxxxxxx>
---
 xen/arch/arm/arm64/lib/strrchr.S | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/arm64/lib/strrchr.S b/xen/arch/arm/arm64/lib/strrchr.S
index 81033c0822..31f304b183 100644
--- a/xen/arch/arm/arm64/lib/strrchr.S
+++ b/xen/arch/arm/arm64/lib/strrchr.S
@@ -30,11 +30,10 @@ FUNC(strrchr)
        mov     x3, #0
        and     w1, w1, #0xff
 1:     ldrb    w2, [x0], #1
-       cbz     w2, 2f
        cmp     w2, w1
-       b.ne    1b
+       b.ne    2f
        sub     x3, x0, #1
-       b       1b
-2:     mov     x0, x3
+2:     cbnz    w2, 1b
+       mov     x0, x3
        ret
 END(strrchr)
-- 
2.43.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.