hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/samples/configfs/configfs_sample.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * vim: noexpandtab ts=8 sts=0 sw=8:
34 *
....@@ -5,34 +6,17 @@
56 * containing a number of configfs subsystems. It uses the helper
67 * macros defined by configfs.h
78 *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2 of the License, or (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
- * General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public
19
- * License along with this program; if not, write to the
20
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
- * Boston, MA 021110-1307, USA.
22
- *
239 * Based on sysfs:
24
- * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
10
+ * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
2511 *
2612 * configfs Copyright (C) 2005 Oracle. All rights reserved.
2713 */
2814
2915 #include <linux/init.h>
16
+#include <linux/kernel.h>
3017 #include <linux/module.h>
3118 #include <linux/slab.h>
32
-
3319 #include <linux/configfs.h>
34
-
35
-
3620
3721 /*
3822 * 01-childless
....@@ -54,8 +38,8 @@
5438
5539 static inline struct childless *to_childless(struct config_item *item)
5640 {
57
- return item ? container_of(to_configfs_subsystem(to_config_group(item)),
58
- struct childless, subsys) : NULL;
41
+ return container_of(to_configfs_subsystem(to_config_group(item)),
42
+ struct childless, subsys);
5943 }
6044
6145 static ssize_t childless_showme_show(struct config_item *item, char *page)
....@@ -78,17 +62,11 @@
7862 const char *page, size_t count)
7963 {
8064 struct childless *childless = to_childless(item);
81
- unsigned long tmp;
82
- char *p = (char *) page;
65
+ int ret;
8366
84
- tmp = simple_strtoul(p, &p, 10);
85
- if (!p || (*p && (*p != '\n')))
86
- return -EINVAL;
87
-
88
- if (tmp > INT_MAX)
89
- return -ERANGE;
90
-
91
- childless->storeme = tmp;
67
+ ret = kstrtoint(page, 10, &childless->storeme);
68
+ if (ret)
69
+ return ret;
9270
9371 return count;
9472 }
....@@ -131,7 +109,6 @@
131109 },
132110 };
133111
134
-
135112 /* ----------------------------------------------------------------- */
136113
137114 /*
....@@ -150,7 +127,7 @@
150127
151128 static inline struct simple_child *to_simple_child(struct config_item *item)
152129 {
153
- return item ? container_of(item, struct simple_child, item) : NULL;
130
+ return container_of(item, struct simple_child, item);
154131 }
155132
156133 static ssize_t simple_child_storeme_show(struct config_item *item, char *page)
....@@ -162,17 +139,11 @@
162139 const char *page, size_t count)
163140 {
164141 struct simple_child *simple_child = to_simple_child(item);
165
- unsigned long tmp;
166
- char *p = (char *) page;
142
+ int ret;
167143
168
- tmp = simple_strtoul(p, &p, 10);
169
- if (!p || (*p && (*p != '\n')))
170
- return -EINVAL;
171
-
172
- if (tmp > INT_MAX)
173
- return -ERANGE;
174
-
175
- simple_child->storeme = tmp;
144
+ ret = kstrtoint(page, 10, &simple_child->storeme);
145
+ if (ret)
146
+ return ret;
176147
177148 return count;
178149 }
....@@ -190,7 +161,7 @@
190161 }
191162
192163 static struct configfs_item_operations simple_child_item_ops = {
193
- .release = simple_child_release,
164
+ .release = simple_child_release,
194165 };
195166
196167 static const struct config_item_type simple_child_type = {
....@@ -199,15 +170,14 @@
199170 .ct_owner = THIS_MODULE,
200171 };
201172
202
-
203173 struct simple_children {
204174 struct config_group group;
205175 };
206176
207177 static inline struct simple_children *to_simple_children(struct config_item *item)
208178 {
209
- return item ? container_of(to_config_group(item),
210
- struct simple_children, group) : NULL;
179
+ return container_of(to_config_group(item),
180
+ struct simple_children, group);
211181 }
212182
213183 static struct config_item *simple_children_make_item(struct config_group *group,
....@@ -221,8 +191,6 @@
221191
222192 config_item_init_type_name(&simple_child->item, name,
223193 &simple_child_type);
224
-
225
- simple_child->storeme = 0;
226194
227195 return &simple_child->item;
228196 }
....@@ -276,7 +244,6 @@
276244 },
277245 },
278246 };
279
-
280247
281248 /* ----------------------------------------------------------------- */
282249
....@@ -364,9 +331,8 @@
364331
365332 static int __init configfs_example_init(void)
366333 {
367
- int ret;
368
- int i;
369334 struct configfs_subsystem *subsys;
335
+ int ret, i;
370336
371337 for (i = 0; example_subsys[i]; i++) {
372338 subsys = example_subsys[i];
....@@ -375,9 +341,8 @@
375341 mutex_init(&subsys->su_mutex);
376342 ret = configfs_register_subsystem(subsys);
377343 if (ret) {
378
- printk(KERN_ERR "Error %d while registering subsystem %s\n",
379
- ret,
380
- 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);
381346 goto out_unregister;
382347 }
383348 }