blob: 4bc965d8a1fe8d66b66b7e7e220c08104084205a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Helpers for initial module or kernel cmdline parsing
2 Copyright (C) 2001 Rusty Russell.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
Paul Gortmaker72a59aa2011-05-26 21:07:10 -040018#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/kernel.h>
20#include <linux/string.h>
21#include <linux/errno.h>
22#include <linux/module.h>
23#include <linux/device.h>
24#include <linux/err.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080025#include <linux/slab.h>
Peter Oberparleiter26d052b2009-07-06 17:11:22 +020026#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Rusty Russell907b29e2010-08-11 23:04:19 -060028/* Protects all parameters, and incidentally kmalloced_param list. */
29static DEFINE_MUTEX(param_lock);
30
Rusty Russella1054322010-08-11 23:04:18 -060031/* This just allows us to keep track of which parameters are kmalloced. */
32struct kmalloced_param {
33 struct list_head list;
34 char val[];
35};
Rusty Russella1054322010-08-11 23:04:18 -060036static LIST_HEAD(kmalloced_params);
37
38static void *kmalloc_parameter(unsigned int size)
39{
40 struct kmalloced_param *p;
41
42 p = kmalloc(sizeof(*p) + size, GFP_KERNEL);
43 if (!p)
44 return NULL;
45
Rusty Russella1054322010-08-11 23:04:18 -060046 list_add(&p->list, &kmalloced_params);
Rusty Russella1054322010-08-11 23:04:18 -060047 return p->val;
48}
49
50/* Does nothing if parameter wasn't kmalloced above. */
51static void maybe_kfree_parameter(void *param)
52{
53 struct kmalloced_param *p;
54
Rusty Russella1054322010-08-11 23:04:18 -060055 list_for_each_entry(p, &kmalloced_params, list) {
56 if (p->val == param) {
57 list_del(&p->list);
58 kfree(p);
59 break;
60 }
61 }
Rusty Russella1054322010-08-11 23:04:18 -060062}
63
Michal Schmidtb1e4d202011-10-10 00:03:37 +020064static char dash2underscore(char c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
66 if (c == '-')
67 return '_';
68 return c;
69}
70
Michal Schmidtb1e4d202011-10-10 00:03:37 +020071bool parameqn(const char *a, const char *b, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Michal Schmidtb1e4d202011-10-10 00:03:37 +020073 size_t i;
74
75 for (i = 0; i < n; i++) {
76 if (dash2underscore(a[i]) != dash2underscore(b[i]))
77 return false;
78 }
79 return true;
80}
81
82bool parameq(const char *a, const char *b)
83{
84 return parameqn(a, b, strlen(a)+1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
87static int parse_one(char *param,
88 char *val,
Rusty Russell914dcaa2010-08-11 23:04:18 -060089 const struct kernel_param *params,
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 unsigned num_params,
91 int (*handle_unknown)(char *param, char *val))
92{
93 unsigned int i;
Rusty Russell907b29e2010-08-11 23:04:19 -060094 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 /* Find parameter */
97 for (i = 0; i < num_params; i++) {
98 if (parameq(param, params[i].name)) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -030099 /* No one handled NULL, so do it here. */
Dave Young10f296c2012-02-01 10:33:11 +0800100 if (!val && params[i].ops->set != param_set_bool
101 && params[i].ops->set != param_set_bint)
Rusty Russell2e9fb992010-08-11 23:04:10 -0600102 return -EINVAL;
Jim Cromie8487bfd2011-12-06 12:11:31 -0700103 pr_debug("They are equal! Calling %p\n",
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600104 params[i].ops->set);
Rusty Russell907b29e2010-08-11 23:04:19 -0600105 mutex_lock(&param_lock);
106 err = params[i].ops->set(val, &params[i]);
107 mutex_unlock(&param_lock);
108 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 }
110 }
111
112 if (handle_unknown) {
Jim Cromie8487bfd2011-12-06 12:11:31 -0700113 pr_debug("Unknown argument: calling %p\n", handle_unknown);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return handle_unknown(param, val);
115 }
116
Jim Cromie8487bfd2011-12-06 12:11:31 -0700117 pr_debug("Unknown argument `%s'\n", param);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return -ENOENT;
119}
120
121/* You can use " around spaces, but can't escape ". */
122/* Hyphens and underscores equivalent in parameter names. */
123static char *next_arg(char *args, char **param, char **val)
124{
125 unsigned int i, equals = 0;
126 int in_quote = 0, quoted = 0;
127 char *next;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 if (*args == '"') {
130 args++;
131 in_quote = 1;
132 quoted = 1;
133 }
134
135 for (i = 0; args[i]; i++) {
Peter Oberparleiter26d052b2009-07-06 17:11:22 +0200136 if (isspace(args[i]) && !in_quote)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 break;
138 if (equals == 0) {
139 if (args[i] == '=')
140 equals = i;
141 }
142 if (args[i] == '"')
143 in_quote = !in_quote;
144 }
145
146 *param = args;
147 if (!equals)
148 *val = NULL;
149 else {
150 args[equals] = '\0';
151 *val = args + equals + 1;
152
153 /* Don't include quotes in value. */
154 if (**val == '"') {
155 (*val)++;
156 if (args[i-1] == '"')
157 args[i-1] = '\0';
158 }
159 if (quoted && args[i-1] == '"')
160 args[i-1] = '\0';
161 }
162
163 if (args[i]) {
164 args[i] = '\0';
165 next = args + i + 1;
166 } else
167 next = args + i;
Rusty Russellf36462f2005-09-27 21:45:34 -0700168
169 /* Chew up trailing spaces. */
André Goddard Rosae7d28602009-12-14 18:01:06 -0800170 return skip_spaces(next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
173/* Args looks like "foo=bar,bar2 baz=fuz wiz". */
174int parse_args(const char *name,
175 char *args,
Rusty Russell914dcaa2010-08-11 23:04:18 -0600176 const struct kernel_param *params,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 unsigned num,
178 int (*unknown)(char *param, char *val))
179{
180 char *param, *val;
181
Jim Cromie8487bfd2011-12-06 12:11:31 -0700182 pr_debug("Parsing ARGS: %s\n", args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Rusty Russellf36462f2005-09-27 21:45:34 -0700184 /* Chew leading spaces */
André Goddard Rosae7d28602009-12-14 18:01:06 -0800185 args = skip_spaces(args);
Rusty Russellf36462f2005-09-27 21:45:34 -0700186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 while (*args) {
188 int ret;
Ard van Breemena416aba2007-01-05 16:36:20 -0800189 int irq_was_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 args = next_arg(args, &param, &val);
Ard van Breemena416aba2007-01-05 16:36:20 -0800192 irq_was_disabled = irqs_disabled();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 ret = parse_one(param, val, params, num, unknown);
Ard van Breemena416aba2007-01-05 16:36:20 -0800194 if (irq_was_disabled && !irqs_disabled()) {
195 printk(KERN_WARNING "parse_args(): option '%s' enabled "
196 "irq's!\n", param);
197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 switch (ret) {
199 case -ENOENT:
200 printk(KERN_ERR "%s: Unknown parameter `%s'\n",
201 name, param);
202 return ret;
203 case -ENOSPC:
204 printk(KERN_ERR
205 "%s: `%s' too large for parameter `%s'\n",
206 name, val ?: "", param);
207 return ret;
208 case 0:
209 break;
210 default:
211 printk(KERN_ERR
212 "%s: `%s' invalid for parameter `%s'\n",
213 name, val ?: "", param);
214 return ret;
215 }
216 }
217
218 /* All parsed OK. */
219 return 0;
220}
221
222/* Lazy bastard, eh? */
223#define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600224 int param_set_##name(const char *val, const struct kernel_param *kp) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 tmptype l; \
Yi Yang06b2a762008-02-08 04:21:57 -0800227 int ret; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 \
Yi Yang06b2a762008-02-08 04:21:57 -0800229 ret = strtolfn(val, 0, &l); \
Satoru Moriya81c74132011-05-26 19:38:04 -0400230 if (ret < 0 || ((type)l != l)) \
231 return ret < 0 ? ret : -EINVAL; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 *((type *)kp->arg) = l; \
233 return 0; \
234 } \
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600235 int param_get_##name(char *buffer, const struct kernel_param *kp) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 { \
237 return sprintf(buffer, format, *((type *)kp->arg)); \
Rusty Russella14fe242010-08-11 23:04:11 -0600238 } \
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600239 struct kernel_param_ops param_ops_##name = { \
240 .set = param_set_##name, \
241 .get = param_get_##name, \
242 }; \
Rusty Russella14fe242010-08-11 23:04:11 -0600243 EXPORT_SYMBOL(param_set_##name); \
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600244 EXPORT_SYMBOL(param_get_##name); \
245 EXPORT_SYMBOL(param_ops_##name)
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Yi Yang06b2a762008-02-08 04:21:57 -0800248STANDARD_PARAM_DEF(byte, unsigned char, "%c", unsigned long, strict_strtoul);
249STANDARD_PARAM_DEF(short, short, "%hi", long, strict_strtol);
250STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, strict_strtoul);
251STANDARD_PARAM_DEF(int, int, "%i", long, strict_strtol);
252STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, strict_strtoul);
253STANDARD_PARAM_DEF(long, long, "%li", long, strict_strtol);
254STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600256int param_set_charp(const char *val, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (strlen(val) > 1024) {
259 printk(KERN_ERR "%s: string parameter too long\n",
260 kp->name);
261 return -ENOSPC;
262 }
263
Rusty Russella1054322010-08-11 23:04:18 -0600264 maybe_kfree_parameter(*(char **)kp->arg);
265
266 /* This is a hack. We can't kmalloc in early boot, and we
Rusty Russelle180a6b2009-03-31 13:05:29 -0600267 * don't need to; this mangled commandline is preserved. */
268 if (slab_is_available()) {
Rusty Russella1054322010-08-11 23:04:18 -0600269 *(char **)kp->arg = kmalloc_parameter(strlen(val)+1);
Rusty Russelld553ad82009-10-29 08:56:17 -0600270 if (!*(char **)kp->arg)
Rusty Russelle180a6b2009-03-31 13:05:29 -0600271 return -ENOMEM;
Rusty Russella1054322010-08-11 23:04:18 -0600272 strcpy(*(char **)kp->arg, val);
Rusty Russelle180a6b2009-03-31 13:05:29 -0600273 } else
274 *(const char **)kp->arg = val;
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return 0;
277}
Rusty Russella14fe242010-08-11 23:04:11 -0600278EXPORT_SYMBOL(param_set_charp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600280int param_get_charp(char *buffer, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
282 return sprintf(buffer, "%s", *((char **)kp->arg));
283}
Rusty Russella14fe242010-08-11 23:04:11 -0600284EXPORT_SYMBOL(param_get_charp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Rusty Russella1054322010-08-11 23:04:18 -0600286static void param_free_charp(void *arg)
287{
288 maybe_kfree_parameter(*((char **)arg));
289}
290
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600291struct kernel_param_ops param_ops_charp = {
292 .set = param_set_charp,
293 .get = param_get_charp,
Rusty Russella1054322010-08-11 23:04:18 -0600294 .free = param_free_charp,
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600295};
296EXPORT_SYMBOL(param_ops_charp);
297
Rusty Russellfddd5202009-06-12 21:46:57 -0600298/* Actually could be a bool or an int, for historical reasons. */
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600299int param_set_bool(const char *val, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Rusty Russellfddd5202009-06-12 21:46:57 -0600301 bool v;
Jonathan Cameronf721a462011-04-19 12:43:47 +0100302 int ret;
Rusty Russellfddd5202009-06-12 21:46:57 -0600303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 /* No equals means "set"... */
305 if (!val) val = "1";
306
307 /* One of =[yYnN01] */
Jonathan Cameronf721a462011-04-19 12:43:47 +0100308 ret = strtobool(val, &v);
309 if (ret)
310 return ret;
Rusty Russellfddd5202009-06-12 21:46:57 -0600311
312 if (kp->flags & KPARAM_ISBOOL)
313 *(bool *)kp->arg = v;
314 else
315 *(int *)kp->arg = v;
316 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
Rusty Russella14fe242010-08-11 23:04:11 -0600318EXPORT_SYMBOL(param_set_bool);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600320int param_get_bool(char *buffer, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Rusty Russellfddd5202009-06-12 21:46:57 -0600322 bool val;
323 if (kp->flags & KPARAM_ISBOOL)
324 val = *(bool *)kp->arg;
325 else
326 val = *(int *)kp->arg;
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 /* Y and N chosen as being relatively non-coder friendly */
Rusty Russellfddd5202009-06-12 21:46:57 -0600329 return sprintf(buffer, "%c", val ? 'Y' : 'N');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
Rusty Russella14fe242010-08-11 23:04:11 -0600331EXPORT_SYMBOL(param_get_bool);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600333struct kernel_param_ops param_ops_bool = {
334 .set = param_set_bool,
335 .get = param_get_bool,
336};
337EXPORT_SYMBOL(param_ops_bool);
338
Rusty Russellfddd5202009-06-12 21:46:57 -0600339/* This one must be bool. */
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600340int param_set_invbool(const char *val, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Rusty Russellfddd5202009-06-12 21:46:57 -0600342 int ret;
343 bool boolval;
Jan Beulich22e48ea2007-10-16 23:29:34 -0700344 struct kernel_param dummy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Jan Beulich22e48ea2007-10-16 23:29:34 -0700346 dummy.arg = &boolval;
Rusty Russellfddd5202009-06-12 21:46:57 -0600347 dummy.flags = KPARAM_ISBOOL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 ret = param_set_bool(val, &dummy);
349 if (ret == 0)
Rusty Russell9a71af22009-06-12 21:46:53 -0600350 *(bool *)kp->arg = !boolval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 return ret;
352}
Rusty Russella14fe242010-08-11 23:04:11 -0600353EXPORT_SYMBOL(param_set_invbool);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600355int param_get_invbool(char *buffer, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Rusty Russell9a71af22009-06-12 21:46:53 -0600357 return sprintf(buffer, "%c", (*(bool *)kp->arg) ? 'N' : 'Y');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
Rusty Russella14fe242010-08-11 23:04:11 -0600359EXPORT_SYMBOL(param_get_invbool);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600361struct kernel_param_ops param_ops_invbool = {
362 .set = param_set_invbool,
363 .get = param_get_invbool,
364};
365EXPORT_SYMBOL(param_ops_invbool);
366
Rusty Russell69116f22012-01-13 09:32:17 +1030367int param_set_bint(const char *val, const struct kernel_param *kp)
368{
369 struct kernel_param boolkp;
370 bool v;
371 int ret;
372
373 /* Match bool exactly, by re-using it. */
374 boolkp = *kp;
375 boolkp.arg = &v;
376 boolkp.flags |= KPARAM_ISBOOL;
377
378 ret = param_set_bool(val, &boolkp);
379 if (ret == 0)
380 *(int *)kp->arg = v;
381 return ret;
382}
383EXPORT_SYMBOL(param_set_bint);
384
385struct kernel_param_ops param_ops_bint = {
386 .set = param_set_bint,
387 .get = param_get_int,
388};
389EXPORT_SYMBOL(param_ops_bint);
390
Bert Wesarg9730b5b2007-05-08 00:28:50 -0700391/* We break the rule and mangle the string. */
Adrian Bunk98717282006-03-25 03:07:06 -0800392static int param_array(const char *name,
393 const char *val,
394 unsigned int min, unsigned int max,
395 void *elem, int elemsize,
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600396 int (*set)(const char *, const struct kernel_param *kp),
Rusty Russell3c7d76e2009-10-29 08:56:19 -0600397 u16 flags,
Richard Knutssoneb38a992008-02-06 01:37:50 -0800398 unsigned int *num)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
400 int ret;
401 struct kernel_param kp;
402 char save;
403
404 /* Get the name right for errors. */
405 kp.name = name;
406 kp.arg = elem;
Rusty Russell3c7d76e2009-10-29 08:56:19 -0600407 kp.flags = flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 *num = 0;
410 /* We expect a comma-separated list of values. */
411 do {
412 int len;
413
414 if (*num == max) {
415 printk(KERN_ERR "%s: can only take %i arguments\n",
416 name, max);
417 return -EINVAL;
418 }
419 len = strcspn(val, ",");
420
421 /* nul-terminate and parse */
422 save = val[len];
423 ((char *)val)[len] = '\0';
Rusty Russell907b29e2010-08-11 23:04:19 -0600424 BUG_ON(!mutex_is_locked(&param_lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 ret = set(val, &kp);
426
427 if (ret != 0)
428 return ret;
429 kp.arg += elemsize;
430 val += len+1;
431 (*num)++;
432 } while (save == ',');
433
434 if (*num < min) {
435 printk(KERN_ERR "%s: needs at least %i arguments\n",
436 name, min);
437 return -EINVAL;
438 }
439 return 0;
440}
441
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600442static int param_array_set(const char *val, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
Jan Beulich22e48ea2007-10-16 23:29:34 -0700444 const struct kparam_array *arr = kp->arr;
Bert Wesarg31143a12005-04-16 15:25:42 -0700445 unsigned int temp_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 return param_array(kp->name, val, 1, arr->max, arr->elem,
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600448 arr->elemsize, arr->ops->set, kp->flags,
Rusty Russell3c7d76e2009-10-29 08:56:19 -0600449 arr->num ?: &temp_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450}
451
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600452static int param_array_get(char *buffer, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
454 int i, off, ret;
Jan Beulich22e48ea2007-10-16 23:29:34 -0700455 const struct kparam_array *arr = kp->arr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 struct kernel_param p;
457
458 p = *kp;
459 for (i = off = 0; i < (arr->num ? *arr->num : arr->max); i++) {
460 if (i)
461 buffer[off++] = ',';
462 p.arg = arr->elem + arr->elemsize * i;
Rusty Russell907b29e2010-08-11 23:04:19 -0600463 BUG_ON(!mutex_is_locked(&param_lock));
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600464 ret = arr->ops->get(buffer + off, &p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 if (ret < 0)
466 return ret;
467 off += ret;
468 }
469 buffer[off] = '\0';
470 return off;
471}
472
Rusty Russelle6df34a2010-08-11 23:04:17 -0600473static void param_array_free(void *arg)
474{
475 unsigned int i;
476 const struct kparam_array *arr = arg;
477
478 if (arr->ops->free)
479 for (i = 0; i < (arr->num ? *arr->num : arr->max); i++)
480 arr->ops->free(arr->elem + arr->elemsize * i);
481}
482
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600483struct kernel_param_ops param_array_ops = {
484 .set = param_array_set,
485 .get = param_array_get,
Rusty Russelle6df34a2010-08-11 23:04:17 -0600486 .free = param_array_free,
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600487};
488EXPORT_SYMBOL(param_array_ops);
489
490int param_set_copystring(const char *val, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Jan Beulich22e48ea2007-10-16 23:29:34 -0700492 const struct kparam_string *kps = kp->str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 if (strlen(val)+1 > kps->maxlen) {
495 printk(KERN_ERR "%s: string doesn't fit in %u chars.\n",
496 kp->name, kps->maxlen-1);
497 return -ENOSPC;
498 }
499 strcpy(kps->string, val);
500 return 0;
501}
Rusty Russella14fe242010-08-11 23:04:11 -0600502EXPORT_SYMBOL(param_set_copystring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600504int param_get_string(char *buffer, const struct kernel_param *kp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
Jan Beulich22e48ea2007-10-16 23:29:34 -0700506 const struct kparam_string *kps = kp->str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 return strlcpy(buffer, kps->string, kps->maxlen);
508}
Rusty Russella14fe242010-08-11 23:04:11 -0600509EXPORT_SYMBOL(param_get_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600511struct kernel_param_ops param_ops_string = {
512 .set = param_set_copystring,
513 .get = param_get_string,
514};
515EXPORT_SYMBOL(param_ops_string);
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517/* sysfs output in /sys/modules/XYZ/parameters/ */
Edward Z. Yang350f8252010-02-01 18:26:59 -0500518#define to_module_attr(n) container_of(n, struct module_attribute, attr)
519#define to_module_kobject(n) container_of(n, struct module_kobject, kobj)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521extern struct kernel_param __start___param[], __stop___param[];
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523struct param_attribute
524{
525 struct module_attribute mattr;
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600526 const struct kernel_param *param;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527};
528
529struct module_param_attrs
530{
Rusty Russell9b473de2008-10-22 10:00:22 -0500531 unsigned int num;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 struct attribute_group grp;
533 struct param_attribute attrs[0];
534};
535
Randy Dunlapef665c12007-02-13 15:19:06 -0800536#ifdef CONFIG_SYSFS
Edward Z. Yang350f8252010-02-01 18:26:59 -0500537#define to_param_attr(n) container_of(n, struct param_attribute, mattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539static ssize_t param_attr_show(struct module_attribute *mattr,
Kay Sievers4befb022011-07-24 22:06:04 +0930540 struct module_kobject *mk, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
542 int count;
543 struct param_attribute *attribute = to_param_attr(mattr);
544
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600545 if (!attribute->param->ops->get)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return -EPERM;
547
Rusty Russell907b29e2010-08-11 23:04:19 -0600548 mutex_lock(&param_lock);
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600549 count = attribute->param->ops->get(buf, attribute->param);
Rusty Russell907b29e2010-08-11 23:04:19 -0600550 mutex_unlock(&param_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (count > 0) {
552 strcat(buf, "\n");
553 ++count;
554 }
555 return count;
556}
557
558/* sysfs always hands a nul-terminated string in buf. We rely on that. */
559static ssize_t param_attr_store(struct module_attribute *mattr,
Kay Sievers4befb022011-07-24 22:06:04 +0930560 struct module_kobject *km,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 const char *buf, size_t len)
562{
563 int err;
564 struct param_attribute *attribute = to_param_attr(mattr);
565
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600566 if (!attribute->param->ops->set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 return -EPERM;
568
Rusty Russell907b29e2010-08-11 23:04:19 -0600569 mutex_lock(&param_lock);
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600570 err = attribute->param->ops->set(buf, attribute->param);
Rusty Russell907b29e2010-08-11 23:04:19 -0600571 mutex_unlock(&param_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 if (!err)
573 return len;
574 return err;
575}
Randy Dunlapef665c12007-02-13 15:19:06 -0800576#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578#ifdef CONFIG_MODULES
579#define __modinit
580#else
581#define __modinit __init
582#endif
583
Randy Dunlapef665c12007-02-13 15:19:06 -0800584#ifdef CONFIG_SYSFS
Rusty Russell907b29e2010-08-11 23:04:19 -0600585void __kernel_param_lock(void)
586{
587 mutex_lock(&param_lock);
588}
589EXPORT_SYMBOL(__kernel_param_lock);
590
591void __kernel_param_unlock(void)
592{
593 mutex_unlock(&param_lock);
594}
595EXPORT_SYMBOL(__kernel_param_unlock);
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597/*
Rusty Russell9b473de2008-10-22 10:00:22 -0500598 * add_sysfs_param - add a parameter to sysfs
599 * @mk: struct module_kobject
600 * @kparam: the actual parameter definition to add to sysfs
601 * @name: name of parameter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 *
Rusty Russell9b473de2008-10-22 10:00:22 -0500603 * Create a kobject if for a (per-module) parameter if mp NULL, and
604 * create file in sysfs. Returns an error on out of memory. Always cleans up
605 * if there's an error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 */
Rusty Russell9b473de2008-10-22 10:00:22 -0500607static __modinit int add_sysfs_param(struct module_kobject *mk,
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600608 const struct kernel_param *kp,
Rusty Russell9b473de2008-10-22 10:00:22 -0500609 const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Rusty Russell9b473de2008-10-22 10:00:22 -0500611 struct module_param_attrs *new;
612 struct attribute **attrs;
613 int err, num;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Rusty Russell9b473de2008-10-22 10:00:22 -0500615 /* We don't bother calling this with invisible parameters. */
616 BUG_ON(!kp->perm);
617
618 if (!mk->mp) {
619 num = 0;
620 attrs = NULL;
621 } else {
622 num = mk->mp->num;
623 attrs = mk->mp->grp.attrs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 }
625
Rusty Russell9b473de2008-10-22 10:00:22 -0500626 /* Enlarge. */
627 new = krealloc(mk->mp,
628 sizeof(*mk->mp) + sizeof(mk->mp->attrs[0]) * (num+1),
629 GFP_KERNEL);
630 if (!new) {
631 kfree(mk->mp);
632 err = -ENOMEM;
633 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
Rusty Russell9b473de2008-10-22 10:00:22 -0500635 attrs = krealloc(attrs, sizeof(new->grp.attrs[0])*(num+2), GFP_KERNEL);
636 if (!attrs) {
637 err = -ENOMEM;
638 goto fail_free_new;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
Rusty Russell9b473de2008-10-22 10:00:22 -0500640
641 /* Sysfs wants everything zeroed. */
642 memset(new, 0, sizeof(*new));
643 memset(&new->attrs[num], 0, sizeof(new->attrs[num]));
644 memset(&attrs[num], 0, sizeof(attrs[num]));
645 new->grp.name = "parameters";
646 new->grp.attrs = attrs;
647
648 /* Tack new one on the end. */
Eric W. Biedermana07e4152010-02-11 15:23:05 -0800649 sysfs_attr_init(&new->attrs[num].mattr.attr);
Rusty Russell9b473de2008-10-22 10:00:22 -0500650 new->attrs[num].param = kp;
651 new->attrs[num].mattr.show = param_attr_show;
652 new->attrs[num].mattr.store = param_attr_store;
653 new->attrs[num].mattr.attr.name = (char *)name;
654 new->attrs[num].mattr.attr.mode = kp->perm;
655 new->num = num+1;
656
657 /* Fix up all the pointers, since krealloc can move us */
658 for (num = 0; num < new->num; num++)
659 new->grp.attrs[num] = &new->attrs[num].mattr.attr;
660 new->grp.attrs[num] = NULL;
661
662 mk->mp = new;
663 return 0;
664
665fail_free_new:
666 kfree(new);
667fail:
668 mk->mp = NULL;
669 return err;
670}
671
Linus Torvaldsd2441182008-10-23 12:07:17 -0700672#ifdef CONFIG_MODULES
Rusty Russell9b473de2008-10-22 10:00:22 -0500673static void free_module_param_attrs(struct module_kobject *mk)
674{
675 kfree(mk->mp->grp.attrs);
676 kfree(mk->mp);
677 mk->mp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680/*
681 * module_param_sysfs_setup - setup sysfs support for one module
682 * @mod: module
683 * @kparam: module parameters (array)
684 * @num_params: number of module parameters
685 *
Rusty Russell9b473de2008-10-22 10:00:22 -0500686 * Adds sysfs entries for module parameters under
687 * /sys/module/[mod->name]/parameters/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 */
689int module_param_sysfs_setup(struct module *mod,
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600690 const struct kernel_param *kparam,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 unsigned int num_params)
692{
Rusty Russell9b473de2008-10-22 10:00:22 -0500693 int i, err;
694 bool params = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Rusty Russell9b473de2008-10-22 10:00:22 -0500696 for (i = 0; i < num_params; i++) {
697 if (kparam[i].perm == 0)
698 continue;
699 err = add_sysfs_param(&mod->mkobj, &kparam[i], kparam[i].name);
700 if (err)
701 return err;
702 params = true;
703 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Rusty Russell9b473de2008-10-22 10:00:22 -0500705 if (!params)
706 return 0;
707
708 /* Create the param group. */
709 err = sysfs_create_group(&mod->mkobj.kobj, &mod->mkobj.mp->grp);
710 if (err)
711 free_module_param_attrs(&mod->mkobj);
712 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
715/*
716 * module_param_sysfs_remove - remove sysfs support for one module
717 * @mod: module
718 *
719 * Remove sysfs entries for module parameters and the corresponding
720 * kobject.
721 */
722void module_param_sysfs_remove(struct module *mod)
723{
Rusty Russell9b473de2008-10-22 10:00:22 -0500724 if (mod->mkobj.mp) {
725 sysfs_remove_group(&mod->mkobj.kobj, &mod->mkobj.mp->grp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 /* We are positive that no one is using any param
727 * attrs at this point. Deallocate immediately. */
Rusty Russell9b473de2008-10-22 10:00:22 -0500728 free_module_param_attrs(&mod->mkobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 }
730}
731#endif
732
Rusty Russelle180a6b2009-03-31 13:05:29 -0600733void destroy_params(const struct kernel_param *params, unsigned num)
734{
Rusty Russelle6df34a2010-08-11 23:04:17 -0600735 unsigned int i;
736
737 for (i = 0; i < num; i++)
738 if (params[i].ops->free)
739 params[i].ops->free(params[i].arg);
Rusty Russelle180a6b2009-03-31 13:05:29 -0600740}
741
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800742static struct module_kobject * __init locate_module_kobject(const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
744 struct module_kobject *mk;
Rusty Russell9b473de2008-10-22 10:00:22 -0500745 struct kobject *kobj;
746 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Rusty Russell9b473de2008-10-22 10:00:22 -0500748 kobj = kset_find_obj(module_kset, name);
749 if (kobj) {
Rusty Russell9b473de2008-10-22 10:00:22 -0500750 mk = to_module_kobject(kobj);
Rusty Russell9b473de2008-10-22 10:00:22 -0500751 } else {
752 mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL);
753 BUG_ON(!mk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Rusty Russell9b473de2008-10-22 10:00:22 -0500755 mk->mod = THIS_MODULE;
756 mk->kobj.kset = module_kset;
757 err = kobject_init_and_add(&mk->kobj, &module_ktype, NULL,
758 "%s", name);
Kay Sievers88bfa322011-07-24 22:06:04 +0930759#ifdef CONFIG_MODULES
760 if (!err)
761 err = sysfs_create_file(&mk->kobj, &module_uevent.attr);
762#endif
Rusty Russell9b473de2008-10-22 10:00:22 -0500763 if (err) {
764 kobject_put(&mk->kobj);
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800765 printk(KERN_ERR
766 "Module '%s' failed add to sysfs, error number %d\n",
767 name, err);
768 printk(KERN_ERR
769 "The system will be unstable now.\n");
770 return NULL;
Rusty Russell9b473de2008-10-22 10:00:22 -0500771 }
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800772
773 /* So that we hold reference in both cases. */
Rusty Russell9b473de2008-10-22 10:00:22 -0500774 kobject_get(&mk->kobj);
Greg Kroah-Hartman74c5b592007-07-30 11:26:38 -0700775 }
Rusty Russell9b473de2008-10-22 10:00:22 -0500776
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800777 return mk;
778}
779
780static void __init kernel_add_sysfs_param(const char *name,
781 struct kernel_param *kparam,
782 unsigned int name_skip)
783{
784 struct module_kobject *mk;
785 int err;
786
787 mk = locate_module_kobject(name);
788 if (!mk)
789 return;
790
791 /* We need to remove old parameters before adding more. */
792 if (mk->mp)
793 sysfs_remove_group(&mk->kobj, &mk->mp->grp);
794
Rusty Russell9b473de2008-10-22 10:00:22 -0500795 /* These should not fail at boot. */
796 err = add_sysfs_param(mk, kparam, kparam->name + name_skip);
797 BUG_ON(err);
798 err = sysfs_create_group(&mk->kobj, &mk->mp->grp);
799 BUG_ON(err);
Kay Sieversf30c53a2007-01-15 20:22:02 +0100800 kobject_uevent(&mk->kobj, KOBJ_ADD);
Rusty Russell9b473de2008-10-22 10:00:22 -0500801 kobject_put(&mk->kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802}
803
804/*
805 * param_sysfs_builtin - add contents in /sys/parameters for built-in modules
806 *
807 * Add module_parameters to sysfs for "modules" built into the kernel.
808 *
809 * The "module" name (KBUILD_MODNAME) is stored before a dot, the
810 * "parameter" name is stored behind a dot in kernel_param->name. So,
811 * extract the "module" name for all built-in kernel_param-eters,
Rusty Russell9b473de2008-10-22 10:00:22 -0500812 * and for all who have the same, call kernel_add_sysfs_param.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 */
814static void __init param_sysfs_builtin(void)
815{
Rusty Russell9b473de2008-10-22 10:00:22 -0500816 struct kernel_param *kp;
817 unsigned int name_len;
818 char modname[MODULE_NAME_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Rusty Russell9b473de2008-10-22 10:00:22 -0500820 for (kp = __start___param; kp < __stop___param; kp++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 char *dot;
822
Rusty Russell9b473de2008-10-22 10:00:22 -0500823 if (kp->perm == 0)
824 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Rusty Russell730b69d2008-10-22 10:00:22 -0500826 dot = strchr(kp->name, '.');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 if (!dot) {
Rusty Russell67e67ce2008-10-22 10:00:23 -0500828 /* This happens for core_param() */
829 strcpy(modname, "kernel");
830 name_len = 0;
831 } else {
832 name_len = dot - kp->name + 1;
833 strlcpy(modname, kp->name, name_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
Rusty Russell67e67ce2008-10-22 10:00:23 -0500835 kernel_add_sysfs_param(modname, kp, name_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837}
838
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800839ssize_t __modver_version_show(struct module_attribute *mattr,
Kay Sievers4befb022011-07-24 22:06:04 +0930840 struct module_kobject *mk, char *buf)
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800841{
842 struct module_version_attribute *vattr =
843 container_of(mattr, struct module_version_attribute, mattr);
844
845 return sprintf(buf, "%s\n", vattr->version);
846}
847
Dmitry Torokhovb4bc84282011-02-07 16:02:25 -0800848extern const struct module_version_attribute *__start___modver[];
849extern const struct module_version_attribute *__stop___modver[];
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800850
851static void __init version_sysfs_builtin(void)
852{
Dmitry Torokhovb4bc84282011-02-07 16:02:25 -0800853 const struct module_version_attribute **p;
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800854 struct module_kobject *mk;
855 int err;
856
Dmitry Torokhovb4bc84282011-02-07 16:02:25 -0800857 for (p = __start___modver; p < __stop___modver; p++) {
858 const struct module_version_attribute *vattr = *p;
859
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800860 mk = locate_module_kobject(vattr->module_name);
861 if (mk) {
862 err = sysfs_create_file(&mk->kobj, &vattr->mattr.attr);
863 kobject_uevent(&mk->kobj, KOBJ_ADD);
864 kobject_put(&mk->kobj);
865 }
866 }
867}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869/* module-related sysfs stuff */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871static ssize_t module_attr_show(struct kobject *kobj,
872 struct attribute *attr,
873 char *buf)
874{
875 struct module_attribute *attribute;
876 struct module_kobject *mk;
877 int ret;
878
879 attribute = to_module_attr(attr);
880 mk = to_module_kobject(kobj);
881
882 if (!attribute->show)
Dmitry Torokhov70f28172005-04-29 01:27:34 -0500883 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
Kay Sievers4befb022011-07-24 22:06:04 +0930885 ret = attribute->show(attribute, mk, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 return ret;
888}
889
890static ssize_t module_attr_store(struct kobject *kobj,
891 struct attribute *attr,
892 const char *buf, size_t len)
893{
894 struct module_attribute *attribute;
895 struct module_kobject *mk;
896 int ret;
897
898 attribute = to_module_attr(attr);
899 mk = to_module_kobject(kobj);
900
901 if (!attribute->store)
Dmitry Torokhov70f28172005-04-29 01:27:34 -0500902 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Kay Sievers4befb022011-07-24 22:06:04 +0930904 ret = attribute->store(attribute, mk, buf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 return ret;
907}
908
Emese Revfy52cf25d2010-01-19 02:58:23 +0100909static const struct sysfs_ops module_sysfs_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .show = module_attr_show,
911 .store = module_attr_store,
912};
913
Kay Sievers270a6c42007-01-18 13:26:15 +0100914static int uevent_filter(struct kset *kset, struct kobject *kobj)
915{
916 struct kobj_type *ktype = get_ktype(kobj);
917
918 if (ktype == &module_ktype)
919 return 1;
920 return 0;
921}
922
Emese Revfy9cd43612009-12-31 14:52:51 +0100923static const struct kset_uevent_ops module_uevent_ops = {
Kay Sievers270a6c42007-01-18 13:26:15 +0100924 .filter = uevent_filter,
925};
926
Greg Kroah-Hartman7405c1e2007-11-01 10:39:50 -0700927struct kset *module_kset;
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700928int module_sysfs_initialized;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Greg Kroah-Hartman7405c1e2007-11-01 10:39:50 -0700930struct kobj_type module_ktype = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 .sysfs_ops = &module_sysfs_ops,
932};
933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934/*
935 * param_sysfs_init - wrapper for built-in params support
936 */
937static int __init param_sysfs_init(void)
938{
Greg Kroah-Hartman7405c1e2007-11-01 10:39:50 -0700939 module_kset = kset_create_and_add("module", &module_uevent_ops, NULL);
940 if (!module_kset) {
941 printk(KERN_WARNING "%s (%d): error creating kset\n",
942 __FILE__, __LINE__);
943 return -ENOMEM;
Randy Dunlapd8c76492006-09-29 01:58:55 -0700944 }
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700945 module_sysfs_initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
Dmitry Torokhove94965e2010-12-15 14:00:19 -0800947 version_sysfs_builtin();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 param_sysfs_builtin();
949
950 return 0;
951}
Mark Huangd10be6d2006-09-29 01:59:34 -0700952subsys_initcall(param_sysfs_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Greg Kroah-Hartman7405c1e2007-11-01 10:39:50 -0700954#endif /* CONFIG_SYSFS */