--- /dev/null
+From 3d443dd29a1db7efa587a4bb0c06a497e13ca9e4 Mon Sep 17 00:00:00 2001
+From: SeongJae Park <sj@kernel.org>
+Date: Sat, 1 Nov 2025 11:20:00 -0700
+Subject: mm/damon/tests/core-kunit: handle alloc failures on damon_test_merge_two()
+
+From: SeongJae Park <sj@kernel.org>
+
+commit 3d443dd29a1db7efa587a4bb0c06a497e13ca9e4 upstream.
+
+damon_test_merge_two() is assuming all dynamic memory allocation in it
+will succeed. Those are indeed likely in the real use cases since those
+allocations are too small to fail, but theoretically those could fail. In
+the case, inappropriate memory access can happen. Fix it by appropriately
+cleanup pre-allocated memory and skip the execution of the remaining tests
+in the failure cases.
+
+Link: https://lkml.kernel.org/r/20251101182021.74868-7-sj@kernel.org
+Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
+Signed-off-by: SeongJae Park <sj@kernel.org>
+Cc: Brendan Higgins <brendan.higgins@linux.dev>
+Cc: David Gow <davidgow@google.com>
+Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
+Cc: <stable@vger.kernel.org> [5.15+]
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ mm/damon/core-test.h | 10 ++++++++++
+ 1 file changed, 10 insertions(+)
+
+--- a/mm/damon/core-test.h
++++ b/mm/damon/core-test.h
+@@ -161,10 +161,20 @@ static void damon_test_merge_two(struct
+ int i;
+
+ t = damon_new_target(42);
++ if (!t)
++ kunit_skip(test, "target alloc fail");
+ r = damon_new_region(0, 100);
++ if (!r) {
++ damon_free_target(t);
++ kunit_skip(test, "region alloc fail");
++ }
+ r->nr_accesses = 10;
+ damon_add_region(r, t);
+ r2 = damon_new_region(100, 300);
++ if (!r2) {
++ damon_free_target(t);
++ kunit_skip(test, "second region alloc fail");
++ }
+ r2->nr_accesses = 20;
+ damon_add_region(r2, t);
+
--- /dev/null
+From 5e80d73f22043c59c8ad36452a3253937ed77955 Mon Sep 17 00:00:00 2001
+From: SeongJae Park <sj@kernel.org>
+Date: Sat, 1 Nov 2025 11:19:59 -0700
+Subject: mm/damon/tests/core-kunit: handle alloc failures on damon_test_split_at()
+
+From: SeongJae Park <sj@kernel.org>
+
+commit 5e80d73f22043c59c8ad36452a3253937ed77955 upstream.
+
+damon_test_split_at() is assuming all dynamic memory allocation in it will
+succeed. Those are indeed likely in the real use cases since those
+allocations are too small to fail, but theoretically those could fail. In
+the case, inappropriate memory access can happen. Fix it by appropriately
+cleanup pre-allocated memory and skip the execution of the remaining tests
+in the failure cases.
+
+Link: https://lkml.kernel.org/r/20251101182021.74868-6-sj@kernel.org
+Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
+Signed-off-by: SeongJae Park <sj@kernel.org>
+Cc: Brendan Higgins <brendan.higgins@linux.dev>
+Cc: David Gow <davidgow@google.com>
+Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
+Cc: <stable@vger.kernel.org> [5.15+]
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ mm/damon/core-test.h | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+--- a/mm/damon/core-test.h
++++ b/mm/damon/core-test.h
+@@ -128,8 +128,19 @@ static void damon_test_split_at(struct k
+ struct damon_target *t;
+ struct damon_region *r;
+
++ if (!c)
++ kunit_skip(test, "ctx alloc fail");
+ t = damon_new_target(42);
++ if (!t) {
++ damon_destroy_ctx(c);
++ kunit_skip(test, "target alloc fail");
++ }
+ r = damon_new_region(0, 100);
++ if (!r) {
++ damon_destroy_ctx(c);
++ damon_free_target(t);
++ kunit_skip(test, "region alloc fail");
++ }
+ damon_add_region(r, t);
+ damon_split_region_at(c, t, r, 25);
+ KUNIT_EXPECT_EQ(test, r->ar.start, 0ul);
--- /dev/null
+From 0998d2757218771c59d5ca59ccf13d1542a38f17 Mon Sep 17 00:00:00 2001
+From: SeongJae Park <sj@kernel.org>
+Date: Sat, 1 Nov 2025 11:20:01 -0700
+Subject: mm/damon/tests/core-kunit: handle alloc failures on dasmon_test_merge_regions_of()
+
+From: SeongJae Park <sj@kernel.org>
+
+commit 0998d2757218771c59d5ca59ccf13d1542a38f17 upstream.
+
+damon_test_merge_regions_of() is assuming all dynamic memory allocation in
+it will succeed. Those are indeed likely in the real use cases since
+those allocations are too small to fail, but theoretically those could
+fail. In the case, inappropriate memory access can happen. Fix it by
+appropriately cleanup pre-allocated memory and skip the execution of the
+remaining tests in the failure cases.
+
+Link: https://lkml.kernel.org/r/20251101182021.74868-8-sj@kernel.org
+Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
+Signed-off-by: SeongJae Park <sj@kernel.org>
+Cc: Brendan Higgins <brendan.higgins@linux.dev>
+Cc: David Gow <davidgow@google.com>
+Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
+Cc: <stable@vger.kernel.org> [5.15+]
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ mm/damon/core-test.h | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+--- a/mm/damon/core-test.h
++++ b/mm/damon/core-test.h
+@@ -209,8 +209,14 @@ static void damon_test_merge_regions_of(
+ int i;
+
+ t = damon_new_target(42);
++ if (!t)
++ kunit_skip(test, "target alloc fail");
+ for (i = 0; i < ARRAY_SIZE(sa); i++) {
+ r = damon_new_region(sa[i], ea[i]);
++ if (!r) {
++ damon_free_target(t);
++ kunit_skip(test, "region alloc fail");
++ }
+ r->nr_accesses = nrs[i];
+ damon_add_region(r, t);
+ }
--- /dev/null
+From e16fdd4f754048d6e23c56bd8d920b71e41e3777 Mon Sep 17 00:00:00 2001
+From: SeongJae Park <sj@kernel.org>
+Date: Sat, 1 Nov 2025 11:19:56 -0700
+Subject: mm/damon/tests/core-kunit: handle allocation failures in damon_test_regions()
+
+From: SeongJae Park <sj@kernel.org>
+
+commit e16fdd4f754048d6e23c56bd8d920b71e41e3777 upstream.
+
+damon_test_regions() is assuming all dynamic memory allocation in it will
+succeed. Those are indeed likely in the real use cases since those
+allocations are too small to fail, but theoretically those could fail. In
+the case, inappropriate memory access can happen. Fix it by appropriately
+cleanup pre-allocated memory and skip the execution of the remaining tests
+in the failure cases.
+
+Link: https://lkml.kernel.org/r/20251101182021.74868-3-sj@kernel.org
+Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
+Signed-off-by: SeongJae Park <sj@kernel.org>
+Cc: Brendan Higgins <brendan.higgins@linux.dev>
+Cc: David Gow <davidgow@google.com>
+Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
+Cc: <stable@vger.kernel.org> [5.15+]
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ mm/damon/core-test.h | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+--- a/mm/damon/core-test.h
++++ b/mm/damon/core-test.h
+@@ -20,11 +20,17 @@ static void damon_test_regions(struct ku
+ struct damon_target *t;
+
+ r = damon_new_region(1, 2);
++ if (!r)
++ kunit_skip(test, "region alloc fail");
+ KUNIT_EXPECT_EQ(test, 1ul, r->ar.start);
+ KUNIT_EXPECT_EQ(test, 2ul, r->ar.end);
+ KUNIT_EXPECT_EQ(test, 0u, r->nr_accesses);
+
+ t = damon_new_target(42);
++ if (!t) {
++ damon_free_region(r);
++ kunit_skip(test, "target alloc fail");
++ }
+ KUNIT_EXPECT_EQ(test, 0u, damon_nr_regions(t));
+
+ damon_add_region(r, t);
--- /dev/null
+From 0a63a0e7570b9b2631dfb8d836dc572709dce39e Mon Sep 17 00:00:00 2001
+From: SeongJae Park <sj@kernel.org>
+Date: Sat, 1 Nov 2025 11:20:13 -0700
+Subject: mm/damon/tests/vaddr-kunit: handle alloc failures on damon_test_split_evenly_succ()
+
+From: SeongJae Park <sj@kernel.org>
+
+commit 0a63a0e7570b9b2631dfb8d836dc572709dce39e upstream.
+
+damon_test_split_evenly_succ() is assuming all dynamic memory allocation
+in it will succeed. Those are indeed likely in the real use cases since
+those allocations are too small to fail, but theoretically those could
+fail. In the case, inappropriate memory access can happen. Fix it by
+appropriately cleanup pre-allocated memory and skip the execution of the
+remaining tests in the failure cases.
+
+Link: https://lkml.kernel.org/r/20251101182021.74868-20-sj@kernel.org
+Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
+Signed-off-by: SeongJae Park <sj@kernel.org>
+Cc: Brendan Higgins <brendan.higgins@linux.dev>
+Cc: David Gow <davidgow@google.com>
+Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
+Cc: <stable@vger.kernel.org> [5.15+]
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ mm/damon/vaddr-test.h | 9 ++++++++-
+ 1 file changed, 8 insertions(+), 1 deletion(-)
+
+--- a/mm/damon/vaddr-test.h
++++ b/mm/damon/vaddr-test.h
+@@ -290,10 +290,17 @@ static void damon_test_split_evenly_succ
+ unsigned long start, unsigned long end, unsigned int nr_pieces)
+ {
+ struct damon_target *t = damon_new_target(42);
+- struct damon_region *r = damon_new_region(start, end);
++ struct damon_region *r;
+ unsigned long expected_width = (end - start) / nr_pieces;
+ unsigned long i = 0;
+
++ if (!t)
++ kunit_skip(test, "target alloc fail");
++ r = damon_new_region(start, end);
++ if (!r) {
++ damon_free_target(t);
++ kunit_skip(test, "region alloc fail");
++ }
+ damon_add_region(r, t);
+ KUNIT_EXPECT_EQ(test,
+ damon_va_evenly_split_region(t, r, nr_pieces), 0);
mm-damon-tests-vaddr-kunit-handle-alloc-failures-in-damon_test_split_evenly_fail.patch
mm-damon-tests-vaddr-kunit-handle-alloc-failures-on-damon_do_test_apply_three_regions.patch
rdma-core-fix-kasan-slab-use-after-free-read-in-ib_register_device-problem.patch
+mm-damon-tests-vaddr-kunit-handle-alloc-failures-on-damon_test_split_evenly_succ.patch
+mm-damon-tests-core-kunit-handle-allocation-failures-in-damon_test_regions.patch
+mm-damon-tests-core-kunit-handle-alloc-failures-on-damon_test_split_at.patch
+mm-damon-tests-core-kunit-handle-alloc-failures-on-dasmon_test_merge_regions_of.patch
+mm-damon-tests-core-kunit-handle-alloc-failures-on-damon_test_merge_two.patch