{get,put}_binfmt()
Subsystems (4)
PATCH 1/1 {get,put}_binfmt()
Hi,
While browsing through kernel/{fork,exit}.c, I noticed that a pair of {get,put}_binfmt() could make some code slightly more readable (imho). After a few seconds of grepping, I found the function put_binfmt() in fs/exec.c, and I made a little "sister-function" for it: get_binfmt().
This patch adds get_binfmt(). It gives {put,get}_binfmt() a new home:include/linux/binfmts.h (so kernel/{fork,exit}.c can use them.) Minor #include changes was needed in fork.c, exit.c and exec.c to make this work.
If you think this is a bad idea, just ignore this patch :)
Regards,
Erlend Aasland
fs/exec.c +3 -11
@@ -35,9 +35,9 @@#include <linux/highmem.h> #include <linux/spinlock.h> #include <linux/personality.h> -#include <linux/binfmts.h> #define __NO_VERSION__#include <linux/module.h> +#include <linux/binfmts.h> #include <linux/namei.h> #include <asm/uaccess.h>
@@ -92,12 +92,6 @@return -EINVAL ; } -static inline void put_binfmt (struct linux_binfmt * fmt) -{ -if (fmt->module) -__MOD_DEC_USE_COUNT (fmt->module); -} -/* * Note that a shared library must be both readable and executable due to * security reasons.
@@ -947,11 +941,9 @@void set_binfmt (struct linux_binfmt *new) {struct linux_binfmt *old = current->binfmt; -if (new && new->module) -__MOD_INC_USE_COUNT (new->module); +get_binfmt (new); current->binfmt = new; -if (old && old->module) -__MOD_DEC_USE_COUNT (old->module); +put_binfmt (old); }int do_coredump (long signr,struct pt_regs * regs)
include/linux/binfmts.h +12 -0
@@ -3,6 +3,7 @@#include <linux/ptrace.h> #include <linux/capability.h> +#include <linux/module.h> /* * MAX_ARG_PAGES defines the number of pages allocated for arguments
@@ -60,6 +61,17 @@extern int do_coredump (long signr,struct pt_regs * regs);extern void set_binfmt (struct linux_binfmt *new); +static inline void put_binfmt (struct linux_binfmt * fmt) +{ +if (fmt && fmt->module) +__MOD_DEC_USE_COUNT (fmt->module); +} + +static inline void get_binfmt (struct linux_binfmt * fmt) +{ +if (fmt && fmt->module) +__MOD_INC_USE_COUNT (fmt->module); +}#if 0 /* this went away now */
kernel/exit.c +1 -3
@@ -9,7 +9,6 @@#include <linux/slab.h> #include <linux/interrupt.h> #include <linux/smp_lock.h> -#include <linux/module.h> #include <linux/completion.h> #include <linux/personality.h> #include <linux/tty.h>
@@ -551,8 +550,7 @@disassociate_ctty (1 );put_exec_domain (tsk->thread_info->exec_domain); -if (tsk->binfmt && tsk->binfmt->module) -__MOD_DEC_USE_COUNT (tsk->binfmt->module); +put_binfmt (tsk->binfmt); tsk->exit_code = code;exit_notify ();
kernel/fork.c +2 -6
@@ -16,7 +16,6 @@#include <linux/init.h> #include <linux/unistd.h> #include <linux/smp_lock.h> -#include <linux/module.h> #include <linux/vmalloc.h> #include <linux/completion.h> #include <linux/namespace.h>
@@ -645,9 +644,7 @@ goto bad_fork_cleanup_count;get_exec_domain (p->thread_info->exec_domain); - -if (p->binfmt && p->binfmt->module) -__MOD_INC_USE_COUNT (p->binfmt->module); +get_binfmt (p->binfmt);#ifdef CONFIG_PREEMPT /*
@@ -818,8 +815,7 @@exit_semundo (p); bad_fork_cleanup:put_exec_domain (p->thread_info->exec_domain); -if (p->binfmt && p->binfmt->module) -__MOD_DEC_USE_COUNT (p->binfmt->module); +put_binfmt (p->binfmt); bad_fork_cleanup_count:atomic_dec (&p->user->processes);free_uid (p->user);