From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796181368; b=O2DF43/MjbMI7GMa5i9HjyEWuHu1QyhxTRIAmPlAavc04tRGOOhup+iJQiecQ9bnGcUU Ar35JvWzCK/+BPvhUJgSV8H36gATuJY+ZxcOx3aTFDC0m5qPDE0gjXY8KTYOxnUqtOSHu WESrSevp6FSvs+mox+TC82jjVKs08fZRav7zNUbsSbH57iW/f92oEkisHQHIJZOTjxY2T 0rGUON6x9w5ogwBi7tcr9RVJuBcq/HIjR7MNBkGdBFN6AY5GoG3qrkh3sKMswi+RLv6lg Pn2+gq0ee1cMQo9Sq6BJ9N/ULTj4PJkwzGSJchLPFJKu0iRkA+pSohM1/oWfn/zigjw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181368; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=1IfjGRw+PqlT8e76wbcgvy4WpWD4meSsALFJ2YLoOEk=; b=q3bnF+OCYjrStw1xtg4a6tOruflLwSNbG1qpzXnMsLBZWYPYzGiEagx1sqgIWfVgk8Sz ebVkVO3OY1L75GLa4N9+I8Z9yhalEbR72aqay+KITSzjXp2benAoe4bVcOE2zyAyyRtkJ fmUMTpHaI0oDdjdfzV/btXSkh08p7T18lgcLNJOhGnMp7oZFgog+dbhXMUxT4jpGUyXhe UMSKBy/8CF50e4J7aZMuYb24hIoqJ24jRomqhZ9FQ2XfiJyGfW3TMLbDWU+XWuBegc8bz gQdI2BQLdOmNspVUEmSKbbcdTvIKCskvZbow14KxujWkHDAfHSG9obbN5kHptoSl9nQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J27bsfWG; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAAAC606A336 for ; Wed, 2 Dec 2026 03:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J27bsfWG Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796181368; b=0zHcoRXgzUgRNH9mQhEWW02rI/escAEVr3fkQSZmIw+AlXCUx2D7GL2w10gFFzl8iXqj HdcwKmr3mWw6pERHxMm8q7JJSUW2r2o/mdMpXogE9tqgynd6jLF1HZHoEMgpe7wGe9dN1 K9htoaWas+pJQmmZHhMG46tFoSe4A1lBhxZ+B3Ex+9bxDKxk1Nvfuu6bbh4g5jjOtWbAI ZurJOitogX7bOqWIw/oYvBN3Ie0ARrybeEmH1yRVFEbAmS09t/uosOb7JTVWPw8V5Ad/Q a51jTUNF/zkjf2hM2jNC7L0QEeae+6SNKAw3enuhhcdshiojQwNbbTzb8kfgRLpqS4Q== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796181368; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:X-Mailer:X-Developer-Signature: X-Developer-Key:X-Endpoint-Received:X-Original-From:Reply-To: Content-Transfer-Encoding; bh=1IfjGRw+PqlT8e76wbcgvy4WpWD4meSsALFJ2YLoOEk=; b=ECjMF4qnab0f9MAT+9EdxNhc1CQ9bKpN1Uwdreieez/WyTzXIaAy8izhJVBqLcdlzWkJ qCNFuaJRJBXy4QsrL+maNjqXC5IFN9xSmFlewoucXUIMIkHG6gYN0ny6R0EWvgW75jF40 RXJu9EFm9VRmIaTYXaYDyqBbFB5sZTCn7AlElVwkUQZ3ttR0gWZEOwc2q68dQAnSyQJOd r2+0kjA3QrAPigSHhfAEkUo43R0VR38EUGATkBYoYMFJ+QTGEUYIWT5QxM1Vd5VT9meiC /O+cRFImltuy0bwLN8V6HimDBMKfmKlL+rwH2lCz1NAJ/Xuh9BzKRK15PocZCaNCJNw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id A53941F0089A; Wed, 2 Dec 2026 03:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796181368; bh=1IfjGRw+PqlT8e76wbcgvy4WpWD4meSsALFJ2YLoOEk=; h=From:Date:Subject:References:In-Reply-To:To:Reply-To; b=J27bsfWGQleJ/ouqBrcrhMXe/rTM1e9e0+LTFZIM0dOZzykHVqWG9z6ROIk1U0v+N 5YMN/4S2aV0v7q9tVggvefdn8sx+njBwplbdB5UIiNThiutCbuSnSv3jKKvIqUp1Mc E1Zq1Avu9FrcOnFTgDQhqNVpZKiYlL/gg0Ie+NWPWWnyj71zZ+F93+c0lYX0xyfprO Zun3h5oagNIdGV3lGtcSzli2hIe1oTq6qUgKLRTsz4xc8I2CEEACl2y9PmGNhNgi/7 iIpGAos6NnQSElgbodRZMdIrXHfMK9T9ezqTd9CalVpZvoakNXBOyEGXayj7OQszAE v+5HSbpeTn65A== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 332B34F1EA; Wed, 2 Dec 2026 03:15:55 +0000 (UTC) From: Felix Huang via B4 Relay Date: Tue, 01 Dec 2026 22:17:21 -0500 Subject: [PATCH 1/2] kfifo: clean up KUnit test style X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261201-kfifo-kunit-tests-v1-1-8d2a4ff45ad4@gmail.com> References: <20261201-kfifo-kunit-tests-v1-0-8d2a4ff45ad4@gmail.com> In-Reply-To: <20261201-kfifo-kunit-tests-v1-0-8d2a4ff45ad4@gmail.com> To: linux-kernel@vger.kernel.org, Felix Huang X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796181444; l=5577; i=akafelixab@gmail.com; s=20261128; h=from:subject:message-id; bh=oGNYRFWf2PKyhuzRKVNbs6gR0SyEqKSFdNyHlvf+/dw=; b=Am+MdIvBGLDKHQoqnvIXYonEmchhLsBk9sqkg8bQawlAlYS+VZxkbjq6/qWacnP/7NblrWWdT pbPei1/oyR1DP6afEx37HyAtTCjQ/S9aTyzF+WTcYBDbMA14Wo1TXpo X-Developer-Key: i=akafelixab@gmail.com; a=ed25519; pk=Axl3BM1UWa+m0/AWcEhRIdIk/WY9FnY4wZkyQn64uVY= X-Endpoint-Received: by B4 Relay for akafelixab@gmail.com/20261128 with auth_id=1670 X-Original-From: Felix Huang Reply-To: akafelixab@gmail.com Content-Transfer-Encoding: 7bit From: Felix Huang Clean up the kfifo KUnit test to follow the kernel coding style. Replace // comments with the preferred /* */ comment style and remove comments that merely restate the following code. Move loop counter declarations to the beginning of their functions and use ARRAY_SIZE() instead of hardcoded element counts. Also fix the misspelled test name "initiliaze" and update its corresponding KUNIT_CASE() entry. No functional change is intended. Signed-off-by: Felix Huang --- lib/tests/kfifo_kunit.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/tests/kfifo_kunit.c b/lib/tests/kfifo_kunit.c index a85eedc31..dbef9d2c6 100644 --- a/lib/tests/kfifo_kunit.c +++ b/lib/tests/kfifo_kunit.c @@ -38,12 +38,13 @@ static void kfifo_test_define_should_define_an_empty_fifo(struct kunit *test) static void kfifo_test_len_should_ret_n_of_stored_elements(struct kunit *test) { u8 buffer1[N_ELEMENTS]; - - for (int i = 0; i < N_ELEMENTS; i++) - buffer1[i] = i + 1; + int i; DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); + for (i = 0; i < N_ELEMENTS; i++) + buffer1[i] = i + 1; + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 0); kfifo_in(&my_fifo, buffer1, N_ELEMENTS); @@ -60,19 +61,20 @@ static void kfifo_test_put_should_insert_and_get_should_pop(struct kunit *test) { u8 out_data = 0; int processed_elements; + int i; u8 elements[] = { 3, 5, 11 }; DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); - // If the fifo is empty, get returns 0 + /* An empty FIFO returns no element. */ processed_elements = kfifo_get(&my_fifo, &out_data); KUNIT_EXPECT_EQ(test, processed_elements, 0); KUNIT_EXPECT_EQ(test, out_data, 0); - for (int i = 0; i < 3; i++) + for (i = 0; i < ARRAY_SIZE(elements); i++) kfifo_put(&my_fifo, elements[i]); - for (int i = 0; i < 3; i++) { + for (i = 0; i < ARRAY_SIZE(elements); i++) { processed_elements = kfifo_get(&my_fifo, &out_data); KUNIT_EXPECT_EQ(test, processed_elements, 1); KUNIT_EXPECT_EQ(test, out_data, elements[i]); @@ -121,7 +123,7 @@ static void kfifo_test_dec_init_should_define_an_empty_fifo(struct kunit *test) INIT_KFIFO(my_fifo); - // my_fifo is a struct with an inplace buffer + /* my_fifo is a struct with an inplace buffer */ KUNIT_EXPECT_FALSE(test, __is_kfifo_ptr(&my_fifo)); KUNIT_EXPECT_TRUE(test, kfifo_initialized(&my_fifo)); @@ -129,16 +131,15 @@ static void kfifo_test_dec_init_should_define_an_empty_fifo(struct kunit *test) static void kfifo_test_define_should_equal_declare_init(struct kunit *test) { - // declare a variable my_fifo of type struct kfifo of u8 DECLARE_KFIFO(my_fifo1, u8, KFIFO_SIZE); - // initialize the my_fifo variable INIT_KFIFO(my_fifo1); - // DEFINE_KFIFO declares the variable with the initial value - // essentially the same as calling DECLARE_KFIFO and INIT_KFIFO + /* + * DEFINE_KFIFO() both declares and initializes the FIFO, equivalent to + * DECLARE_KFIFO() followed by INIT_KFIFO(). + */ DEFINE_KFIFO(my_fifo2, u8, KFIFO_SIZE); - // my_fifo1 and my_fifo2 have the same size KUNIT_EXPECT_EQ(test, sizeof(my_fifo1), sizeof(my_fifo2)); KUNIT_EXPECT_EQ(test, kfifo_initialized(&my_fifo1), kfifo_initialized(&my_fifo2)); @@ -146,22 +147,20 @@ static void kfifo_test_define_should_equal_declare_init(struct kunit *test) kfifo_is_empty(&my_fifo2)); } -static void kfifo_test_alloc_should_initiliaze_a_ptr_fifo(struct kunit *test) +static void kfifo_test_alloc_should_initialize_a_ptr_fifo(struct kunit *test) { int ret; DECLARE_KFIFO_PTR(my_fifo, u8); INIT_KFIFO(my_fifo); - // kfifo_initialized returns false signaling the buffer pointer is NULL + /* kfifo_initialized returns false signaling the buffer pointer is NULL */ KUNIT_EXPECT_FALSE(test, kfifo_initialized(&my_fifo)); - // kfifo_alloc allocates the buffer ret = kfifo_alloc(&my_fifo, KFIFO_SIZE, GFP_KERNEL); KUNIT_EXPECT_EQ_MSG(test, ret, 0, "Memory allocation should succeed"); KUNIT_EXPECT_TRUE(test, kfifo_initialized(&my_fifo)); - // kfifo_free frees the buffer kfifo_free(&my_fifo); } @@ -172,7 +171,7 @@ static void kfifo_test_peek_should_not_remove_elements(struct kunit *test) DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); - // If the fifo is empty, peek returns 0 + /* If the fifo is empty, peek returns 0 */ processed_elements = kfifo_peek(&my_fifo, &out_data); KUNIT_EXPECT_EQ(test, processed_elements, 0); @@ -188,9 +187,11 @@ static void kfifo_test_peek_should_not_remove_elements(struct kunit *test) KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 3); - // Using peek doesn't remove the element - // so the read element and the fifo length - // remains the same + /* + * Using peek doesn't remove the element + * so the read element and the fifo length + * remains the same + */ processed_elements = kfifo_peek(&my_fifo, &out_data); KUNIT_EXPECT_EQ(test, processed_elements, 1); KUNIT_EXPECT_EQ(test, out_data, 3); @@ -207,7 +208,7 @@ static struct kunit_case kfifo_test_cases[] = { KUNIT_CASE(kfifo_test_out_should_pop_multiple_elements), KUNIT_CASE(kfifo_test_dec_init_should_define_an_empty_fifo), KUNIT_CASE(kfifo_test_define_should_equal_declare_init), - KUNIT_CASE(kfifo_test_alloc_should_initiliaze_a_ptr_fifo), + KUNIT_CASE(kfifo_test_alloc_should_initialize_a_ptr_fifo), KUNIT_CASE(kfifo_test_peek_should_not_remove_elements), {}, }; -- 2.56.1