7
7
* macros defined by configfs.h
8
8
*
9
9
* Based on sysfs:
10
- * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
10
+ * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
11
11
*
12
12
* configfs Copyright (C) 2005 Oracle. All rights reserved.
13
13
*/
14
14
15
15
#include <linux/init.h>
16
+ #include <linux/kernel.h>
16
17
#include <linux/module.h>
17
18
#include <linux/slab.h>
18
-
19
19
#include <linux/configfs.h>
20
20
21
-
22
-
23
21
/*
24
22
* 01-childless
25
23
*
@@ -40,8 +38,8 @@ struct childless {
40
38
41
39
static inline struct childless * to_childless (struct config_item * item )
42
40
{
43
- return item ? container_of (to_configfs_subsystem (to_config_group (item )),
44
- struct childless , subsys ) : NULL ;
41
+ return container_of (to_configfs_subsystem (to_config_group (item )),
42
+ struct childless , subsys );
45
43
}
46
44
47
45
static ssize_t childless_showme_show (struct config_item * item , char * page )
@@ -64,17 +62,11 @@ static ssize_t childless_storeme_store(struct config_item *item,
64
62
const char * page , size_t count )
65
63
{
66
64
struct childless * childless = to_childless (item );
67
- unsigned long tmp ;
68
- char * p = (char * ) page ;
69
-
70
- tmp = simple_strtoul (p , & p , 10 );
71
- if (!p || (* p && (* p != '\n' )))
72
- return - EINVAL ;
73
-
74
- if (tmp > INT_MAX )
75
- return - ERANGE ;
65
+ int ret ;
76
66
77
- childless -> storeme = tmp ;
67
+ ret = kstrtoint (page , 10 , & childless -> storeme );
68
+ if (ret )
69
+ return ret ;
78
70
79
71
return count ;
80
72
}
@@ -117,7 +109,6 @@ static struct childless childless_subsys = {
117
109
},
118
110
};
119
111
120
-
121
112
/* ----------------------------------------------------------------- */
122
113
123
114
/*
@@ -136,7 +127,7 @@ struct simple_child {
136
127
137
128
static inline struct simple_child * to_simple_child (struct config_item * item )
138
129
{
139
- return item ? container_of (item , struct simple_child , item ) : NULL ;
130
+ return container_of (item , struct simple_child , item );
140
131
}
141
132
142
133
static ssize_t simple_child_storeme_show (struct config_item * item , char * page )
@@ -148,17 +139,11 @@ static ssize_t simple_child_storeme_store(struct config_item *item,
148
139
const char * page , size_t count )
149
140
{
150
141
struct simple_child * simple_child = to_simple_child (item );
151
- unsigned long tmp ;
152
- char * p = (char * ) page ;
153
-
154
- tmp = simple_strtoul (p , & p , 10 );
155
- if (!p || (* p && (* p != '\n' )))
156
- return - EINVAL ;
157
-
158
- if (tmp > INT_MAX )
159
- return - ERANGE ;
142
+ int ret ;
160
143
161
- simple_child -> storeme = tmp ;
144
+ ret = kstrtoint (page , 10 , & simple_child -> storeme );
145
+ if (ret )
146
+ return ret ;
162
147
163
148
return count ;
164
149
}
@@ -176,7 +161,7 @@ static void simple_child_release(struct config_item *item)
176
161
}
177
162
178
163
static struct configfs_item_operations simple_child_item_ops = {
179
- .release = simple_child_release ,
164
+ .release = simple_child_release ,
180
165
};
181
166
182
167
static const struct config_item_type simple_child_type = {
@@ -185,15 +170,14 @@ static const struct config_item_type simple_child_type = {
185
170
.ct_owner = THIS_MODULE ,
186
171
};
187
172
188
-
189
173
struct simple_children {
190
174
struct config_group group ;
191
175
};
192
176
193
177
static inline struct simple_children * to_simple_children (struct config_item * item )
194
178
{
195
- return item ? container_of (to_config_group (item ),
196
- struct simple_children , group ) : NULL ;
179
+ return container_of (to_config_group (item ),
180
+ struct simple_children , group );
197
181
}
198
182
199
183
static struct config_item * simple_children_make_item (struct config_group * group ,
@@ -208,8 +192,6 @@ static struct config_item *simple_children_make_item(struct config_group *group,
208
192
config_item_init_type_name (& simple_child -> item , name ,
209
193
& simple_child_type );
210
194
211
- simple_child -> storeme = 0 ;
212
-
213
195
return & simple_child -> item ;
214
196
}
215
197
@@ -263,7 +245,6 @@ static struct configfs_subsystem simple_children_subsys = {
263
245
},
264
246
};
265
247
266
-
267
248
/* ----------------------------------------------------------------- */
268
249
269
250
/*
@@ -350,9 +331,8 @@ static struct configfs_subsystem *example_subsys[] = {
350
331
351
332
static int __init configfs_example_init (void )
352
333
{
353
- int ret ;
354
- int i ;
355
334
struct configfs_subsystem * subsys ;
335
+ int ret , i ;
356
336
357
337
for (i = 0 ; example_subsys [i ]; i ++ ) {
358
338
subsys = example_subsys [i ];
@@ -361,9 +341,8 @@ static int __init configfs_example_init(void)
361
341
mutex_init (& subsys -> su_mutex );
362
342
ret = configfs_register_subsystem (subsys );
363
343
if (ret ) {
364
- printk (KERN_ERR "Error %d while registering subsystem %s\n" ,
365
- ret ,
366
- subsys -> su_group .cg_item .ci_namebuf );
344
+ pr_err ("Error %d while registering subsystem %s\n" ,
345
+ ret , subsys -> su_group .cg_item .ci_namebuf );
367
346
goto out_unregister ;
368
347
}
369
348
}
0 commit comments