2022-08-12 01:36:19

by Zeng Jingxiang

[permalink] [raw]
Subject: [PATCH] mm/damon: remove dead code in damon_lru_sort_enabled_store()

From: Zeng Jingxiang <[email protected]>

The variable damon_lru_sort_initialized is always true, causing the
corresponding conditional expression cannot be executed.

Assigning true to damon_lru_sort_initialized here
544 damon_lru_sort_initialized = true;

The value of damon_lru_sort_initialized is always true.
As a result, the following expression cannot be executed.

463 if (!damon_lru_sort_initialized)
464 return rc;

Fixes: 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting")
Signed-off-by: Zeng Jingxiang <[email protected]>
---
mm/damon/lru_sort.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 9de6f00a71c5..e2a656e1b728 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -450,8 +450,6 @@ static void damon_lru_sort_timer_fn(struct work_struct *work)
}
static DECLARE_DELAYED_WORK(damon_lru_sort_timer, damon_lru_sort_timer_fn);

-static bool damon_lru_sort_initialized;
-
static int damon_lru_sort_enabled_store(const char *val,
const struct kernel_param *kp)
{
@@ -460,9 +458,6 @@ static int damon_lru_sort_enabled_store(const char *val,
if (rc < 0)
return rc;

- if (!damon_lru_sort_initialized)
- return rc;
-
schedule_delayed_work(&damon_lru_sort_timer, 0);

return 0;
@@ -541,7 +536,6 @@ static int __init damon_lru_sort_init(void)

schedule_delayed_work(&damon_lru_sort_timer, 0);

- damon_lru_sort_initialized = true;
return 0;
}

--
2.36.1


2022-08-12 01:57:27

by SeongJae Park

[permalink] [raw]
Subject: Re: [PATCH] mm/damon: remove dead code in damon_lru_sort_enabled_store()

Hi Zeng,

On Fri, 12 Aug 2022 09:24:59 +0800 Zeng Jingxiang <[email protected]> wrote:

> From: Zeng Jingxiang <[email protected]>
>
> The variable damon_lru_sort_initialized is always true, causing the
> corresponding conditional expression cannot be executed.
>
> Assigning true to damon_lru_sort_initialized here
> 544 damon_lru_sort_initialized = true;

Before the assignment, the variable is set 'false'.

>
> The value of damon_lru_sort_initialized is always true.
> As a result, the following expression cannot be executed.
>
> 463 if (!damon_lru_sort_initialized)
> 464 return rc;

If this code is executed before the assignment, the expression can be executed.

Actually, there was a bug due to the absence of the variable. You may refer to
that for the detail:
https://lore.kernel.org/damon/[email protected]/T/#t


Thanks,
SJ

[...]