damos_commit_dests() receives 'struct damos' pointers, while it uses
only their ->migrate_dests fields.  This makes code unnecessarily
difficult to read.  It also makes unit tests writing complicated.
Refactor the function to receive pointers to the ->migrate_dests fields.

Signed-off-by: SeongJae Park <[email protected]>
---
 mm/damon/core.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 06ad359024ad..a14cc73c2cab 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1000,36 +1000,32 @@ static void damos_set_filters_default_reject(struct 
damos *s)
                damos_filters_default_reject(&s->ops_filters);
 }
 
-static int damos_commit_dests(struct damos *dst, struct damos *src)
+static int damos_commit_dests(struct damos_migrate_dests *dst,
+               struct damos_migrate_dests *src)
 {
-       struct damos_migrate_dests *dst_dests, *src_dests;
+       if (dst->nr_dests != src->nr_dests) {
+               kfree(dst->node_id_arr);
+               kfree(dst->weight_arr);
 
-       dst_dests = &dst->migrate_dests;
-       src_dests = &src->migrate_dests;
-
-       if (dst_dests->nr_dests != src_dests->nr_dests) {
-               kfree(dst_dests->node_id_arr);
-               kfree(dst_dests->weight_arr);
-
-               dst_dests->node_id_arr = kmalloc_array(src_dests->nr_dests,
-                       sizeof(*dst_dests->node_id_arr), GFP_KERNEL);
-               if (!dst_dests->node_id_arr) {
-                       dst_dests->weight_arr = NULL;
+               dst->node_id_arr = kmalloc_array(src->nr_dests,
+                       sizeof(*dst->node_id_arr), GFP_KERNEL);
+               if (!dst->node_id_arr) {
+                       dst->weight_arr = NULL;
                        return -ENOMEM;
                }
 
-               dst_dests->weight_arr = kmalloc_array(src_dests->nr_dests,
-                       sizeof(*dst_dests->weight_arr), GFP_KERNEL);
-               if (!dst_dests->weight_arr) {
+               dst->weight_arr = kmalloc_array(src->nr_dests,
+                       sizeof(*dst->weight_arr), GFP_KERNEL);
+               if (!dst->weight_arr) {
                        /* ->node_id_arr will be freed by scheme destruction */
                        return -ENOMEM;
                }
        }
 
-       dst_dests->nr_dests = src_dests->nr_dests;
-       for (int i = 0; i < src_dests->nr_dests; i++) {
-               dst_dests->node_id_arr[i] = src_dests->node_id_arr[i];
-               dst_dests->weight_arr[i] = src_dests->weight_arr[i];
+       dst->nr_dests = src->nr_dests;
+       for (int i = 0; i < src->nr_dests; i++) {
+               dst->node_id_arr[i] = src->node_id_arr[i];
+               dst->weight_arr[i] = src->weight_arr[i];
        }
 
        return 0;
@@ -1076,7 +1072,7 @@ static int damos_commit(struct damos *dst, struct damos 
*src)
        dst->wmarks = src->wmarks;
        dst->target_nid = src->target_nid;
 
-       err = damos_commit_dests(dst, src);
+       err = damos_commit_dests(&dst->migrate_dests, &src->migrate_dests);
        if (err)
                return err;
 
-- 
2.47.3

Reply via email to