Commit a17a8b3b authored by Xin Hao's avatar Xin Hao Committed by Andrew Morton

mm/damon/sysfs: change few functions execute order

There's no need to run container_of() as early as we do.

The compiler figures this out, but the resulting code is more readable.

Link: https://lkml.kernel.org/r/20220908081932.77370-1-xhao@linux.alibaba.comSigned-off-by: default avatarXin Hao <xhao@linux.alibaba.com>
Reviewed-by: default avatarSeongJae Park <sj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent f4981502
...@@ -1031,8 +1031,7 @@ static ssize_t nr_schemes_show(struct kobject *kobj, ...@@ -1031,8 +1031,7 @@ static ssize_t nr_schemes_show(struct kobject *kobj,
static ssize_t nr_schemes_store(struct kobject *kobj, static ssize_t nr_schemes_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count) struct kobj_attribute *attr, const char *buf, size_t count)
{ {
struct damon_sysfs_schemes *schemes = container_of(kobj, struct damon_sysfs_schemes *schemes;
struct damon_sysfs_schemes, kobj);
int nr, err = kstrtoint(buf, 0, &nr); int nr, err = kstrtoint(buf, 0, &nr);
if (err) if (err)
...@@ -1040,6 +1039,8 @@ static ssize_t nr_schemes_store(struct kobject *kobj, ...@@ -1040,6 +1039,8 @@ static ssize_t nr_schemes_store(struct kobject *kobj,
if (nr < 0) if (nr < 0)
return -EINVAL; return -EINVAL;
schemes = container_of(kobj, struct damon_sysfs_schemes, kobj);
if (!mutex_trylock(&damon_sysfs_lock)) if (!mutex_trylock(&damon_sysfs_lock))
return -EBUSY; return -EBUSY;
err = damon_sysfs_schemes_add_dirs(schemes, nr); err = damon_sysfs_schemes_add_dirs(schemes, nr);
...@@ -1237,8 +1238,7 @@ static ssize_t nr_regions_show(struct kobject *kobj, ...@@ -1237,8 +1238,7 @@ static ssize_t nr_regions_show(struct kobject *kobj,
static ssize_t nr_regions_store(struct kobject *kobj, static ssize_t nr_regions_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count) struct kobj_attribute *attr, const char *buf, size_t count)
{ {
struct damon_sysfs_regions *regions = container_of(kobj, struct damon_sysfs_regions *regions;
struct damon_sysfs_regions, kobj);
int nr, err = kstrtoint(buf, 0, &nr); int nr, err = kstrtoint(buf, 0, &nr);
if (err) if (err)
...@@ -1246,6 +1246,8 @@ static ssize_t nr_regions_store(struct kobject *kobj, ...@@ -1246,6 +1246,8 @@ static ssize_t nr_regions_store(struct kobject *kobj,
if (nr < 0) if (nr < 0)
return -EINVAL; return -EINVAL;
regions = container_of(kobj, struct damon_sysfs_regions, kobj);
if (!mutex_trylock(&damon_sysfs_lock)) if (!mutex_trylock(&damon_sysfs_lock))
return -EBUSY; return -EBUSY;
err = damon_sysfs_regions_add_dirs(regions, nr); err = damon_sysfs_regions_add_dirs(regions, nr);
...@@ -1440,8 +1442,7 @@ static ssize_t nr_targets_show(struct kobject *kobj, ...@@ -1440,8 +1442,7 @@ static ssize_t nr_targets_show(struct kobject *kobj,
static ssize_t nr_targets_store(struct kobject *kobj, static ssize_t nr_targets_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count) struct kobj_attribute *attr, const char *buf, size_t count)
{ {
struct damon_sysfs_targets *targets = container_of(kobj, struct damon_sysfs_targets *targets;
struct damon_sysfs_targets, kobj);
int nr, err = kstrtoint(buf, 0, &nr); int nr, err = kstrtoint(buf, 0, &nr);
if (err) if (err)
...@@ -1449,6 +1450,8 @@ static ssize_t nr_targets_store(struct kobject *kobj, ...@@ -1449,6 +1450,8 @@ static ssize_t nr_targets_store(struct kobject *kobj,
if (nr < 0) if (nr < 0)
return -EINVAL; return -EINVAL;
targets = container_of(kobj, struct damon_sysfs_targets, kobj);
if (!mutex_trylock(&damon_sysfs_lock)) if (!mutex_trylock(&damon_sysfs_lock))
return -EBUSY; return -EBUSY;
err = damon_sysfs_targets_add_dirs(targets, nr); err = damon_sysfs_targets_add_dirs(targets, nr);
...@@ -1962,8 +1965,7 @@ static ssize_t nr_contexts_show(struct kobject *kobj, ...@@ -1962,8 +1965,7 @@ static ssize_t nr_contexts_show(struct kobject *kobj,
static ssize_t nr_contexts_store(struct kobject *kobj, static ssize_t nr_contexts_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count) struct kobj_attribute *attr, const char *buf, size_t count)
{ {
struct damon_sysfs_contexts *contexts = container_of(kobj, struct damon_sysfs_contexts *contexts;
struct damon_sysfs_contexts, kobj);
int nr, err; int nr, err;
err = kstrtoint(buf, 0, &nr); err = kstrtoint(buf, 0, &nr);
...@@ -1973,6 +1975,7 @@ static ssize_t nr_contexts_store(struct kobject *kobj, ...@@ -1973,6 +1975,7 @@ static ssize_t nr_contexts_store(struct kobject *kobj,
if (nr < 0 || 1 < nr) if (nr < 0 || 1 < nr)
return -EINVAL; return -EINVAL;
contexts = container_of(kobj, struct damon_sysfs_contexts, kobj);
if (!mutex_trylock(&damon_sysfs_lock)) if (!mutex_trylock(&damon_sysfs_lock))
return -EBUSY; return -EBUSY;
err = damon_sysfs_contexts_add_dirs(contexts, nr); err = damon_sysfs_contexts_add_dirs(contexts, nr);
...@@ -2737,8 +2740,7 @@ static ssize_t nr_kdamonds_show(struct kobject *kobj, ...@@ -2737,8 +2740,7 @@ static ssize_t nr_kdamonds_show(struct kobject *kobj,
static ssize_t nr_kdamonds_store(struct kobject *kobj, static ssize_t nr_kdamonds_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count) struct kobj_attribute *attr, const char *buf, size_t count)
{ {
struct damon_sysfs_kdamonds *kdamonds = container_of(kobj, struct damon_sysfs_kdamonds *kdamonds;
struct damon_sysfs_kdamonds, kobj);
int nr, err; int nr, err;
err = kstrtoint(buf, 0, &nr); err = kstrtoint(buf, 0, &nr);
...@@ -2747,6 +2749,8 @@ static ssize_t nr_kdamonds_store(struct kobject *kobj, ...@@ -2747,6 +2749,8 @@ static ssize_t nr_kdamonds_store(struct kobject *kobj,
if (nr < 0) if (nr < 0)
return -EINVAL; return -EINVAL;
kdamonds = container_of(kobj, struct damon_sysfs_kdamonds, kobj);
if (!mutex_trylock(&damon_sysfs_lock)) if (!mutex_trylock(&damon_sysfs_lock))
return -EBUSY; return -EBUSY;
err = damon_sysfs_kdamonds_add_dirs(kdamonds, nr); err = damon_sysfs_kdamonds_add_dirs(kdamonds, nr);
......
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