blob: eac184e6d65774da9a39cf70e6f71848a1a373d5 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Kay Sievers2b2af542009-04-30 15:23:42 +02002/*
3 * devtmpfs - kernel-maintained tmpfs-based /dev
4 *
5 * Copyright (C) 2009, Kay Sievers <kay.sievers@vrfy.org>
6 *
7 * During bootup, before any driver core device is registered,
8 * devtmpfs, a tmpfs-based filesystem is created. Every driver-core
9 * device which requests a device node, will add a node in this
Kay Sieverse454cea2009-09-18 23:01:12 +020010 * filesystem.
Peter Korsgaard02fbe5e2012-04-17 12:13:18 +020011 * By default, all devices are named after the name of the device,
12 * owned by root and have a default mode of 0600. Subsystems can
13 * overwrite the default setting if needed.
Kay Sievers2b2af542009-04-30 15:23:42 +020014 */
15
16#include <linux/kernel.h>
17#include <linux/syscalls.h>
18#include <linux/mount.h>
19#include <linux/device.h>
20#include <linux/genhd.h>
21#include <linux/namei.h>
22#include <linux/fs.h>
23#include <linux/shmem_fs.h>
Peter Korsgaardda5e4ef2010-03-16 21:55:21 +010024#include <linux/ramfs.h>
Kay Sieverse454cea2009-09-18 23:01:12 +020025#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Al Viro2780f1f2011-06-27 16:25:29 -040027#include <linux/kthread.h>
Christoph Hellwigc60166f2020-07-21 11:12:08 +020028#include <linux/init_syscalls.h>
David Howellse262e32d2018-11-01 23:07:23 +000029#include <uapi/linux/mount.h>
Greg Kroah-Hartmanc3a30422013-04-10 09:00:15 -070030#include "base.h"
Kay Sievers2b2af542009-04-30 15:23:42 +020031
Al Viro2780f1f2011-06-27 16:25:29 -040032static struct task_struct *thread;
Kay Sievers2b2af542009-04-30 15:23:42 +020033
Rasmus Villemoesfad1db82020-01-15 19:41:52 +010034static int __initdata mount_dev = IS_ENABLED(CONFIG_DEVTMPFS_MOUNT);
Kay Sievers2b2af542009-04-30 15:23:42 +020035
Al Viro2780f1f2011-06-27 16:25:29 -040036static DEFINE_SPINLOCK(req_lock);
37
38static struct req {
39 struct req *next;
40 struct completion done;
41 int err;
42 const char *name;
Al Viro2c9ede52011-07-23 20:24:48 -040043 umode_t mode; /* 0 => delete */
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -070044 kuid_t uid;
45 kgid_t gid;
Al Viro2780f1f2011-06-27 16:25:29 -040046 struct device *dev;
47} *requests;
Kay Sieversed413ae2009-10-28 19:51:06 +010048
Kay Sievers2b2af542009-04-30 15:23:42 +020049static int __init mount_param(char *str)
50{
Al Virofc14f2f2010-07-25 01:48:30 +040051 mount_dev = simple_strtoul(str, NULL, 0);
Kay Sievers2b2af542009-04-30 15:23:42 +020052 return 1;
53}
54__setup("devtmpfs.mount=", mount_param);
55
Al Virod4017272019-06-01 18:43:09 -040056static struct vfsmount *mnt;
57
58static struct dentry *public_dev_mount(struct file_system_type *fs_type, int flags,
59 const char *dev_name, void *data)
60{
61 struct super_block *s = mnt->mnt_sb;
62 atomic_inc(&s->s_active);
63 down_write(&s->s_umount);
64 return dget(s->s_root);
65}
66
Al Virod4017272019-06-01 18:43:09 -040067static struct file_system_type internal_fs_type = {
Kay Sievers2b2af542009-04-30 15:23:42 +020068 .name = "devtmpfs",
David Howellsf3235622019-03-25 16:38:31 +000069#ifdef CONFIG_TMPFS
70 .init_fs_context = shmem_init_fs_context,
Al Virod7167b12019-09-07 07:23:15 -040071 .parameters = shmem_fs_parameters,
David Howellsf3235622019-03-25 16:38:31 +000072#else
73 .init_fs_context = ramfs_init_fs_context,
Al Virod7167b12019-09-07 07:23:15 -040074 .parameters = ramfs_fs_parameters,
David Howellsf3235622019-03-25 16:38:31 +000075#endif
Kay Sievers2b2af542009-04-30 15:23:42 +020076 .kill_sb = kill_litter_super,
77};
78
Al Virod4017272019-06-01 18:43:09 -040079static struct file_system_type dev_fs_type = {
80 .name = "devtmpfs",
81 .mount = public_dev_mount,
82};
83
Kay Sievers2b2af542009-04-30 15:23:42 +020084#ifdef CONFIG_BLOCK
85static inline int is_blockdev(struct device *dev)
86{
87 return dev->class == &block_class;
88}
89#else
90static inline int is_blockdev(struct device *dev) { return 0; }
91#endif
92
Rasmus Villemoes72a9cc92020-01-15 19:41:53 +010093static int devtmpfs_submit_req(struct req *req, const char *tmp)
94{
95 init_completion(&req->done);
96
97 spin_lock(&req_lock);
98 req->next = requests;
99 requests = req;
100 spin_unlock(&req_lock);
101
102 wake_up_process(thread);
103 wait_for_completion(&req->done);
104
105 kfree(tmp);
106
107 return req->err;
108}
109
Al Viro2780f1f2011-06-27 16:25:29 -0400110int devtmpfs_create_node(struct device *dev)
111{
112 const char *tmp = NULL;
113 struct req req;
114
115 if (!thread)
116 return 0;
117
118 req.mode = 0;
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -0700119 req.uid = GLOBAL_ROOT_UID;
120 req.gid = GLOBAL_ROOT_GID;
Kay Sievers3c2670e2013-04-06 09:56:00 -0700121 req.name = device_get_devnode(dev, &req.mode, &req.uid, &req.gid, &tmp);
Al Viro2780f1f2011-06-27 16:25:29 -0400122 if (!req.name)
123 return -ENOMEM;
124
125 if (req.mode == 0)
126 req.mode = 0600;
127 if (is_blockdev(dev))
128 req.mode |= S_IFBLK;
129 else
130 req.mode |= S_IFCHR;
131
132 req.dev = dev;
133
Rasmus Villemoes72a9cc92020-01-15 19:41:53 +0100134 return devtmpfs_submit_req(&req, tmp);
Al Viro2780f1f2011-06-27 16:25:29 -0400135}
136
137int devtmpfs_delete_node(struct device *dev)
138{
139 const char *tmp = NULL;
140 struct req req;
141
142 if (!thread)
143 return 0;
144
Kay Sievers3c2670e2013-04-06 09:56:00 -0700145 req.name = device_get_devnode(dev, NULL, NULL, NULL, &tmp);
Al Viro2780f1f2011-06-27 16:25:29 -0400146 if (!req.name)
147 return -ENOMEM;
148
149 req.mode = 0;
150 req.dev = dev;
151
Rasmus Villemoes72a9cc92020-01-15 19:41:53 +0100152 return devtmpfs_submit_req(&req, tmp);
Al Viro2780f1f2011-06-27 16:25:29 -0400153}
154
Al Virofbd48a62011-07-24 10:47:56 -0400155static int dev_mkdir(const char *name, umode_t mode)
Kay Sievers2b2af542009-04-30 15:23:42 +0200156{
Kay Sievers2b2af542009-04-30 15:23:42 +0200157 struct dentry *dentry;
Al Viro69753a02011-06-27 16:35:45 -0400158 struct path path;
Kay Sievers2b2af542009-04-30 15:23:42 +0200159 int err;
160
Jeff Layton1ac12b42012-12-11 12:10:06 -0500161 dentry = kern_path_create(AT_FDCWD, name, &path, LOOKUP_DIRECTORY);
Al Viro69753a02011-06-27 16:35:45 -0400162 if (IS_ERR(dentry))
163 return PTR_ERR(dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200164
David Howells75c3cfa2015-03-17 22:26:12 +0000165 err = vfs_mkdir(d_inode(path.dentry), dentry, mode);
Al Viro69753a02011-06-27 16:35:45 -0400166 if (!err)
167 /* mark as kernel-created inode */
David Howells75c3cfa2015-03-17 22:26:12 +0000168 d_inode(dentry)->i_private = &thread;
Al Viro921a1652012-07-20 01:15:31 +0400169 done_path_create(&path, dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200170 return err;
171}
172
173static int create_path(const char *nodepath)
174{
Al Viro5da4e682011-06-27 16:37:12 -0400175 char *path;
176 char *s;
Al Viro9d108d22011-07-27 22:27:33 -0400177 int err = 0;
Kay Sievers2b2af542009-04-30 15:23:42 +0200178
Al Viro5da4e682011-06-27 16:37:12 -0400179 /* parent directories do not exist, create them */
180 path = kstrdup(nodepath, GFP_KERNEL);
181 if (!path)
182 return -ENOMEM;
Kay Sievers2b2af542009-04-30 15:23:42 +0200183
Al Viro5da4e682011-06-27 16:37:12 -0400184 s = path;
185 for (;;) {
186 s = strchr(s, '/');
187 if (!s)
188 break;
189 s[0] = '\0';
190 err = dev_mkdir(path, 0755);
191 if (err && err != -EEXIST)
192 break;
193 s[0] = '/';
194 s++;
Kay Sievers2b2af542009-04-30 15:23:42 +0200195 }
Al Viro5da4e682011-06-27 16:37:12 -0400196 kfree(path);
Kay Sievers2b2af542009-04-30 15:23:42 +0200197 return err;
198}
199
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -0700200static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
201 kgid_t gid, struct device *dev)
Kay Sievers2b2af542009-04-30 15:23:42 +0200202{
Kay Sievers2b2af542009-04-30 15:23:42 +0200203 struct dentry *dentry;
Al Viro69753a02011-06-27 16:35:45 -0400204 struct path path;
Kay Sievers2b2af542009-04-30 15:23:42 +0200205 int err;
206
Al Viro69753a02011-06-27 16:35:45 -0400207 dentry = kern_path_create(AT_FDCWD, nodename, &path, 0);
208 if (dentry == ERR_PTR(-ENOENT)) {
Kay Sievers2b2af542009-04-30 15:23:42 +0200209 create_path(nodename);
Al Viro69753a02011-06-27 16:35:45 -0400210 dentry = kern_path_create(AT_FDCWD, nodename, &path, 0);
Kay Sievers2b2af542009-04-30 15:23:42 +0200211 }
Al Viro69753a02011-06-27 16:35:45 -0400212 if (IS_ERR(dentry))
213 return PTR_ERR(dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200214
David Howells75c3cfa2015-03-17 22:26:12 +0000215 err = vfs_mknod(d_inode(path.dentry), dentry, mode, dev->devt);
Al Viro69753a02011-06-27 16:35:45 -0400216 if (!err) {
217 struct iattr newattrs;
Kay Sievers00926992009-10-28 19:50:57 +0100218
Al Viro69753a02011-06-27 16:35:45 -0400219 newattrs.ia_mode = mode;
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -0700220 newattrs.ia_uid = uid;
221 newattrs.ia_gid = gid;
Kay Sievers3c2670e2013-04-06 09:56:00 -0700222 newattrs.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID;
Al Viro59551022016-01-22 15:40:57 -0500223 inode_lock(d_inode(dentry));
J. Bruce Fields27ac0ff2011-09-20 17:19:26 -0400224 notify_change(dentry, &newattrs, NULL);
Al Viro59551022016-01-22 15:40:57 -0500225 inode_unlock(d_inode(dentry));
Kay Sievers00926992009-10-28 19:50:57 +0100226
Al Viro69753a02011-06-27 16:35:45 -0400227 /* mark as kernel-created inode */
David Howells75c3cfa2015-03-17 22:26:12 +0000228 d_inode(dentry)->i_private = &thread;
Kay Sievers2b2af542009-04-30 15:23:42 +0200229 }
Al Viro921a1652012-07-20 01:15:31 +0400230 done_path_create(&path, dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200231 return err;
232}
233
234static int dev_rmdir(const char *name)
235{
Al Viro79714f72012-06-15 03:01:42 +0400236 struct path parent;
Kay Sievers2b2af542009-04-30 15:23:42 +0200237 struct dentry *dentry;
238 int err;
239
Al Viro79714f72012-06-15 03:01:42 +0400240 dentry = kern_path_locked(name, &parent);
241 if (IS_ERR(dentry))
242 return PTR_ERR(dentry);
David Howells75c3cfa2015-03-17 22:26:12 +0000243 if (d_really_is_positive(dentry)) {
244 if (d_inode(dentry)->i_private == &thread)
245 err = vfs_rmdir(d_inode(parent.dentry), dentry);
Al Viro79714f72012-06-15 03:01:42 +0400246 else
247 err = -EPERM;
Kay Sievers2b2af542009-04-30 15:23:42 +0200248 } else {
Al Viro79714f72012-06-15 03:01:42 +0400249 err = -ENOENT;
Kay Sievers2b2af542009-04-30 15:23:42 +0200250 }
Al Viro79714f72012-06-15 03:01:42 +0400251 dput(dentry);
Al Viro59551022016-01-22 15:40:57 -0500252 inode_unlock(d_inode(parent.dentry));
Al Viro79714f72012-06-15 03:01:42 +0400253 path_put(&parent);
Kay Sievers2b2af542009-04-30 15:23:42 +0200254 return err;
255}
256
257static int delete_path(const char *nodepath)
258{
Rasmus Villemoesbe6b1df2018-08-22 13:00:07 +0200259 char *path;
Kay Sievers2b2af542009-04-30 15:23:42 +0200260 int err = 0;
261
262 path = kstrdup(nodepath, GFP_KERNEL);
263 if (!path)
264 return -ENOMEM;
265
Kay Sieversed413ae2009-10-28 19:51:06 +0100266 for (;;) {
Kay Sievers2b2af542009-04-30 15:23:42 +0200267 char *base;
268
269 base = strrchr(path, '/');
270 if (!base)
271 break;
272 base[0] = '\0';
273 err = dev_rmdir(path);
274 if (err)
275 break;
276 }
277
278 kfree(path);
279 return err;
280}
281
282static int dev_mynode(struct device *dev, struct inode *inode, struct kstat *stat)
283{
284 /* did we create it */
Al Viro2780f1f2011-06-27 16:25:29 -0400285 if (inode->i_private != &thread)
Kay Sievers2b2af542009-04-30 15:23:42 +0200286 return 0;
287
288 /* does the dev_t match */
289 if (is_blockdev(dev)) {
290 if (!S_ISBLK(stat->mode))
291 return 0;
292 } else {
293 if (!S_ISCHR(stat->mode))
294 return 0;
295 }
296 if (stat->rdev != dev->devt)
297 return 0;
298
299 /* ours */
300 return 1;
301}
302
Al Viro2780f1f2011-06-27 16:25:29 -0400303static int handle_remove(const char *nodename, struct device *dev)
Kay Sievers2b2af542009-04-30 15:23:42 +0200304{
Al Viro79714f72012-06-15 03:01:42 +0400305 struct path parent;
Kay Sievers2b2af542009-04-30 15:23:42 +0200306 struct dentry *dentry;
Axel Linfbde7c62013-11-16 16:15:23 +0800307 int deleted = 0;
Kay Sievers2b2af542009-04-30 15:23:42 +0200308 int err;
309
Al Viro79714f72012-06-15 03:01:42 +0400310 dentry = kern_path_locked(nodename, &parent);
311 if (IS_ERR(dentry))
312 return PTR_ERR(dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200313
David Howells75c3cfa2015-03-17 22:26:12 +0000314 if (d_really_is_positive(dentry)) {
Al Viro79714f72012-06-15 03:01:42 +0400315 struct kstat stat;
Al Viro3dadecc2013-01-24 02:18:08 -0500316 struct path p = {.mnt = parent.mnt, .dentry = dentry};
David Howellsa528d352017-01-31 16:46:22 +0000317 err = vfs_getattr(&p, &stat, STATX_TYPE | STATX_MODE,
318 AT_STATX_SYNC_AS_STAT);
David Howells75c3cfa2015-03-17 22:26:12 +0000319 if (!err && dev_mynode(dev, d_inode(dentry), &stat)) {
Al Viro79714f72012-06-15 03:01:42 +0400320 struct iattr newattrs;
321 /*
322 * before unlinking this node, reset permissions
323 * of possible references like hardlinks
324 */
Eric W. Biederman91fa2cc2012-04-25 04:25:35 -0700325 newattrs.ia_uid = GLOBAL_ROOT_UID;
326 newattrs.ia_gid = GLOBAL_ROOT_GID;
Al Viro79714f72012-06-15 03:01:42 +0400327 newattrs.ia_mode = stat.mode & ~0777;
328 newattrs.ia_valid =
329 ATTR_UID|ATTR_GID|ATTR_MODE;
Al Viro59551022016-01-22 15:40:57 -0500330 inode_lock(d_inode(dentry));
J. Bruce Fields27ac0ff2011-09-20 17:19:26 -0400331 notify_change(dentry, &newattrs, NULL);
Al Viro59551022016-01-22 15:40:57 -0500332 inode_unlock(d_inode(dentry));
David Howells75c3cfa2015-03-17 22:26:12 +0000333 err = vfs_unlink(d_inode(parent.dentry), dentry, NULL);
Al Viro79714f72012-06-15 03:01:42 +0400334 if (!err || err == -ENOENT)
335 deleted = 1;
Kay Sievers2b2af542009-04-30 15:23:42 +0200336 }
Kay Sievers2b2af542009-04-30 15:23:42 +0200337 } else {
Al Viro79714f72012-06-15 03:01:42 +0400338 err = -ENOENT;
Kay Sievers2b2af542009-04-30 15:23:42 +0200339 }
Al Viro79714f72012-06-15 03:01:42 +0400340 dput(dentry);
Al Viro59551022016-01-22 15:40:57 -0500341 inode_unlock(d_inode(parent.dentry));
Kay Sievers2b2af542009-04-30 15:23:42 +0200342
Al Viro79714f72012-06-15 03:01:42 +0400343 path_put(&parent);
Kay Sievers2b2af542009-04-30 15:23:42 +0200344 if (deleted && strchr(nodename, '/'))
345 delete_path(nodename);
Kay Sievers2b2af542009-04-30 15:23:42 +0200346 return err;
347}
348
349/*
350 * If configured, or requested by the commandline, devtmpfs will be
351 * auto-mounted after the kernel mounted the root filesystem.
352 */
Rasmus Villemoesfad1db82020-01-15 19:41:52 +0100353int __init devtmpfs_mount(void)
Kay Sievers2b2af542009-04-30 15:23:42 +0200354{
Kay Sievers2b2af542009-04-30 15:23:42 +0200355 int err;
356
Al Virofc14f2f2010-07-25 01:48:30 +0400357 if (!mount_dev)
Kay Sievers2b2af542009-04-30 15:23:42 +0200358 return 0;
359
Al Viro2780f1f2011-06-27 16:25:29 -0400360 if (!thread)
Kay Sievers2b2af542009-04-30 15:23:42 +0200361 return 0;
362
Christoph Hellwigc60166f2020-07-21 11:12:08 +0200363 err = init_mount("devtmpfs", "dev", "devtmpfs", MS_SILENT, NULL);
Kay Sievers2b2af542009-04-30 15:23:42 +0200364 if (err)
365 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
366 else
367 printk(KERN_INFO "devtmpfs: mounted\n");
Kay Sievers2b2af542009-04-30 15:23:42 +0200368 return err;
369}
370
Arnaud Lacombef9e0b152011-07-21 13:16:19 -0400371static DECLARE_COMPLETION(setup_done);
Al Viro2780f1f2011-06-27 16:25:29 -0400372
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -0700373static int handle(const char *name, umode_t mode, kuid_t uid, kgid_t gid,
Kay Sievers3c2670e2013-04-06 09:56:00 -0700374 struct device *dev)
Al Viro2780f1f2011-06-27 16:25:29 -0400375{
376 if (mode)
Kay Sievers3c2670e2013-04-06 09:56:00 -0700377 return handle_create(name, mode, uid, gid, dev);
Al Viro2780f1f2011-06-27 16:25:29 -0400378 else
379 return handle_remove(name, dev);
380}
381
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200382static void __noreturn devtmpfs_work_loop(void)
Al Viro2780f1f2011-06-27 16:25:29 -0400383{
Al Viro2780f1f2011-06-27 16:25:29 -0400384 while (1) {
385 spin_lock(&req_lock);
386 while (requests) {
387 struct req *req = requests;
388 requests = NULL;
389 spin_unlock(&req_lock);
390 while (req) {
Al Viroe13889b2011-07-25 14:15:50 -0400391 struct req *next = req->next;
Kay Sievers3c2670e2013-04-06 09:56:00 -0700392 req->err = handle(req->name, req->mode,
393 req->uid, req->gid, req->dev);
Al Viro2780f1f2011-06-27 16:25:29 -0400394 complete(&req->done);
Al Viroe13889b2011-07-25 14:15:50 -0400395 req = next;
Al Viro2780f1f2011-06-27 16:25:29 -0400396 }
397 spin_lock(&req_lock);
398 }
Kautuk Consul65e67572011-11-15 14:52:34 -0800399 __set_current_state(TASK_INTERRUPTIBLE);
Al Viro2780f1f2011-06-27 16:25:29 -0400400 spin_unlock(&req_lock);
401 schedule();
Al Viro2780f1f2011-06-27 16:25:29 -0400402 }
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200403}
404
405static int __init devtmpfs_setup(void *p)
406{
407 int err;
408
409 err = ksys_unshare(CLONE_NEWNS);
410 if (err)
411 goto out;
Christoph Hellwigc60166f2020-07-21 11:12:08 +0200412 err = init_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL);
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200413 if (err)
414 goto out;
Christoph Hellwigdb63f1e2020-07-22 11:25:21 +0200415 init_chdir("/.."); /* will traverse into overmounted root */
Christoph Hellwig4b7ca502020-07-22 11:26:13 +0200416 init_chroot(".");
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200417out:
418 *(int *)p = err;
419 complete(&setup_done);
420 return err;
421}
422
423/*
424 * The __ref is because devtmpfs_setup needs to be __init for the routines it
425 * calls. That call is done while devtmpfs_init, which is marked __init,
426 * synchronously waits for it to complete.
427 */
428static int __ref devtmpfsd(void *p)
429{
430 int err = devtmpfs_setup(p);
431
432 if (err)
433 return err;
434 devtmpfs_work_loop();
Al Viro2780f1f2011-06-27 16:25:29 -0400435 return 0;
Al Viro2780f1f2011-06-27 16:25:29 -0400436}
437
Kay Sievers2b2af542009-04-30 15:23:42 +0200438/*
439 * Create devtmpfs instance, driver-core devices will add their device
440 * nodes here.
441 */
442int __init devtmpfs_init(void)
443{
Al Virod4017272019-06-01 18:43:09 -0400444 char opts[] = "mode=0755";
445 int err;
446
447 mnt = vfs_kern_mount(&internal_fs_type, 0, "devtmpfs", opts);
448 if (IS_ERR(mnt)) {
449 printk(KERN_ERR "devtmpfs: unable to create devtmpfs %ld\n",
450 PTR_ERR(mnt));
451 return PTR_ERR(mnt);
452 }
453 err = register_filesystem(&dev_fs_type);
Kay Sievers2b2af542009-04-30 15:23:42 +0200454 if (err) {
455 printk(KERN_ERR "devtmpfs: unable to register devtmpfs "
456 "type %i\n", err);
457 return err;
458 }
459
Al Viro2780f1f2011-06-27 16:25:29 -0400460 thread = kthread_run(devtmpfsd, &err, "kdevtmpfs");
461 if (!IS_ERR(thread)) {
462 wait_for_completion(&setup_done);
463 } else {
464 err = PTR_ERR(thread);
465 thread = NULL;
466 }
467
468 if (err) {
Kay Sievers2b2af542009-04-30 15:23:42 +0200469 printk(KERN_ERR "devtmpfs: unable to create devtmpfs %i\n", err);
470 unregister_filesystem(&dev_fs_type);
471 return err;
472 }
Kay Sievers2b2af542009-04-30 15:23:42 +0200473
474 printk(KERN_INFO "devtmpfs: initialized\n");
475 return 0;
476}