From: Kunwu Chan <kunwu.chan@gmail.com>
To: SJ Park <sj@kernel.org>
Cc: Kunwu Chan <kunwu.chan@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [RFC PATCH v2 3/8] mm/damon/core: return an error from damos_commit_filter_arg()
Date: Tue, 15 Sep 2026 11:30:49 +0800 [thread overview]
Message-ID: <20260915033050.1579457-1-kunwu.chan@gmail.com> (raw)
In-Reply-To: <20260913171706.103052-4-sj@kernel.org>
On Sun, 13 Sep 2026 10:17:00 -0700 SJ Park <sj@kernel.org> wrote:
> damos_commit_filter_arg() is supposed to always succeed. It may not in
> future, for example, if the given filter is invalid. Prepare the case
> by modifying its signature to return an error when it failed. Also pipe
> the return value to its callers and let them handle the error.
>
> Signed-off-by: SJ Park <sj@kernel.org>
> ---
> mm/damon/core.c | 41 ++++++++++++++++++++++++++++-------------
> 1 file changed, 28 insertions(+), 13 deletions(-)
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 3d7a973ea8b6f..ea7d8d5a4abf6 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -1317,7 +1317,7 @@ static struct damos_filter *damos_nth_ops_filter(int n, struct damos *s)
> return NULL;
> }
>
> -static void damos_commit_filter_arg(
> +static int damos_commit_filter_arg(
> struct damos_filter *dst, struct damos_filter *src)
> {
> switch (dst->type) {
> @@ -1340,28 +1340,32 @@ static void damos_commit_filter_arg(
> default:
> break;
> }
> + return 0;
> }
>
> -static void damos_commit_filter(
> +static int damos_commit_filter(
> struct damos_filter *dst, struct damos_filter *src)
> {
> dst->type = src->type;
> dst->matching = src->matching;
> dst->allow = src->allow;
> - damos_commit_filter_arg(dst, src);
> + return damos_commit_filter_arg(dst, src);
> }
>
> static int damos_commit_core_filters(struct damos *dst, struct damos *src)
> {
> struct damos_filter *dst_filter, *next, *src_filter, *new_filter;
> - int i = 0, j = 0;
> + int i = 0, j = 0, err;
>
> damos_for_each_core_filter_safe(dst_filter, next, dst) {
> src_filter = damos_nth_core_filter(i++, src);
> - if (src_filter)
> - damos_commit_filter(dst_filter, src_filter);
> - else
> + if (src_filter) {
> + err = damos_commit_filter(dst_filter, src_filter);
> + if (err)
> + return err;
> + } else {
> damos_destroy_filter(dst_filter);
> + }
> }
>
> damos_for_each_core_filter_safe(src_filter, next, src) {
> @@ -1373,7 +1377,11 @@ static int damos_commit_core_filters(struct damos *dst, struct damos *src)
> src_filter->allow);
> if (!new_filter)
> return -ENOMEM;
> - damos_commit_filter_arg(new_filter, src_filter);
> + err = damos_commit_filter_arg(new_filter, src_filter);
> + if (err) {
> + damos_destroy_filter(new_filter);
> + return err;
> + }
> damos_add_filter(dst, new_filter);
> }
> return 0;
> @@ -1382,14 +1390,17 @@ static int damos_commit_core_filters(struct damos *dst, struct damos *src)
> static int damos_commit_ops_filters(struct damos *dst, struct damos *src)
> {
> struct damos_filter *dst_filter, *next, *src_filter, *new_filter;
> - int i = 0, j = 0;
> + int i = 0, j = 0, err;
>
> damos_for_each_ops_filter_safe(dst_filter, next, dst) {
> src_filter = damos_nth_ops_filter(i++, src);
> - if (src_filter)
> - damos_commit_filter(dst_filter, src_filter);
> - else
> + if (src_filter) {
> + err = damos_commit_filter(dst_filter, src_filter);
> + if (err)
> + return err;
> + } else {
> damos_destroy_filter(dst_filter);
> + }
> }
>
> damos_for_each_ops_filter_safe(src_filter, next, src) {
> @@ -1401,7 +1412,11 @@ static int damos_commit_ops_filters(struct damos *dst, struct damos *src)
> src_filter->allow);
> if (!new_filter)
> return -ENOMEM;
> - damos_commit_filter_arg(new_filter, src_filter);
> + err = damos_commit_filter_arg(new_filter, src_filter);
> + if (err) {
> + damos_destroy_filter(new_filter);
> + return err;
> + }
I re-checked this version, and the error return from
damos_commit_filter_arg() is now handled at all call sites,
including the new-filter paths.
Reviewed-by: Kunwu Chan <kunwu.chan@gmail.com>
I'll take another look at the remaining patches.
Thanks,
Kunwu
> damos_add_filter(dst, new_filter);
> }
> return 0;
> --
> 2.47.3
>
Sent using hkml (https://github.com/sjp38/hackermail)
next prev parent reply other threads:[~2026-09-15 3:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-13 17:16 [RFC PATCH v2 0/8] mm/damon: move damos filter range arguments validation to core SJ Park
2026-09-13 17:16 ` [RFC PATCH v2 1/8] mm/damon/sysfs-schemes: read sysfs_filter->addr_range only once SJ Park
2026-09-13 17:16 ` [RFC PATCH v2 2/8] mm/damon/sysfs-schemes: read sysfs_filter->sz_range " SJ Park
2026-09-13 17:17 ` [RFC PATCH v2 3/8] mm/damon/core: return an error from damos_commit_filter_arg() SJ Park
2026-09-15 3:30 ` Kunwu Chan [this message]
2026-09-13 17:17 ` [RFC PATCH v2 4/8] mm/damon/core: disallow max < min damos filter range arguments commit SJ Park
2026-09-13 17:17 ` [RFC PATCH v2 5/8] mm/damon/sysfs-schemes: drop centralized filter range arg validations SJ Park
2026-09-13 17:17 ` [RFC PATCH v2 6/8] mm/damon/sysfs-schemes: use switch-case in add_scheme_filters() SJ Park
2026-09-13 17:17 ` [RFC PATCH v2 7/8] mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input SJ Park
2026-09-13 17:17 ` [RFC PATCH v2 8/8] mm/damon/core-kunit: test invalid damos filter commits 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=20260915033050.1579457-1-kunwu.chan@gmail.com \
--to=kunwu.chan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sj@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®