inode.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * inode.c - part of debugfs, a tiny little debug file system
  3. *
  4. * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
  5. * Copyright (C) 2004 IBM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version
  9. * 2 as published by the Free Software Foundation.
  10. *
  11. * debugfs is for people to use instead of /proc or /sys.
  12. * See Documentation/DocBook/kernel-api for more details.
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/fs.h>
  17. #include <linux/mount.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/init.h>
  20. #include <linux/kobject.h>
  21. #include <linux/namei.h>
  22. #include <linux/debugfs.h>
  23. #include <linux/fsnotify.h>
  24. #include <linux/string.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/parser.h>
  27. #include <linux/magic.h>
  28. #include <linux/slab.h>
  29. #define DEBUGFS_DEFAULT_MODE 0700
  30. static struct vfsmount *debugfs_mount;
  31. static int debugfs_mount_count;
  32. static bool debugfs_registered;
  33. static struct inode *debugfs_get_inode(struct super_block *sb, umode_t mode, dev_t dev,
  34. void *data, const struct file_operations *fops)
  35. {
  36. struct inode *inode = new_inode(sb);
  37. if (inode) {
  38. inode->i_ino = get_next_ino();
  39. inode->i_mode = mode;
  40. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  41. switch (mode & S_IFMT) {
  42. default:
  43. init_special_inode(inode, mode, dev);
  44. break;
  45. case S_IFREG:
  46. inode->i_fop = fops ? fops : &debugfs_file_operations;
  47. inode->i_private = data;
  48. break;
  49. case S_IFLNK:
  50. inode->i_op = &debugfs_link_operations;
  51. inode->i_private = data;
  52. break;
  53. case S_IFDIR:
  54. inode->i_op = &simple_dir_inode_operations;
  55. inode->i_fop = &simple_dir_operations;
  56. /* directory inodes start off with i_nlink == 2
  57. * (for "." entry) */
  58. inc_nlink(inode);
  59. break;
  60. }
  61. }
  62. return inode;
  63. }
  64. /* SMP-safe */
  65. static int debugfs_mknod(struct inode *dir, struct dentry *dentry,
  66. umode_t mode, dev_t dev, void *data,
  67. const struct file_operations *fops)
  68. {
  69. struct inode *inode;
  70. int error = -EPERM;
  71. if (dentry->d_inode)
  72. return -EEXIST;
  73. inode = debugfs_get_inode(dir->i_sb, mode, dev, data, fops);
  74. if (inode) {
  75. d_instantiate(dentry, inode);
  76. dget(dentry);
  77. error = 0;
  78. }
  79. return error;
  80. }
  81. static int debugfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  82. {
  83. int res;
  84. mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
  85. res = debugfs_mknod(dir, dentry, mode, 0, NULL, NULL);
  86. if (!res) {
  87. inc_nlink(dir);
  88. fsnotify_mkdir(dir, dentry);
  89. }
  90. return res;
  91. }
  92. static int debugfs_link(struct inode *dir, struct dentry *dentry, umode_t mode,
  93. void *data)
  94. {
  95. mode = (mode & S_IALLUGO) | S_IFLNK;
  96. return debugfs_mknod(dir, dentry, mode, 0, data, NULL);
  97. }
  98. static int debugfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
  99. void *data, const struct file_operations *fops)
  100. {
  101. int res;
  102. mode = (mode & S_IALLUGO) | S_IFREG;
  103. res = debugfs_mknod(dir, dentry, mode, 0, data, fops);
  104. if (!res)
  105. fsnotify_create(dir, dentry);
  106. return res;
  107. }
  108. static inline int debugfs_positive(struct dentry *dentry)
  109. {
  110. return dentry->d_inode && !d_unhashed(dentry);
  111. }
  112. struct debugfs_mount_opts {
  113. kuid_t uid;
  114. kgid_t gid;
  115. umode_t mode;
  116. };
  117. enum {
  118. Opt_uid,
  119. Opt_gid,
  120. Opt_mode,
  121. Opt_err
  122. };
  123. static const match_table_t tokens = {
  124. {Opt_uid, "uid=%u"},
  125. {Opt_gid, "gid=%u"},
  126. {Opt_mode, "mode=%o"},
  127. {Opt_err, NULL}
  128. };
  129. struct debugfs_fs_info {
  130. struct debugfs_mount_opts mount_opts;
  131. };
  132. static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts)
  133. {
  134. substring_t args[MAX_OPT_ARGS];
  135. int option;
  136. int token;
  137. kuid_t uid;
  138. kgid_t gid;
  139. char *p;
  140. opts->mode = DEBUGFS_DEFAULT_MODE;
  141. while ((p = strsep(&data, ",")) != NULL) {
  142. if (!*p)
  143. continue;
  144. token = match_token(p, tokens, args);
  145. switch (token) {
  146. case Opt_uid:
  147. if (match_int(&args[0], &option))
  148. return -EINVAL;
  149. uid = make_kuid(current_user_ns(), option);
  150. if (!uid_valid(uid))
  151. return -EINVAL;
  152. opts->uid = uid;
  153. break;
  154. case Opt_gid:
  155. if (match_int(&args[0], &option))
  156. return -EINVAL;
  157. gid = make_kgid(current_user_ns(), option);
  158. if (!gid_valid(gid))
  159. return -EINVAL;
  160. opts->gid = gid;
  161. break;
  162. case Opt_mode:
  163. if (match_octal(&args[0], &option))
  164. return -EINVAL;
  165. opts->mode = option & S_IALLUGO;
  166. break;
  167. /*
  168. * We might like to report bad mount options here;
  169. * but traditionally debugfs has ignored all mount options
  170. */
  171. }
  172. }
  173. return 0;
  174. }
  175. static int debugfs_apply_options(struct super_block *sb)
  176. {
  177. struct debugfs_fs_info *fsi = sb->s_fs_info;
  178. struct inode *inode = sb->s_root->d_inode;
  179. struct debugfs_mount_opts *opts = &fsi->mount_opts;
  180. inode->i_mode &= ~S_IALLUGO;
  181. inode->i_mode |= opts->mode;
  182. inode->i_uid = opts->uid;
  183. inode->i_gid = opts->gid;
  184. return 0;
  185. }
  186. static int debugfs_remount(struct super_block *sb, int *flags, char *data)
  187. {
  188. int err;
  189. struct debugfs_fs_info *fsi = sb->s_fs_info;
  190. sync_filesystem(sb);
  191. err = debugfs_parse_options(data, &fsi->mount_opts);
  192. if (err)
  193. goto fail;
  194. debugfs_apply_options(sb);
  195. fail:
  196. return err;
  197. }
  198. static int debugfs_show_options(struct seq_file *m, struct dentry *root)
  199. {
  200. struct debugfs_fs_info *fsi = root->d_sb->s_fs_info;
  201. struct debugfs_mount_opts *opts = &fsi->mount_opts;
  202. if (!uid_eq(opts->uid, GLOBAL_ROOT_UID))
  203. seq_printf(m, ",uid=%u",
  204. from_kuid_munged(&init_user_ns, opts->uid));
  205. if (!gid_eq(opts->gid, GLOBAL_ROOT_GID))
  206. seq_printf(m, ",gid=%u",
  207. from_kgid_munged(&init_user_ns, opts->gid));
  208. if (opts->mode != DEBUGFS_DEFAULT_MODE)
  209. seq_printf(m, ",mode=%o", opts->mode);
  210. return 0;
  211. }
  212. static const struct super_operations debugfs_super_operations = {
  213. .statfs = simple_statfs,
  214. .remount_fs = debugfs_remount,
  215. .show_options = debugfs_show_options,
  216. };
  217. static int debug_fill_super(struct super_block *sb, void *data, int silent)
  218. {
  219. static struct tree_descr debug_files[] = {{""}};
  220. struct debugfs_fs_info *fsi;
  221. int err;
  222. save_mount_options(sb, data);
  223. fsi = kzalloc(sizeof(struct debugfs_fs_info), GFP_KERNEL);
  224. sb->s_fs_info = fsi;
  225. if (!fsi) {
  226. err = -ENOMEM;
  227. goto fail;
  228. }
  229. err = debugfs_parse_options(data, &fsi->mount_opts);
  230. if (err)
  231. goto fail;
  232. err = simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
  233. if (err)
  234. goto fail;
  235. sb->s_op = &debugfs_super_operations;
  236. debugfs_apply_options(sb);
  237. return 0;
  238. fail:
  239. kfree(fsi);
  240. sb->s_fs_info = NULL;
  241. return err;
  242. }
  243. static struct dentry *debug_mount(struct file_system_type *fs_type,
  244. int flags, const char *dev_name,
  245. void *data)
  246. {
  247. return mount_single(fs_type, flags, data, debug_fill_super);
  248. }
  249. static struct file_system_type debug_fs_type = {
  250. .owner = THIS_MODULE,
  251. .name = "debugfs",
  252. .mount = debug_mount,
  253. .kill_sb = kill_litter_super,
  254. };
  255. MODULE_ALIAS_FS("debugfs");
  256. static struct dentry *__create_file(const char *name, umode_t mode,
  257. struct dentry *parent, void *data,
  258. const struct file_operations *fops)
  259. {
  260. struct dentry *dentry = NULL;
  261. int error;
  262. pr_debug("debugfs: creating file '%s'\n",name);
  263. error = simple_pin_fs(&debug_fs_type, &debugfs_mount,
  264. &debugfs_mount_count);
  265. if (error)
  266. goto exit;
  267. /* If the parent is not specified, we create it in the root.
  268. * We need the root dentry to do this, which is in the super
  269. * block. A pointer to that is in the struct vfsmount that we
  270. * have around.
  271. */
  272. if (!parent)
  273. parent = debugfs_mount->mnt_root;
  274. mutex_lock(&parent->d_inode->i_mutex);
  275. dentry = lookup_one_len(name, parent, strlen(name));
  276. if (!IS_ERR(dentry)) {
  277. switch (mode & S_IFMT) {
  278. case S_IFDIR:
  279. error = debugfs_mkdir(parent->d_inode, dentry, mode);
  280. break;
  281. case S_IFLNK:
  282. error = debugfs_link(parent->d_inode, dentry, mode,
  283. data);
  284. break;
  285. default:
  286. error = debugfs_create(parent->d_inode, dentry, mode,
  287. data, fops);
  288. break;
  289. }
  290. dput(dentry);
  291. } else
  292. error = PTR_ERR(dentry);
  293. mutex_unlock(&parent->d_inode->i_mutex);
  294. if (error) {
  295. dentry = NULL;
  296. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  297. }
  298. exit:
  299. return dentry;
  300. }
  301. /**
  302. * debugfs_create_file - create a file in the debugfs filesystem
  303. * @name: a pointer to a string containing the name of the file to create.
  304. * @mode: the permission that the file should have.
  305. * @parent: a pointer to the parent dentry for this file. This should be a
  306. * directory dentry if set. If this parameter is NULL, then the
  307. * file will be created in the root of the debugfs filesystem.
  308. * @data: a pointer to something that the caller will want to get to later
  309. * on. The inode.i_private pointer will point to this value on
  310. * the open() call.
  311. * @fops: a pointer to a struct file_operations that should be used for
  312. * this file.
  313. *
  314. * This is the basic "create a file" function for debugfs. It allows for a
  315. * wide range of flexibility in creating a file, or a directory (if you want
  316. * to create a directory, the debugfs_create_dir() function is
  317. * recommended to be used instead.)
  318. *
  319. * This function will return a pointer to a dentry if it succeeds. This
  320. * pointer must be passed to the debugfs_remove() function when the file is
  321. * to be removed (no automatic cleanup happens if your module is unloaded,
  322. * you are responsible here.) If an error occurs, %NULL will be returned.
  323. *
  324. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  325. * returned.
  326. */
  327. struct dentry *debugfs_create_file(const char *name, umode_t mode,
  328. struct dentry *parent, void *data,
  329. const struct file_operations *fops)
  330. {
  331. switch (mode & S_IFMT) {
  332. case S_IFREG:
  333. case 0:
  334. break;
  335. default:
  336. BUG();
  337. }
  338. return __create_file(name, mode, parent, data, fops);
  339. }
  340. EXPORT_SYMBOL_GPL(debugfs_create_file);
  341. /**
  342. * debugfs_create_dir - create a directory in the debugfs filesystem
  343. * @name: a pointer to a string containing the name of the directory to
  344. * create.
  345. * @parent: a pointer to the parent dentry for this file. This should be a
  346. * directory dentry if set. If this parameter is NULL, then the
  347. * directory will be created in the root of the debugfs filesystem.
  348. *
  349. * This function creates a directory in debugfs with the given name.
  350. *
  351. * This function will return a pointer to a dentry if it succeeds. This
  352. * pointer must be passed to the debugfs_remove() function when the file is
  353. * to be removed (no automatic cleanup happens if your module is unloaded,
  354. * you are responsible here.) If an error occurs, %NULL will be returned.
  355. *
  356. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  357. * returned.
  358. */
  359. struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
  360. {
  361. return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
  362. parent, NULL, NULL);
  363. }
  364. EXPORT_SYMBOL_GPL(debugfs_create_dir);
  365. /**
  366. * debugfs_create_symlink- create a symbolic link in the debugfs filesystem
  367. * @name: a pointer to a string containing the name of the symbolic link to
  368. * create.
  369. * @parent: a pointer to the parent dentry for this symbolic link. This
  370. * should be a directory dentry if set. If this parameter is NULL,
  371. * then the symbolic link will be created in the root of the debugfs
  372. * filesystem.
  373. * @target: a pointer to a string containing the path to the target of the
  374. * symbolic link.
  375. *
  376. * This function creates a symbolic link with the given name in debugfs that
  377. * links to the given target path.
  378. *
  379. * This function will return a pointer to a dentry if it succeeds. This
  380. * pointer must be passed to the debugfs_remove() function when the symbolic
  381. * link is to be removed (no automatic cleanup happens if your module is
  382. * unloaded, you are responsible here.) If an error occurs, %NULL will be
  383. * returned.
  384. *
  385. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  386. * returned.
  387. */
  388. struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
  389. const char *target)
  390. {
  391. struct dentry *result;
  392. char *link;
  393. link = kstrdup(target, GFP_KERNEL);
  394. if (!link)
  395. return NULL;
  396. result = __create_file(name, S_IFLNK | S_IRWXUGO, parent, link, NULL);
  397. if (!result)
  398. kfree(link);
  399. return result;
  400. }
  401. EXPORT_SYMBOL_GPL(debugfs_create_symlink);
  402. static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
  403. {
  404. int ret = 0;
  405. if (debugfs_positive(dentry)) {
  406. if (dentry->d_inode) {
  407. dget(dentry);
  408. switch (dentry->d_inode->i_mode & S_IFMT) {
  409. case S_IFDIR:
  410. ret = simple_rmdir(parent->d_inode, dentry);
  411. break;
  412. case S_IFLNK:
  413. kfree(dentry->d_inode->i_private);
  414. /* fall through */
  415. default:
  416. simple_unlink(parent->d_inode, dentry);
  417. break;
  418. }
  419. if (!ret)
  420. d_delete(dentry);
  421. dput(dentry);
  422. }
  423. }
  424. return ret;
  425. }
  426. /**
  427. * debugfs_remove - removes a file or directory from the debugfs filesystem
  428. * @dentry: a pointer to a the dentry of the file or directory to be
  429. * removed.
  430. *
  431. * This function removes a file or directory in debugfs that was previously
  432. * created with a call to another debugfs function (like
  433. * debugfs_create_file() or variants thereof.)
  434. *
  435. * This function is required to be called in order for the file to be
  436. * removed, no automatic cleanup of files will happen when a module is
  437. * removed, you are responsible here.
  438. */
  439. void debugfs_remove(struct dentry *dentry)
  440. {
  441. struct dentry *parent;
  442. int ret;
  443. if (IS_ERR_OR_NULL(dentry))
  444. return;
  445. parent = dentry->d_parent;
  446. if (!parent || !parent->d_inode)
  447. return;
  448. mutex_lock(&parent->d_inode->i_mutex);
  449. ret = __debugfs_remove(dentry, parent);
  450. mutex_unlock(&parent->d_inode->i_mutex);
  451. if (!ret)
  452. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  453. }
  454. EXPORT_SYMBOL_GPL(debugfs_remove);
  455. /**
  456. * debugfs_remove_recursive - recursively removes a directory
  457. * @dentry: a pointer to a the dentry of the directory to be removed.
  458. *
  459. * This function recursively removes a directory tree in debugfs that
  460. * was previously created with a call to another debugfs function
  461. * (like debugfs_create_file() or variants thereof.)
  462. *
  463. * This function is required to be called in order for the file to be
  464. * removed, no automatic cleanup of files will happen when a module is
  465. * removed, you are responsible here.
  466. */
  467. void debugfs_remove_recursive(struct dentry *dentry)
  468. {
  469. struct dentry *child, *parent;
  470. if (IS_ERR_OR_NULL(dentry))
  471. return;
  472. parent = dentry->d_parent;
  473. if (!parent || !parent->d_inode)
  474. return;
  475. parent = dentry;
  476. down:
  477. mutex_lock(&parent->d_inode->i_mutex);
  478. loop:
  479. /*
  480. * The parent->d_subdirs is protected by the d_lock. Outside that
  481. * lock, the child can be unlinked and set to be freed which can
  482. * use the d_u.d_child as the rcu head and corrupt this list.
  483. */
  484. spin_lock(&parent->d_lock);
  485. list_for_each_entry(child, &parent->d_subdirs, d_child) {
  486. if (!debugfs_positive(child))
  487. continue;
  488. /* perhaps simple_empty(child) makes more sense */
  489. if (!list_empty(&child->d_subdirs)) {
  490. spin_unlock(&parent->d_lock);
  491. mutex_unlock(&parent->d_inode->i_mutex);
  492. parent = child;
  493. goto down;
  494. }
  495. spin_unlock(&parent->d_lock);
  496. if (!__debugfs_remove(child, parent))
  497. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  498. /*
  499. * The parent->d_lock protects agaist child from unlinking
  500. * from d_subdirs. When releasing the parent->d_lock we can
  501. * no longer trust that the next pointer is valid.
  502. * Restart the loop. We'll skip this one with the
  503. * debugfs_positive() check.
  504. */
  505. goto loop;
  506. }
  507. spin_unlock(&parent->d_lock);
  508. mutex_unlock(&parent->d_inode->i_mutex);
  509. child = parent;
  510. parent = parent->d_parent;
  511. mutex_lock(&parent->d_inode->i_mutex);
  512. if (child != dentry)
  513. /* go up */
  514. goto loop;
  515. if (!__debugfs_remove(child, parent))
  516. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  517. mutex_unlock(&parent->d_inode->i_mutex);
  518. }
  519. EXPORT_SYMBOL_GPL(debugfs_remove_recursive);
  520. /**
  521. * debugfs_rename - rename a file/directory in the debugfs filesystem
  522. * @old_dir: a pointer to the parent dentry for the renamed object. This
  523. * should be a directory dentry.
  524. * @old_dentry: dentry of an object to be renamed.
  525. * @new_dir: a pointer to the parent dentry where the object should be
  526. * moved. This should be a directory dentry.
  527. * @new_name: a pointer to a string containing the target name.
  528. *
  529. * This function renames a file/directory in debugfs. The target must not
  530. * exist for rename to succeed.
  531. *
  532. * This function will return a pointer to old_dentry (which is updated to
  533. * reflect renaming) if it succeeds. If an error occurs, %NULL will be
  534. * returned.
  535. *
  536. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  537. * returned.
  538. */
  539. struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
  540. struct dentry *new_dir, const char *new_name)
  541. {
  542. int error;
  543. struct dentry *dentry = NULL, *trap;
  544. const char *old_name;
  545. trap = lock_rename(new_dir, old_dir);
  546. /* Source or destination directories don't exist? */
  547. if (!old_dir->d_inode || !new_dir->d_inode)
  548. goto exit;
  549. /* Source does not exist, cyclic rename, or mountpoint? */
  550. if (!old_dentry->d_inode || old_dentry == trap ||
  551. d_mountpoint(old_dentry))
  552. goto exit;
  553. dentry = lookup_one_len(new_name, new_dir, strlen(new_name));
  554. /* Lookup failed, cyclic rename or target exists? */
  555. if (IS_ERR(dentry) || dentry == trap || dentry->d_inode)
  556. goto exit;
  557. old_name = fsnotify_oldname_init(old_dentry->d_name.name);
  558. error = simple_rename(old_dir->d_inode, old_dentry, new_dir->d_inode,
  559. dentry);
  560. if (error) {
  561. fsnotify_oldname_free(old_name);
  562. goto exit;
  563. }
  564. d_move(old_dentry, dentry);
  565. fsnotify_move(old_dir->d_inode, new_dir->d_inode, old_name,
  566. S_ISDIR(old_dentry->d_inode->i_mode),
  567. NULL, old_dentry);
  568. fsnotify_oldname_free(old_name);
  569. unlock_rename(new_dir, old_dir);
  570. dput(dentry);
  571. return old_dentry;
  572. exit:
  573. if (dentry && !IS_ERR(dentry))
  574. dput(dentry);
  575. unlock_rename(new_dir, old_dir);
  576. return NULL;
  577. }
  578. EXPORT_SYMBOL_GPL(debugfs_rename);
  579. /**
  580. * debugfs_initialized - Tells whether debugfs has been registered
  581. */
  582. bool debugfs_initialized(void)
  583. {
  584. return debugfs_registered;
  585. }
  586. EXPORT_SYMBOL_GPL(debugfs_initialized);
  587. static struct kobject *debug_kobj;
  588. static int __init debugfs_init(void)
  589. {
  590. int retval;
  591. debug_kobj = kobject_create_and_add("debug", kernel_kobj);
  592. if (!debug_kobj)
  593. return -EINVAL;
  594. retval = register_filesystem(&debug_fs_type);
  595. if (retval)
  596. kobject_put(debug_kobj);
  597. else
  598. debugfs_registered = true;
  599. return retval;
  600. }
  601. core_initcall(debugfs_init);