From: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
To: o-takashi@sakamocchi.jp
Cc: linux-kernel@vger.kernel.org,
linux1394-devel@lists.sourceforge.net,
sreekuttan2156239@gmail.com
Subject: [PATCH v2 2/2] firewire: Add KUnit tests for CSR iterator
Date: Tue, 3 Nov 2026 15:14:21 +0000 [thread overview]
Message-ID: <20261103151421.7248-3-sreekuttan2156239@gmail.com> (raw)
In-Reply-To: <20261103151421.7248-1-sreekuttan2156239@gmail.com>
Add a separate KUnit test suite for the CSR iterator.
Test iteration over valid entries, an empty directory,
and calling the iterator after reaching the end.
Add a separate Kconfig option to enable the iterator tests
and update the KUnit configuration.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
drivers/firewire/.kunitconfig | 1 +
drivers/firewire/Kconfig | 12 +++
drivers/firewire/config-rom-iterator-test.c | 93 +++++++++++++++++++++
drivers/firewire/core-device.c | 4 +
4 files changed, 110 insertions(+)
create mode 100644 drivers/firewire/config-rom-iterator-test.c
diff --git a/drivers/firewire/.kunitconfig b/drivers/firewire/.kunitconfig
index ee9129081cef..e36dd34fd344 100644
--- a/drivers/firewire/.kunitconfig
+++ b/drivers/firewire/.kunitconfig
@@ -8,3 +8,4 @@ CONFIG_FIREWIRE_KUNIT_SELF_ID_SEQUENCE_HELPER_TEST=y
CONFIG_FIREWIRE_KUNIT_OHCI_SERDES_TEST=y
CONFIG_FIREWIRE_KUNIT_NODE_TREE_TEST=y
CONFIG_FIREWIRE_KUNIT_CONFIG_ROM_PARSER_AND_GENERATOR_TEST=y
+CONFIG_FIREWIRE_KUNIT_CONFIG_ROM_ITERATOR_TEST=y
diff --git a/drivers/firewire/Kconfig b/drivers/firewire/Kconfig
index 7e1d4b2c440b..e67c2524c799 100644
--- a/drivers/firewire/Kconfig
+++ b/drivers/firewire/Kconfig
@@ -112,6 +112,18 @@ config FIREWIRE_KUNIT_CONFIG_ROM_PARSER_AND_GENERATOR_TEST
For more information on KUnit and unit tests in general, refer
to the KUnit documentation in Documentation/dev-tools/kunit/.
+config FIREWIRE_KUNIT_CONFIG_ROM_ITERATOR_TEST
+ tristate "KUnit tests for config ROM iterator" if !KUNIT_ALL_TESTS
+ depends on FIREWIRE && KUNIT
+ default KUNIT_ALL_TESTS
+ help
+ This builds KUnit tests for the configuration ROM iterator used
+ by the FireWire subsystem.
+
+ The tests check iteration over valid entries, handling empty
+ directories, and calls to the iterator after reaching the end of
+ a directory
+
config FIREWIRE_OHCI
tristate "OHCI-1394 controllers"
depends on PCI && FIREWIRE
diff --git a/drivers/firewire/config-rom-iterator-test.c b/drivers/firewire/config-rom-iterator-test.c
new file mode 100644
index 000000000000..8c846f2f2011
--- /dev/null
+++ b/drivers/firewire/config-rom-iterator-test.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2026 Sreeraj S Kurup
+ *
+ * config-rom-iterator-test.c - KUnit tests for configuration ROM iterator.
+ */
+
+#include <kunit/test.h>
+
+static void test_csr_iterator_with_valid_entries(struct kunit *test)
+{
+ static const u32 directory[] = {
+ 0x00020000, /* Two entries. */
+ 0x12001234,
+ 0x34005678,
+ };
+ struct fw_csr_iterator ci;
+ int key, value;
+
+ fw_csr_iterator_init(&ci, directory);
+
+ KUNIT_EXPECT_TRUE(test,
+ fw_csr_iterator_next(&ci, &key, &value));
+ KUNIT_EXPECT_EQ(test, key, 0x12);
+ KUNIT_EXPECT_EQ(test, value, 0x001234);
+
+ KUNIT_EXPECT_TRUE(test,
+ fw_csr_iterator_next(&ci, &key, &value));
+ KUNIT_EXPECT_EQ(test, key, 0x34);
+ KUNIT_EXPECT_EQ(test, value, 0x005678);
+
+ KUNIT_EXPECT_FALSE(test,
+ fw_csr_iterator_next(&ci, &key, &value));
+}
+
+static void test_csr_iterator_at_end(struct kunit *test)
+{
+ static const u32 directory[] = {
+ 0x00010000, /* One entry. */
+ 0x12001234,
+ };
+ struct fw_csr_iterator ci;
+ int key, value;
+
+ fw_csr_iterator_init(&ci, directory);
+
+ KUNIT_ASSERT_TRUE(test,
+ fw_csr_iterator_next(&ci, &key, &value));
+
+ KUNIT_EXPECT_EQ(test, key, 0x12);
+ KUNIT_EXPECT_EQ(test, value, 0x001234);
+
+ KUNIT_EXPECT_PTR_EQ(test, ci.p, ci.end);
+
+ /*
+ * Calling next() after the last entry must not
+ * advance the iterator beyond its end.
+ */
+ KUNIT_EXPECT_FALSE(test,
+ fw_csr_iterator_next(&ci, &key, &value));
+
+ KUNIT_EXPECT_PTR_EQ(test, ci.p, ci.end);
+}
+
+static void test_csr_iterator_empty_directory(struct kunit *test)
+{
+ static const u32 directory[] = {
+ 0x00000000,
+ };
+ struct fw_csr_iterator ci;
+ int key, value;
+
+ fw_csr_iterator_init(&ci, directory);
+
+ KUNIT_EXPECT_FALSE(test,
+ fw_csr_iterator_next(&ci, &key, &value));
+
+ KUNIT_EXPECT_PTR_EQ(test, ci.p, ci.end);
+}
+
+static struct kunit_case csr_iterator_test_cases[] = {
+ KUNIT_CASE(test_csr_iterator_with_valid_entries),
+ KUNIT_CASE(test_csr_iterator_at_end),
+ KUNIT_CASE(test_csr_iterator_empty_directory),
+ {}
+};
+
+static struct kunit_suite csr_iterator_test_suite = {
+ .name = "firewire-config-rom-iterator",
+ .test_cases = csr_iterator_test_cases,
+};
+
+kunit_test_suite(csr_iterator_test_suite);
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index 36667841ca3c..5d5ad4f41ab5 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -1450,3 +1450,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
#ifdef CONFIG_FIREWIRE_KUNIT_CONFIG_ROM_PARSER_AND_GENERATOR_TEST
#include "config-rom-parser-test.c"
#endif
+
+#ifdef CONFIG_FIREWIRE_KUNIT_CONFIG_ROM_ITERATOR_TEST
+#include "config-rom-iterator-test.c"
+#endif
--
2.55.0
prev parent reply other threads:[~2026-11-03 15:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 6:53 [PATCH] firewire: Fix out-of-bounds access in " Sreeraj S Kurup
2026-11-03 4:24 ` Takashi Sakamoto
2026-11-03 15:14 ` [PATCH v2 0/2] " Sreeraj S Kurup
2026-11-03 15:14 ` [PATCH v2 1/2] " Sreeraj S Kurup
2026-11-03 15:14 ` Sreeraj S Kurup [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261103151421.7248-3-sreekuttan2156239@gmail.com \
--to=sreekuttan2156239@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux1394-devel@lists.sourceforge.net \
--cc=o-takashi@sakamocchi.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®