| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * vim: noexpandtab ts=8 sts=0 sw=8: |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * containing a number of configfs subsystems. It uses the helper |
|---|
| 6 | 7 | * macros defined by configfs.h |
|---|
| 7 | 8 | * |
|---|
| 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 | | - * |
|---|
| 23 | 9 | * Based on sysfs: |
|---|
| 24 | | - * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel |
|---|
| 10 | + * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel |
|---|
| 25 | 11 | * |
|---|
| 26 | 12 | * configfs Copyright (C) 2005 Oracle. All rights reserved. |
|---|
| 27 | 13 | */ |
|---|
| 28 | 14 | |
|---|
| 29 | 15 | #include <linux/init.h> |
|---|
| 16 | +#include <linux/kernel.h> |
|---|
| 30 | 17 | #include <linux/module.h> |
|---|
| 31 | 18 | #include <linux/slab.h> |
|---|
| 32 | | - |
|---|
| 33 | 19 | #include <linux/configfs.h> |
|---|
| 34 | | - |
|---|
| 35 | | - |
|---|
| 36 | 20 | |
|---|
| 37 | 21 | /* |
|---|
| 38 | 22 | * 01-childless |
|---|
| .. | .. |
|---|
| 54 | 38 | |
|---|
| 55 | 39 | static inline struct childless *to_childless(struct config_item *item) |
|---|
| 56 | 40 | { |
|---|
| 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); |
|---|
| 59 | 43 | } |
|---|
| 60 | 44 | |
|---|
| 61 | 45 | static ssize_t childless_showme_show(struct config_item *item, char *page) |
|---|
| .. | .. |
|---|
| 78 | 62 | const char *page, size_t count) |
|---|
| 79 | 63 | { |
|---|
| 80 | 64 | struct childless *childless = to_childless(item); |
|---|
| 81 | | - unsigned long tmp; |
|---|
| 82 | | - char *p = (char *) page; |
|---|
| 65 | + int ret; |
|---|
| 83 | 66 | |
|---|
| 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; |
|---|
| 92 | 70 | |
|---|
| 93 | 71 | return count; |
|---|
| 94 | 72 | } |
|---|
| .. | .. |
|---|
| 131 | 109 | }, |
|---|
| 132 | 110 | }; |
|---|
| 133 | 111 | |
|---|
| 134 | | - |
|---|
| 135 | 112 | /* ----------------------------------------------------------------- */ |
|---|
| 136 | 113 | |
|---|
| 137 | 114 | /* |
|---|
| .. | .. |
|---|
| 150 | 127 | |
|---|
| 151 | 128 | static inline struct simple_child *to_simple_child(struct config_item *item) |
|---|
| 152 | 129 | { |
|---|
| 153 | | - return item ? container_of(item, struct simple_child, item) : NULL; |
|---|
| 130 | + return container_of(item, struct simple_child, item); |
|---|
| 154 | 131 | } |
|---|
| 155 | 132 | |
|---|
| 156 | 133 | static ssize_t simple_child_storeme_show(struct config_item *item, char *page) |
|---|
| .. | .. |
|---|
| 162 | 139 | const char *page, size_t count) |
|---|
| 163 | 140 | { |
|---|
| 164 | 141 | struct simple_child *simple_child = to_simple_child(item); |
|---|
| 165 | | - unsigned long tmp; |
|---|
| 166 | | - char *p = (char *) page; |
|---|
| 142 | + int ret; |
|---|
| 167 | 143 | |
|---|
| 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; |
|---|
| 176 | 147 | |
|---|
| 177 | 148 | return count; |
|---|
| 178 | 149 | } |
|---|
| .. | .. |
|---|
| 190 | 161 | } |
|---|
| 191 | 162 | |
|---|
| 192 | 163 | static struct configfs_item_operations simple_child_item_ops = { |
|---|
| 193 | | - .release = simple_child_release, |
|---|
| 164 | + .release = simple_child_release, |
|---|
| 194 | 165 | }; |
|---|
| 195 | 166 | |
|---|
| 196 | 167 | static const struct config_item_type simple_child_type = { |
|---|
| .. | .. |
|---|
| 199 | 170 | .ct_owner = THIS_MODULE, |
|---|
| 200 | 171 | }; |
|---|
| 201 | 172 | |
|---|
| 202 | | - |
|---|
| 203 | 173 | struct simple_children { |
|---|
| 204 | 174 | struct config_group group; |
|---|
| 205 | 175 | }; |
|---|
| 206 | 176 | |
|---|
| 207 | 177 | static inline struct simple_children *to_simple_children(struct config_item *item) |
|---|
| 208 | 178 | { |
|---|
| 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); |
|---|
| 211 | 181 | } |
|---|
| 212 | 182 | |
|---|
| 213 | 183 | static struct config_item *simple_children_make_item(struct config_group *group, |
|---|
| .. | .. |
|---|
| 221 | 191 | |
|---|
| 222 | 192 | config_item_init_type_name(&simple_child->item, name, |
|---|
| 223 | 193 | &simple_child_type); |
|---|
| 224 | | - |
|---|
| 225 | | - simple_child->storeme = 0; |
|---|
| 226 | 194 | |
|---|
| 227 | 195 | return &simple_child->item; |
|---|
| 228 | 196 | } |
|---|
| .. | .. |
|---|
| 276 | 244 | }, |
|---|
| 277 | 245 | }, |
|---|
| 278 | 246 | }; |
|---|
| 279 | | - |
|---|
| 280 | 247 | |
|---|
| 281 | 248 | /* ----------------------------------------------------------------- */ |
|---|
| 282 | 249 | |
|---|
| .. | .. |
|---|
| 364 | 331 | |
|---|
| 365 | 332 | static int __init configfs_example_init(void) |
|---|
| 366 | 333 | { |
|---|
| 367 | | - int ret; |
|---|
| 368 | | - int i; |
|---|
| 369 | 334 | struct configfs_subsystem *subsys; |
|---|
| 335 | + int ret, i; |
|---|
| 370 | 336 | |
|---|
| 371 | 337 | for (i = 0; example_subsys[i]; i++) { |
|---|
| 372 | 338 | subsys = example_subsys[i]; |
|---|
| .. | .. |
|---|
| 375 | 341 | mutex_init(&subsys->su_mutex); |
|---|
| 376 | 342 | ret = configfs_register_subsystem(subsys); |
|---|
| 377 | 343 | 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); |
|---|
| 381 | 346 | goto out_unregister; |
|---|
| 382 | 347 | } |
|---|
| 383 | 348 | } |
|---|