DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "longlong yan" <yanlonglong@kylinos.cn>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH v2] selftests/damon: Add missing NULL checks after malloc()
Date: Tue, 21 Jul 2026 06:12:34 +0000	[thread overview]
Message-ID: <20260721061234.B44CA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260721060542.326-1-yanlonglong@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly introduced error path returns -1 to prevent an OOM crash, but this does not coordinate with the Python test harnesses to actually skip the test or report a resource error. Instead, it causes tests to either silently pass (false positive) or crash with Python exceptions.
--

--- Patch [1]: [PATCH v2] selftests/damon: Add missing NULL checks after malloc() ---
commit c48bfd12db1afa969a2ab38d496264e74f1b6b1e
Author: longlong yan <yanlonglong@kylinos.cn>

selftests/damon: Add missing NULL checks after malloc()

This commit adds NULL checks after malloc() calls in access_memory.c and 
access_memory_even.c to prevent crashes during low-memory conditions.

> diff --git a/tools/testing/selftests/damon/access_memory.c b/tools/testing/selftests/damon/access_memory.c
> --- a/tools/testing/selftests/damon/access_memory.c
> +++ b/tools/testing/selftests/damon/access_memory.c
> @@ -38,8 +38,17 @@ int main(int argc, char *argv[])
>  		mode = ACCESS_MODE_REPEAT;
>  
>  	regions = malloc(sizeof(*regions) * nr_regions);
> -	for (i = 0; i < nr_regions; i++)
> +	if (!regions) {
> +		fprintf(stderr, "Failed to allocate regions array\n");
> +		return -1;

[Severity: Medium]
Will returning -1 here coordinate correctly with the Python test harnesses
like damos_quota.py and sysfs_update_schemes_tried_regions_wss_estimation.py?

If the Python scripts do not check the subprocess return code, an early exit
might leave data arrays empty. Depending on the script, this can either lead
to a Python IndexError (e.g., when accessing wss_collected in
pass_wss_estimation) or a silent test pass that masks the out of memory
condition entirely.

Should this return KSFT_SKIP (4) instead to properly notify the test harness,
or do the Python scripts need updating to verify the return code?

> +	}
> +	for (i = 0; i < nr_regions; i++) {
>  		regions[i] = malloc(sz_region);
> +		if (!regions[i]) {
> +			fprintf(stderr, "Failed to allocate region %d\n", i);
> +			return -1;
> +		}
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721060542.326-1-yanlonglong@kylinos.cn?part=1

  reply	other threads:[~2026-07-21  6:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260721025802.298-1-yanlonglong@kylinos.cn>
2026-07-21  4:31 ` [PATCH] selftests/damon: Add missing NULL checks after malloc() SJ Park
2026-07-21  6:05   ` [PATCH v2] " longlong yan
2026-07-21  6:12     ` sashiko-bot [this message]
2026-07-21  6:41     ` SJ 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=20260721061234.B44CA1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yanlonglong@kylinos.cn \
    /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