Commit 9210622a authored by Rongwei Wang's avatar Rongwei Wang Committed by Linus Torvalds

mm/damon/dbgfs: remove unnecessary variables

In some functions, it's unnecessary to declare 'err' and 'ret' variables
at the same time.  This patch mainly to simplify the issue of such
declarations by reusing one variable.

Link: https://lkml.kernel.org/r/20211014073014.35754-1-sj@kernel.orgSigned-off-by: default avatarRongwei Wang <rongwei.wang@linux.alibaba.com>
Signed-off-by: default avatarSeongJae Park <sj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 199b50f4
...@@ -69,8 +69,7 @@ static ssize_t dbgfs_attrs_write(struct file *file, ...@@ -69,8 +69,7 @@ static ssize_t dbgfs_attrs_write(struct file *file,
struct damon_ctx *ctx = file->private_data; struct damon_ctx *ctx = file->private_data;
unsigned long s, a, r, minr, maxr; unsigned long s, a, r, minr, maxr;
char *kbuf; char *kbuf;
ssize_t ret = count; ssize_t ret;
int err;
kbuf = user_input_str(buf, count, ppos); kbuf = user_input_str(buf, count, ppos);
if (IS_ERR(kbuf)) if (IS_ERR(kbuf))
...@@ -88,9 +87,9 @@ static ssize_t dbgfs_attrs_write(struct file *file, ...@@ -88,9 +87,9 @@ static ssize_t dbgfs_attrs_write(struct file *file,
goto unlock_out; goto unlock_out;
} }
err = damon_set_attrs(ctx, s, a, r, minr, maxr); ret = damon_set_attrs(ctx, s, a, r, minr, maxr);
if (err) if (!ret)
ret = err; ret = count;
unlock_out: unlock_out:
mutex_unlock(&ctx->kdamond_lock); mutex_unlock(&ctx->kdamond_lock);
out: out:
...@@ -220,14 +219,13 @@ static ssize_t dbgfs_schemes_write(struct file *file, const char __user *buf, ...@@ -220,14 +219,13 @@ static ssize_t dbgfs_schemes_write(struct file *file, const char __user *buf,
struct damon_ctx *ctx = file->private_data; struct damon_ctx *ctx = file->private_data;
char *kbuf; char *kbuf;
struct damos **schemes; struct damos **schemes;
ssize_t nr_schemes = 0, ret = count; ssize_t nr_schemes = 0, ret;
int err;
kbuf = user_input_str(buf, count, ppos); kbuf = user_input_str(buf, count, ppos);
if (IS_ERR(kbuf)) if (IS_ERR(kbuf))
return PTR_ERR(kbuf); return PTR_ERR(kbuf);
schemes = str_to_schemes(kbuf, ret, &nr_schemes); schemes = str_to_schemes(kbuf, count, &nr_schemes);
if (!schemes) { if (!schemes) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
...@@ -239,11 +237,12 @@ static ssize_t dbgfs_schemes_write(struct file *file, const char __user *buf, ...@@ -239,11 +237,12 @@ static ssize_t dbgfs_schemes_write(struct file *file, const char __user *buf,
goto unlock_out; goto unlock_out;
} }
err = damon_set_schemes(ctx, schemes, nr_schemes); ret = damon_set_schemes(ctx, schemes, nr_schemes);
if (err) if (!ret) {
ret = err; ret = count;
else
nr_schemes = 0; nr_schemes = 0;
}
unlock_out: unlock_out:
mutex_unlock(&ctx->kdamond_lock); mutex_unlock(&ctx->kdamond_lock);
free_schemes_arr(schemes, nr_schemes); free_schemes_arr(schemes, nr_schemes);
...@@ -343,9 +342,8 @@ static ssize_t dbgfs_target_ids_write(struct file *file, ...@@ -343,9 +342,8 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
char *kbuf, *nrs; char *kbuf, *nrs;
unsigned long *targets; unsigned long *targets;
ssize_t nr_targets; ssize_t nr_targets;
ssize_t ret = count; ssize_t ret;
int i; int i;
int err;
kbuf = user_input_str(buf, count, ppos); kbuf = user_input_str(buf, count, ppos);
if (IS_ERR(kbuf)) if (IS_ERR(kbuf))
...@@ -358,7 +356,7 @@ static ssize_t dbgfs_target_ids_write(struct file *file, ...@@ -358,7 +356,7 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
scnprintf(kbuf, count, "42 "); scnprintf(kbuf, count, "42 ");
} }
targets = str_to_target_ids(nrs, ret, &nr_targets); targets = str_to_target_ids(nrs, count, &nr_targets);
if (!targets) { if (!targets) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -393,11 +391,12 @@ static ssize_t dbgfs_target_ids_write(struct file *file, ...@@ -393,11 +391,12 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
else else
damon_pa_set_primitives(ctx); damon_pa_set_primitives(ctx);
err = damon_set_targets(ctx, targets, nr_targets); ret = damon_set_targets(ctx, targets, nr_targets);
if (err) { if (ret) {
if (id_is_pid) if (id_is_pid)
dbgfs_put_pids(targets, nr_targets); dbgfs_put_pids(targets, nr_targets);
ret = err; } else {
ret = count;
} }
unlock_out: unlock_out:
...@@ -715,8 +714,7 @@ static ssize_t dbgfs_mk_context_write(struct file *file, ...@@ -715,8 +714,7 @@ static ssize_t dbgfs_mk_context_write(struct file *file,
{ {
char *kbuf; char *kbuf;
char *ctx_name; char *ctx_name;
ssize_t ret = count; ssize_t ret;
int err;
kbuf = user_input_str(buf, count, ppos); kbuf = user_input_str(buf, count, ppos);
if (IS_ERR(kbuf)) if (IS_ERR(kbuf))
...@@ -734,9 +732,9 @@ static ssize_t dbgfs_mk_context_write(struct file *file, ...@@ -734,9 +732,9 @@ static ssize_t dbgfs_mk_context_write(struct file *file,
} }
mutex_lock(&damon_dbgfs_lock); mutex_lock(&damon_dbgfs_lock);
err = dbgfs_mk_context(ctx_name); ret = dbgfs_mk_context(ctx_name);
if (err) if (!ret)
ret = err; ret = count;
mutex_unlock(&damon_dbgfs_lock); mutex_unlock(&damon_dbgfs_lock);
out: out:
...@@ -805,8 +803,7 @@ static ssize_t dbgfs_rm_context_write(struct file *file, ...@@ -805,8 +803,7 @@ static ssize_t dbgfs_rm_context_write(struct file *file,
const char __user *buf, size_t count, loff_t *ppos) const char __user *buf, size_t count, loff_t *ppos)
{ {
char *kbuf; char *kbuf;
ssize_t ret = count; ssize_t ret;
int err;
char *ctx_name; char *ctx_name;
kbuf = user_input_str(buf, count, ppos); kbuf = user_input_str(buf, count, ppos);
...@@ -825,9 +822,9 @@ static ssize_t dbgfs_rm_context_write(struct file *file, ...@@ -825,9 +822,9 @@ static ssize_t dbgfs_rm_context_write(struct file *file,
} }
mutex_lock(&damon_dbgfs_lock); mutex_lock(&damon_dbgfs_lock);
err = dbgfs_rm_context(ctx_name); ret = dbgfs_rm_context(ctx_name);
if (err) if (!ret)
ret = err; ret = count;
mutex_unlock(&damon_dbgfs_lock); mutex_unlock(&damon_dbgfs_lock);
out: out:
...@@ -851,9 +848,8 @@ static ssize_t dbgfs_monitor_on_read(struct file *file, ...@@ -851,9 +848,8 @@ static ssize_t dbgfs_monitor_on_read(struct file *file,
static ssize_t dbgfs_monitor_on_write(struct file *file, static ssize_t dbgfs_monitor_on_write(struct file *file,
const char __user *buf, size_t count, loff_t *ppos) const char __user *buf, size_t count, loff_t *ppos)
{ {
ssize_t ret = count; ssize_t ret;
char *kbuf; char *kbuf;
int err;
kbuf = user_input_str(buf, count, ppos); kbuf = user_input_str(buf, count, ppos);
if (IS_ERR(kbuf)) if (IS_ERR(kbuf))
...@@ -866,14 +862,14 @@ static ssize_t dbgfs_monitor_on_write(struct file *file, ...@@ -866,14 +862,14 @@ static ssize_t dbgfs_monitor_on_write(struct file *file,
} }
if (!strncmp(kbuf, "on", count)) if (!strncmp(kbuf, "on", count))
err = damon_start(dbgfs_ctxs, dbgfs_nr_ctxs); ret = damon_start(dbgfs_ctxs, dbgfs_nr_ctxs);
else if (!strncmp(kbuf, "off", count)) else if (!strncmp(kbuf, "off", count))
err = damon_stop(dbgfs_ctxs, dbgfs_nr_ctxs); ret = damon_stop(dbgfs_ctxs, dbgfs_nr_ctxs);
else else
err = -EINVAL; ret = -EINVAL;
if (err) if (!ret)
ret = err; ret = count;
kfree(kbuf); kfree(kbuf);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment