Skip to content

Commit bcbacc4

Browse files
author
Christoph Hellwig
committed
devtmpfs: refactor devtmpfsd()
Split the main worker loop into a separate function. This allows devtmpfsd_setup to be marked __init, which will allows us to call __init routines for the setup work. devtmpfѕ itself needs a __ref marker for that to work, and a comment explaining why it works. Signed-off-by: Christoph Hellwig <[email protected]>
1 parent e24ab0e commit bcbacc4

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

drivers/base/devtmpfs.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,30 @@ static int handle(const char *name, umode_t mode, kuid_t uid, kgid_t gid,
378378
return handle_remove(name, dev);
379379
}
380380

381-
static int devtmpfs_setup(void *p)
381+
static void __noreturn devtmpfs_work_loop(void)
382+
{
383+
while (1) {
384+
spin_lock(&req_lock);
385+
while (requests) {
386+
struct req *req = requests;
387+
requests = NULL;
388+
spin_unlock(&req_lock);
389+
while (req) {
390+
struct req *next = req->next;
391+
req->err = handle(req->name, req->mode,
392+
req->uid, req->gid, req->dev);
393+
complete(&req->done);
394+
req = next;
395+
}
396+
spin_lock(&req_lock);
397+
}
398+
__set_current_state(TASK_INTERRUPTIBLE);
399+
spin_unlock(&req_lock);
400+
schedule();
401+
}
402+
}
403+
404+
static int __init devtmpfs_setup(void *p)
382405
{
383406
int err;
384407

@@ -396,31 +419,18 @@ static int devtmpfs_setup(void *p)
396419
return err;
397420
}
398421

399-
static int devtmpfsd(void *p)
422+
/*
423+
* The __ref is because devtmpfs_setup needs to be __init for the routines it
424+
* calls. That call is done while devtmpfs_init, which is marked __init,
425+
* synchronously waits for it to complete.
426+
*/
427+
static int __ref devtmpfsd(void *p)
400428
{
401429
int err = devtmpfs_setup(p);
402430

403431
if (err)
404432
return err;
405-
while (1) {
406-
spin_lock(&req_lock);
407-
while (requests) {
408-
struct req *req = requests;
409-
requests = NULL;
410-
spin_unlock(&req_lock);
411-
while (req) {
412-
struct req *next = req->next;
413-
req->err = handle(req->name, req->mode,
414-
req->uid, req->gid, req->dev);
415-
complete(&req->done);
416-
req = next;
417-
}
418-
spin_lock(&req_lock);
419-
}
420-
__set_current_state(TASK_INTERRUPTIBLE);
421-
spin_unlock(&req_lock);
422-
schedule();
423-
}
433+
devtmpfs_work_loop();
424434
return 0;
425435
}
426436

0 commit comments

Comments
 (0)