1 // SPDX-License-Identifier: GPL-2.0
3 * Common Primitives for DAMON Sysfs Interface
5 * Author: SeongJae Park <sj@kernel.org>
8 #include <linux/slab.h>
10 #include "sysfs-common.h"
12 DEFINE_MUTEX(damon_sysfs_lock);
15 * unsigned long range directory
18 struct damon_sysfs_ul_range *damon_sysfs_ul_range_alloc(
22 struct damon_sysfs_ul_range *range = kmalloc(sizeof(*range),
27 range->kobj = (struct kobject){};
34 static ssize_t min_show(struct kobject *kobj, struct kobj_attribute *attr,
37 struct damon_sysfs_ul_range *range = container_of(kobj,
38 struct damon_sysfs_ul_range, kobj);
40 return sysfs_emit(buf, "%lu\n", range->min);
43 static ssize_t min_store(struct kobject *kobj, struct kobj_attribute *attr,
44 const char *buf, size_t count)
46 struct damon_sysfs_ul_range *range = container_of(kobj,
47 struct damon_sysfs_ul_range, kobj);
51 err = kstrtoul(buf, 0, &min);
59 static ssize_t max_show(struct kobject *kobj, struct kobj_attribute *attr,
62 struct damon_sysfs_ul_range *range = container_of(kobj,
63 struct damon_sysfs_ul_range, kobj);
65 return sysfs_emit(buf, "%lu\n", range->max);
68 static ssize_t max_store(struct kobject *kobj, struct kobj_attribute *attr,
69 const char *buf, size_t count)
71 struct damon_sysfs_ul_range *range = container_of(kobj,
72 struct damon_sysfs_ul_range, kobj);
76 err = kstrtoul(buf, 0, &max);
84 void damon_sysfs_ul_range_release(struct kobject *kobj)
86 kfree(container_of(kobj, struct damon_sysfs_ul_range, kobj));
89 static struct kobj_attribute damon_sysfs_ul_range_min_attr =
90 __ATTR_RW_MODE(min, 0600);
92 static struct kobj_attribute damon_sysfs_ul_range_max_attr =
93 __ATTR_RW_MODE(max, 0600);
95 static struct attribute *damon_sysfs_ul_range_attrs[] = {
96 &damon_sysfs_ul_range_min_attr.attr,
97 &damon_sysfs_ul_range_max_attr.attr,
100 ATTRIBUTE_GROUPS(damon_sysfs_ul_range);
102 struct kobj_type damon_sysfs_ul_range_ktype = {
103 .release = damon_sysfs_ul_range_release,
104 .sysfs_ops = &kobj_sysfs_ops,
105 .default_groups = damon_sysfs_ul_range_groups,