kset-example.c (5e2aa2ed08e2e280121dc7cf5609c87d464f12ef) kset-example.c (5fd637e7a75fb2a4c0b62683c08dae959160fedf)
1/*
2 * Sample kset and ktype implementation
3 *
4 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2007 Novell Inc.
6 *
7 * Released under the GPL version 2 only.
8 *

--- 106 unchanged lines hidden (view full) ---

115 char *buf)
116{
117 return sprintf(buf, "%d\n", foo_obj->foo);
118}
119
120static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
121 const char *buf, size_t count)
122{
1/*
2 * Sample kset and ktype implementation
3 *
4 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2007 Novell Inc.
6 *
7 * Released under the GPL version 2 only.
8 *

--- 106 unchanged lines hidden (view full) ---

115 char *buf)
116{
117 return sprintf(buf, "%d\n", foo_obj->foo);
118}
119
120static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
121 const char *buf, size_t count)
122{
123 sscanf(buf, "%du", &foo_obj->foo);
123 int ret;
124
125 ret = kstrtoint(buf, 10, &foo_obj->foo);
126 if (ret < 0)
127 return ret;
128
124 return count;
125}
126
127/* Sysfs attributes cannot be world-writable. */
128static struct foo_attribute foo_attribute =
129 __ATTR(foo, 0664, foo_show, foo_store);
130
131/*

--- 10 unchanged lines hidden (view full) ---

142 else
143 var = foo_obj->bar;
144 return sprintf(buf, "%d\n", var);
145}
146
147static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
148 const char *buf, size_t count)
149{
129 return count;
130}
131
132/* Sysfs attributes cannot be world-writable. */
133static struct foo_attribute foo_attribute =
134 __ATTR(foo, 0664, foo_show, foo_store);
135
136/*

--- 10 unchanged lines hidden (view full) ---

147 else
148 var = foo_obj->bar;
149 return sprintf(buf, "%d\n", var);
150}
151
152static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
153 const char *buf, size_t count)
154{
150 int var;
155 int var, ret;
151
156
152 sscanf(buf, "%du", &var);
157 ret = kstrtoint(buf, 10, &var);
158 if (ret < 0)
159 return ret;
160
153 if (strcmp(attr->attr.name, "baz") == 0)
154 foo_obj->baz = var;
155 else
156 foo_obj->bar = var;
157 return count;
158}
159
160static struct foo_attribute baz_attribute =

--- 121 unchanged lines hidden ---
161 if (strcmp(attr->attr.name, "baz") == 0)
162 foo_obj->baz = var;
163 else
164 foo_obj->bar = var;
165 return count;
166}
167
168static struct foo_attribute baz_attribute =

--- 121 unchanged lines hidden ---