Re: [RFC PATCH 1/4] mm/damon/core: handle NULL ctx parameter in damon_call()

From: Gutierrez Asier

Date: Thu Aug 13 2026 - 04:53:37 EST


Hi SJ,

On 8/13/2026 6:49 AM, SJ Park wrote:
> When NULL damon_ctx pointer parameter is passed, damon_call() could do
> NULL dereference. The caller is responsible to avoid that. It is easy
> to forget, and there are many damon_call() callers. Meanwhile,
> damon_call() is never meant to be performance critical. It uses mutex
> and completion. Add the NULL pointer check inside damon_call() so that
> callers can pass the parameter without NULL checks.
>
> Signed-off-by: SJ Park <sj@xxxxxxxxxx>
> ---
> mm/damon/core.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 92631a36d7b51..5882f9c94c47f 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2188,6 +2188,8 @@ int damon_kdamond_pid(struct damon_ctx *ctx)
> */
> int damon_call(struct damon_ctx *ctx, struct damon_call_control *control)
> {
> + if (!ctx)
> + return -EINVAL;
> if (!control->repeat)
> init_completion(&control->completion);
> control->canceled = false;

I know that this is a minor optimization, but how about moving INIT_LIST_HEAD(&control->list)
to right before list_add_tail?

It doesn't make sense to initialize the list before checking call_controls_obsolete.

Maybe this suggestion should go in a different patch.

--
Asier Gutierrez
Huawei