From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88D47D72358 for ; Fri, 23 Jan 2026 08:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hgFnkvokhQyzLt2H9wZ91QusN7BGCbQJgadlOFG8xOY=; b=kItEDe0OO18ABk i7q6z5lg/s8njVQa6nBGsdPjq1IVG1sbbVqMtC88Vbw/H+O+H/zrZ6th8n8ldFHhOUBxDhgefBlP7 VTZK2OFeh4+r25SR2Tp7D8U+iplVt9AvY1ZqIOo9tmm3K+A+ERMVSxT4fKVAgSN75iz3Ou9uFXu+l Z2qfnfGt8jIPiINLfyed4LQQ4pCJxe8ojTKCvZCX2IPMRZgodoztU79nm0A3W2p3wyCyh8nIE41QW pt/bAW+IrofSd1xNcvhZniW9fem7AyX97R0dYDnpekRqStKPKOHHwH3r9GZY7foThfP/8BpFw5fKX +pDo38e3RjR9/Si/+rKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vjD0Q-00000008VrZ-0lRF; Fri, 23 Jan 2026 08:59:02 +0000 Received: from mailgw.kylinos.cn ([124.126.103.232]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vjD0K-00000008Vmv-3FzH for linux-riscv@lists.infradead.org; Fri, 23 Jan 2026 08:58:58 +0000 X-UUID: bc54094ef83911f0b0f03b4cfa9209d1-20260123 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.6,REQID:202381a5-b0e6-41e7-85eb-8be49477ad59,IP:0,UR L:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:-5 X-CID-META: VersionHash:a9d874c,CLOUDID:7adacdfc704780914d4afd00aea2fc10,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|850|898,TC:nil,Content:0|15|50 ,EDM:-3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,O SA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: bc54094ef83911f0b0f03b4cfa9209d1-20260123 X-User: jiangfeng@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 91718921; Fri, 23 Jan 2026 16:58:50 +0800 From: Feng Jiang To: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, akpm@linux-foundation.org, kees@kernel.org, andy@kernel.org, jiangfeng@kylinos.cn, ebiggers@kernel.org, martin.petersen@oracle.com, mingo@kernel.org, charlie@rivosinc.com, conor.dooley@microchip.com, samuel.holland@sifive.com, linus.walleij@linaro.org, nathan@kernel.org Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Joel Stanley Subject: [PATCH v4 3/8] lib/string_kunit: add correctness test for strrchr() Date: Fri, 23 Jan 2026 16:58:36 +0800 Message-Id: <20260123085841.212468-4-jiangfeng@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260123085841.212468-1-jiangfeng@kylinos.cn> References: <20260123085841.212468-1-jiangfeng@kylinos.cn> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260123_005857_529053_43C247BA X-CRM114-Status: UNSURE ( 9.04 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Introduce a KUnit test to verify strrchr() across various memory alignments and character positions. This ensures the implementation correctly identifies the last occurrence of a character. Signed-off-by: Feng Jiang Acked-by: Andy Shevchenko Tested-by: Joel Stanley --- lib/tests/string_kunit.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/tests/string_kunit.c b/lib/tests/string_kunit.c index 991f01d52eb2..7f1e2bf6a352 100644 --- a/lib/tests/string_kunit.c +++ b/lib/tests/string_kunit.c @@ -184,6 +184,35 @@ static void string_test_strchr(struct kunit *test) KUNIT_ASSERT_NULL(test, result); } +static void string_test_strrchr(struct kunit *test) +{ + const size_t buf_size = STRING_TEST_MAX_LEN + STRING_TEST_MAX_OFFSET + 1; + size_t offset, len; + char *buf; + + buf = kunit_kzalloc(test, buf_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + + memset(buf, 'A', buf_size); + buf[buf_size - 1] = '\0'; + + for (offset = 0; offset < STRING_TEST_MAX_OFFSET; offset++) { + for (len = 0; len <= STRING_TEST_MAX_LEN; len++) { + buf[offset + len] = '\0'; + + KUNIT_EXPECT_PTR_EQ(test, strrchr(buf + offset, 'Z'), NULL); + + if (len > 0) + KUNIT_EXPECT_PTR_EQ(test, strrchr(buf + offset, 'A'), + buf + offset + len - 1); + else + KUNIT_EXPECT_PTR_EQ(test, strrchr(buf + offset, 'A'), NULL); + + buf[offset + len] = 'A'; + } + } +} + static void string_test_strnchr(struct kunit *test) { const char *test_string = "abcdefghijkl"; @@ -679,6 +708,7 @@ static struct kunit_case string_test_cases[] = { KUNIT_CASE(string_test_strnlen), KUNIT_CASE(string_test_strchr), KUNIT_CASE(string_test_strnchr), + KUNIT_CASE(string_test_strrchr), KUNIT_CASE(string_test_strspn), KUNIT_CASE(string_test_strcmp), KUNIT_CASE(string_test_strcmp_long_strings), -- 2.25.1 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv