Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kmod: move call_usermodehelper_fns() to .c file and unexport all it's helpers

If we move call_usermodehelper_fns() to kmod.c file and EXPORT_SYMBOL it
we can avoid exporting all it's helper functions:
call_usermodehelper_setup
call_usermodehelper_setfns
call_usermodehelper_exec
And make all of them static to kmod.c

Since the optimizer will see all these as a single call site it will
inline them inside call_usermodehelper_fns(). So we loose the call to
_fns but gain 3 calls to the helpers. (Not that it matters)

Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Boaz Harrosh and committed by
Linus Torvalds
785042f2 81ab6e7b

+24 -31
+2 -28
include/linux/kmod.h
··· 66 66 void *data; 67 67 }; 68 68 69 - /* Allocate a subprocess_info structure */ 70 - struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, 71 - char **envp, gfp_t gfp_mask); 72 - 73 - /* Set various pieces of state into the subprocess_info structure */ 74 - void call_usermodehelper_setfns(struct subprocess_info *info, 75 - int (*init)(struct subprocess_info *info, struct cred *new), 76 - void (*cleanup)(struct subprocess_info *info), 77 - void *data); 78 - 79 - /* Actually execute the sub-process */ 80 - int call_usermodehelper_exec(struct subprocess_info *info, int wait); 81 - 82 - static inline int 69 + extern int 83 70 call_usermodehelper_fns(char *path, char **argv, char **envp, int wait, 84 71 int (*init)(struct subprocess_info *info, struct cred *new), 85 - void (*cleanup)(struct subprocess_info *), void *data) 86 - { 87 - struct subprocess_info *info; 88 - gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; 89 - 90 - info = call_usermodehelper_setup(path, argv, envp, gfp_mask); 91 - 92 - if (info == NULL) 93 - return -ENOMEM; 94 - 95 - call_usermodehelper_setfns(info, init, cleanup, data); 96 - 97 - return call_usermodehelper_exec(info, wait); 98 - } 72 + void (*cleanup)(struct subprocess_info *), void *data); 99 73 100 74 static inline int 101 75 call_usermodehelper(char *path, char **argv, char **envp, int wait)
+22 -3
kernel/kmod.c
··· 478 478 * structure. This should be passed to call_usermodehelper_exec to 479 479 * exec the process and free the structure. 480 480 */ 481 + static 481 482 struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, 482 483 char **envp, gfp_t gfp_mask) 483 484 { ··· 494 493 out: 495 494 return sub_info; 496 495 } 497 - EXPORT_SYMBOL(call_usermodehelper_setup); 498 496 499 497 /** 500 498 * call_usermodehelper_setfns - set a cleanup/init function ··· 511 511 * Function must be runnable in either a process context or the 512 512 * context in which call_usermodehelper_exec is called. 513 513 */ 514 + static 514 515 void call_usermodehelper_setfns(struct subprocess_info *info, 515 516 int (*init)(struct subprocess_info *info, struct cred *new), 516 517 void (*cleanup)(struct subprocess_info *info), ··· 521 520 info->init = init; 522 521 info->data = data; 523 522 } 524 - EXPORT_SYMBOL(call_usermodehelper_setfns); 525 523 526 524 /** 527 525 * call_usermodehelper_exec - start a usermode application ··· 534 534 * asynchronously if wait is not set, and runs as a child of keventd. 535 535 * (ie. it runs with full root capabilities). 536 536 */ 537 + static 537 538 int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait) 538 539 { 539 540 DECLARE_COMPLETION_ONSTACK(done); ··· 576 575 helper_unlock(); 577 576 return retval; 578 577 } 579 - EXPORT_SYMBOL(call_usermodehelper_exec); 578 + 579 + int call_usermodehelper_fns( 580 + char *path, char **argv, char **envp, int wait, 581 + int (*init)(struct subprocess_info *info, struct cred *new), 582 + void (*cleanup)(struct subprocess_info *), void *data) 583 + { 584 + struct subprocess_info *info; 585 + gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; 586 + 587 + info = call_usermodehelper_setup(path, argv, envp, gfp_mask); 588 + 589 + if (info == NULL) 590 + return -ENOMEM; 591 + 592 + call_usermodehelper_setfns(info, init, cleanup, data); 593 + 594 + return call_usermodehelper_exec(info, wait); 595 + } 596 + EXPORT_SYMBOL(call_usermodehelper_fns); 580 597 581 598 static int proc_cap_handler(struct ctl_table *table, int write, 582 599 void __user *buffer, size_t *lenp, loff_t *ppos)