~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/mm/damon/sysfs-common.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Common Primitives for DAMON Sysfs Interface
  4  *
  5  * Author: SeongJae Park <sj@kernel.org>
  6  */
  7 
  8 #include <linux/slab.h>
  9 
 10 #include "sysfs-common.h"
 11 
 12 DEFINE_MUTEX(damon_sysfs_lock);
 13 
 14 /*
 15  * unsigned long range directory
 16  */
 17 
 18 struct damon_sysfs_ul_range *damon_sysfs_ul_range_alloc(
 19                 unsigned long min,
 20                 unsigned long max)
 21 {
 22         struct damon_sysfs_ul_range *range = kmalloc(sizeof(*range),
 23                         GFP_KERNEL);
 24 
 25         if (!range)
 26                 return NULL;
 27         range->kobj = (struct kobject){};
 28         range->min = min;
 29         range->max = max;
 30 
 31         return range;
 32 }
 33 
 34 static ssize_t min_show(struct kobject *kobj, struct kobj_attribute *attr,
 35                 char *buf)
 36 {
 37         struct damon_sysfs_ul_range *range = container_of(kobj,
 38                         struct damon_sysfs_ul_range, kobj);
 39 
 40         return sysfs_emit(buf, "%lu\n", range->min);
 41 }
 42 
 43 static ssize_t min_store(struct kobject *kobj, struct kobj_attribute *attr,
 44                 const char *buf, size_t count)
 45 {
 46         struct damon_sysfs_ul_range *range = container_of(kobj,
 47                         struct damon_sysfs_ul_range, kobj);
 48         unsigned long min;
 49         int err;
 50 
 51         err = kstrtoul(buf, 0, &min);
 52         if (err)
 53                 return err;
 54 
 55         range->min = min;
 56         return count;
 57 }
 58 
 59 static ssize_t max_show(struct kobject *kobj, struct kobj_attribute *attr,
 60                 char *buf)
 61 {
 62         struct damon_sysfs_ul_range *range = container_of(kobj,
 63                         struct damon_sysfs_ul_range, kobj);
 64 
 65         return sysfs_emit(buf, "%lu\n", range->max);
 66 }
 67 
 68 static ssize_t max_store(struct kobject *kobj, struct kobj_attribute *attr,
 69                 const char *buf, size_t count)
 70 {
 71         struct damon_sysfs_ul_range *range = container_of(kobj,
 72                         struct damon_sysfs_ul_range, kobj);
 73         unsigned long max;
 74         int err;
 75 
 76         err = kstrtoul(buf, 0, &max);
 77         if (err)
 78                 return err;
 79 
 80         range->max = max;
 81         return count;
 82 }
 83 
 84 void damon_sysfs_ul_range_release(struct kobject *kobj)
 85 {
 86         kfree(container_of(kobj, struct damon_sysfs_ul_range, kobj));
 87 }
 88 
 89 static struct kobj_attribute damon_sysfs_ul_range_min_attr =
 90                 __ATTR_RW_MODE(min, 0600);
 91 
 92 static struct kobj_attribute damon_sysfs_ul_range_max_attr =
 93                 __ATTR_RW_MODE(max, 0600);
 94 
 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,
 98         NULL,
 99 };
100 ATTRIBUTE_GROUPS(damon_sysfs_ul_range);
101 
102 const 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,
106 };
107 
108 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php