From nobody Mon Feb 9 16:17:36 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62DA133ADAC; Fri, 23 Jan 2026 08:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769158748; cv=none; b=AN7G9xQbTbOVOm62pqd2ToMj96OXajvyj6gwwuZ9+sHilaTv6DqP/LaArbzbawKmlBTHuv9pCXleMgsVPglsIkQ83duKi3UdFLyr2H3RUJE1lzSo82LgdS+aHq1eRI9ReUbqOXichlkELO6rE1/gJlbKK4vCLzzt3NiU/ALz1I8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769158748; c=relaxed/simple; bh=gdp0TkFXB6tIKP75KCs0gmk3wZBq+K9AMFnNVtN0+zc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LC9QM+ObfCVDuLCK8GKAaevb/xDM0l/7fW1r9BVYYdtpuWVgPiqJvm2QbWEyaUMtW/HGdhlehAWj3ka/YKn97r9j90ELQrogk7eCe5YMsmby6507ciaQDvMCcBLyQ7LYMNtXym1bwDhBqQcxhpjgodPsC+Lr1pRimNBOK21X61A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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); } =20 +static void string_test_strrchr(struct kunit *test) +{ + const size_t buf_size =3D STRING_TEST_MAX_LEN + STRING_TEST_MAX_OFFSET + = 1; + size_t offset, len; + char *buf; + + buf =3D kunit_kzalloc(test, buf_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + + memset(buf, 'A', buf_size); + buf[buf_size - 1] =3D '\0'; + + for (offset =3D 0; offset < STRING_TEST_MAX_OFFSET; offset++) { + for (len =3D 0; len <=3D STRING_TEST_MAX_LEN; len++) { + buf[offset + len] =3D '\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] =3D 'A'; + } + } +} + static void string_test_strnchr(struct kunit *test) { const char *test_string =3D "abcdefghijkl"; @@ -679,6 +708,7 @@ static struct kunit_case string_test_cases[] =3D { 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), --=20 2.25.1