Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Bjorn Helgaas" <bhelgaas@google.com>,
	"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Tvrtko Ursulin" <tursulin@ursulin.net>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Michał Winiarski" <michal.winiarski@intel.com>,
	"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	"Anthony Pighin" <anthony.pighin@nokia.com>,
	linux-kernel@vger.kernel.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH v2 08/16] resource, kunit: Add test for release_leaf_resource()
Date: Sat,  5 Dec 2026 02:39:43 +0200	[thread overview]
Message-ID: <20261205003957.3304-9-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com>

release_leaf_resource() must not release a resource that has children,
and must leave the resource tree untouched when it refuses to release.

Add a test that checks the -EBUSY case with a child, the release once the
child is gone, and the -EINVAL case for a resource that is not in a tree.
Export release_leaf_resource() for the test when it is built as a module.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 kernel/resource.c       |  3 +++
 kernel/resource_kunit.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/kernel/resource.c b/kernel/resource.c
index 2ea3fddf8769..9761aae4f4f8 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -10,6 +10,8 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <kunit/visibility.h>
+
 #include <linux/export.h>
 #include <linux/errno.h>
 #include <linux/ioport.h>
@@ -345,6 +347,7 @@ int release_leaf_resource(struct resource *old)
 
 	return __release_resource(old, false);
 }
+EXPORT_SYMBOL_IF_KUNIT(release_leaf_resource);
 
 static bool is_type_match(struct resource *p, unsigned long flags, unsigned long desc)
 {
diff --git a/kernel/resource_kunit.c b/kernel/resource_kunit.c
index c8e49f757efa..d24d5e83b734 100644
--- a/kernel/resource_kunit.c
+++ b/kernel/resource_kunit.c
@@ -307,11 +307,38 @@ static void resource_test_release_not_in_tree(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, release_resource(&res), -EINVAL);
 }
 
+static void resource_test_release_leaf(struct kunit *test)
+{
+	struct resource root = DEFINE_RES_MEM_NAMED(0, SZ_64K, "test root");
+	struct resource res = DEFINE_RES_MEM_NAMED(0x1000, 0x1000, "test res");
+	struct resource child = DEFINE_RES_MEM_NAMED(0x1100, 0x100, "test child");
+
+	KUNIT_EXPECT_EQ(test, release_leaf_resource(&res), -EINVAL);
+
+	KUNIT_ASSERT_EQ(test, request_resource(&root, &res), 0);
+	KUNIT_ASSERT_EQ(test, request_resource(&res, &child), 0);
+
+	KUNIT_EXPECT_EQ(test, release_leaf_resource(&res), -EBUSY);
+	KUNIT_EXPECT_PTR_EQ(test, root.child, &res);
+	KUNIT_EXPECT_PTR_EQ(test, res.parent, &root);
+	KUNIT_EXPECT_PTR_EQ(test, res.child, &child);
+	KUNIT_EXPECT_PTR_EQ(test, child.parent, &res);
+
+	KUNIT_EXPECT_EQ(test, release_leaf_resource(&child), 0);
+	KUNIT_EXPECT_NULL(test, child.parent);
+	KUNIT_EXPECT_NULL(test, res.child);
+
+	KUNIT_EXPECT_EQ(test, release_leaf_resource(&res), 0);
+	KUNIT_EXPECT_NULL(test, res.parent);
+	KUNIT_EXPECT_NULL(test, root.child);
+}
+
 static struct kunit_case resource_test_cases[] = {
 	KUNIT_CASE(resource_test_union),
 	KUNIT_CASE(resource_test_intersection),
 	KUNIT_CASE(resource_test_region_intersects),
 	KUNIT_CASE(resource_test_release_not_in_tree),
+	KUNIT_CASE(resource_test_release_leaf),
 	{}
 };
 
@@ -321,5 +348,6 @@ static struct kunit_suite resource_test_suite = {
 };
 kunit_test_suite(resource_test_suite);
 
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
 MODULE_DESCRIPTION("I/O Port & Memory Resource manager unit tests");
 MODULE_LICENSE("GPL");
-- 
2.47.3


  parent reply	other threads:[~2026-12-05  0:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  0:39 [PATCH v2 00/16] PCI: Resource release fixes and improvements Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 01/16] PCI: Release all resources before restoring them in BAR resize rollback Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 02/16] PCI: Set new BAR Size only after releasing the BARs for BAR resize Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 03/16] PCI: Abort BAR resize only if saving the resized BAR fails Ilpo Järvinen
2026-12-05  1:04   ` sashiko-bot
2026-12-05  1:25     ` Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 04/16] PCI: Consistently use Header Type to detect bridge headers Ilpo Järvinen
2026-12-05  1:04   ` sashiko-bot
2026-12-05  0:39 ` [PATCH v2 05/16] resource: Check that the resource is in the tree when releasing it Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 06/16] resource, kunit: Add test for releasing a resource not in the tree Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 07/16] resource: Add release_leaf_resource() Ilpo Järvinen
2026-12-05  0:39 ` Ilpo Järvinen [this message]
2026-12-05  0:39 ` [PATCH v2 09/16] PCI: Do not release resources with children in pci_release_resource() Ilpo Järvinen
2026-12-05  1:04   ` sashiko-bot
2026-12-05  1:29     ` Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 10/16] resource: Rename next_resource() and for_each_resource() Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 11/16] resource: Make resource_lock and resource tree traversal available Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 12/16] resource: Add release_resource_locked() Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 13/16] PCI: Split pci_resource_post_release() out of pci_release_resource() Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 14/16] PCI: Add iterators for devices and resources in bus windows Ilpo Järvinen
2026-12-05  1:02   ` sashiko-bot
2026-12-05  1:12     ` Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 15/16] PCI: Keep the range of fixed resources when releasing them Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 16/16] PCI: Release only PCI resources when releasing a resource tree Ilpo Järvinen
2026-12-05  1:11   ` sashiko-bot
2026-12-05  1:57     ` Ilpo Järvinen
2026-12-05  0:50 ` ✗ CI.checkpatch: warning for PCI: Resource release fixes and improvements (rev2) Patchwork
2026-12-05  0:52 ` ✓ CI.KUnit: success " Patchwork
2026-12-05  1:27 ` ✓ Xe.CI.BAT: " Patchwork

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=20261205003957.3304-9-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=anthony.pighin@nokia.com \
    --cc=bhelgaas@google.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=matthew.brost@intel.com \
    --cc=michal.winiarski@intel.com \
    --cc=robh@kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tursulin@ursulin.net \
    --cc=ville.syrjala@linux.intel.com \
    /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