From: SeongJae Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SeongJae Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [RFC PATCH 04/14] mm/damon/tests/vaddr-kunit: replace damon_add_region() with damon_set_regions()
Date: Wed, 20 May 2026 06:53:57 -0700 [thread overview]
Message-ID: <20260520135358.169417-1-sj@kernel.org> (raw)
In-Reply-To: <20260520063841.7C04C1F000E9@smtp.kernel.org>
On Wed, 20 May 2026 06:38:41 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [Medium] The dynamically allocated `ranges` array is never freed, resulting in a memory leak.
> - [Medium] The return value of `damon_set_regions()` is ignored, which can lead to a NULL pointer dereference if memory allocation fails.
> --
>
> commit 178b94e956635731d61e076b1aa09699c5f9b686
> Author: SeongJae Park <sj@kernel.org>
>
> mm/damon/tests/vaddr-kunit: replace damon_add_region() with damon_set_regions()
>
> This commit updates the DAMON vaddr unit tests to use damon_set_regions()
> for setting up target region boundaries. This replaces the manual setup
> loop that previously used damon_add_region().
>
> > diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
> > index 98e734d77d517..23be9c3be75fa 100644
> > --- a/mm/damon/tests/vaddr-kunit.h
> > +++ b/mm/damon/tests/vaddr-kunit.h
> [ ... ]
> > @@ -132,20 +132,24 @@ static void damon_do_test_apply_three_regions(struct kunit *test,
> > unsigned long *expected, int nr_expected)
> > {
> > struct damon_target *t;
> > + struct damon_addr_range *ranges;
> > struct damon_region *r;
> > int i;
> >
> > t = damon_new_target();
> > if (!t)
> > kunit_skip(test, "target alloc fail");
> > +
> > + ranges = kmalloc_array(nr_regions / 2, sizeof(*ranges), GFP_KERNEL);
> > + if (!ranges) {
> > + damon_destroy_target(t, NULL);
> > + kunit_skip(test, "ranges alloc fail");
> > + }
> > for (i = 0; i < nr_regions / 2; i++) {
> > - r = damon_new_region(regions[i * 2], regions[i * 2 + 1]);
> > - if (!r) {
> > - damon_destroy_target(t, NULL);
> > - kunit_skip(test, "region alloc fail");
> > - }
> > - damon_add_region(r, t);
> > + ranges[i].start = regions[i * 2];
> > + ranges[i].end = regions[i * 2 + 1];
> > }
> > + damon_set_regions(t, ranges, nr_regions / 2, DAMON_MIN_REGION_SZ);
>
> [Severity: Medium]
> Is it safe to ignore the return value of damon_set_regions() here?
>
> If damon_set_regions() encounters an allocation failure, it returns -ENOMEM,
> leaving the target with fewer regions than intended. Could this lead to a
> NULL pointer dereference in the subsequent test code if it attempts to access
> regions that failed to allocate?
Nice catch. I will check the results and skip in the case of failure.
>
> [Severity: Medium]
> Does this code leak the ranges array?
>
> It appears ranges is dynamically allocated via kmalloc_array() but is never
> freed before the function returns, and damon_set_regions() does not take
> ownership of this memory.
Good finding. I will free it.
>
> >
> > damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION_SZ);
> >
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260520062858.167011-1-sj@kernel.org?part=4
Thanks,
SJ
next prev parent reply other threads:[~2026-05-20 13:54 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 6:28 [RFC PATCH 00/14] mm/damon: minor improvements for code readability and tests SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 01/14] mm/damon/core: safely handle no region case in damon_set_regions() SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 02/14] mm/damon/core: do not use region out of a loop " SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 03/14] samples/damon/mtier: replace damon_add_region() with damon_set_regions() SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 04/14] mm/damon/tests/vaddr-kunit: " SeongJae Park
2026-05-20 6:38 ` sashiko-bot
2026-05-20 13:53 ` SeongJae Park [this message]
2026-05-20 6:28 ` [RFC PATCH 05/14] mm/damon/core: hide damon_add_region() SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 06/14] mm/damon/core: hide damon_insert_region() SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 07/14] mm/damon/core: hide damon_destroy_region() SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 08/14] mm/damon/core: add kdamond_call() debug_sanity check SeongJae Park
2026-05-20 6:52 ` sashiko-bot
2026-05-20 13:58 ` SeongJae Park
2026-05-20 14:04 ` SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 09/14] mm/damon/core: remove damon_verify_nr_regions() SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 10/14] mm/damon/tests/core-kunit: add damon_set_regions() test cases SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 11/14] selftests/damon/sysfs.py: stop kdamonds before failing SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 12/14] selftests/damon/sysfs.sh: test monitoring intervals goal dir SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 13/14] selftests/damon/sysfs.sh: test addr_unit file existence SeongJae Park
2026-05-20 6:41 ` sashiko-bot
2026-05-20 14:08 ` SeongJae Park
2026-05-20 14:20 ` SeongJae Park
2026-05-20 6:28 ` [RFC PATCH 14/14] selftests/damon/sysfs.sh: test pause " SeongJae Park
2026-05-20 6:42 ` sashiko-bot
2026-05-20 14:11 ` SeongJae Park
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=20260520135358.169417-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-bot@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.