Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/tests/core-kunit: handle alloc failures on damon_test_split_regions_of()

damon_test_split_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-9-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>

authored by

SeongJae Park and committed by
Andrew Morton
eded254c 0998d275

+20
+20
mm/damon/tests/core-kunit.h
··· 278 278 struct damon_target *t; 279 279 struct damon_region *r; 280 280 281 + if (!c) 282 + kunit_skip("ctx alloc fail"); 281 283 t = damon_new_target(); 284 + if (!t) { 285 + damon_destroy_ctx(c); 286 + kunit_skip(test, "target alloc fail"); 287 + } 282 288 r = damon_new_region(0, 22); 289 + if (!r) { 290 + damon_destroy_ctx(c); 291 + damon_free_target(t); 292 + kunit_skip(test, "region alloc fail"); 293 + } 283 294 damon_add_region(r, t); 284 295 damon_split_regions_of(t, 2, DAMON_MIN_REGION); 285 296 KUNIT_EXPECT_LE(test, damon_nr_regions(t), 2u); 286 297 damon_free_target(t); 287 298 288 299 t = damon_new_target(); 300 + if (!t) { 301 + damon_destroy_ctx(c); 302 + kunit_skip(test, "second target alloc fail"); 303 + } 289 304 r = damon_new_region(0, 220); 305 + if (!r) { 306 + damon_destroy_ctx(c); 307 + damon_free_target(t); 308 + kunit_skip(test, "second region alloc fail"); 309 + } 290 310 damon_add_region(r, t); 291 311 damon_split_regions_of(t, 4, DAMON_MIN_REGION); 292 312 KUNIT_EXPECT_LE(test, damon_nr_regions(t), 4u);