Commit afe0458b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

[PATCH] avoid deprecated module functions in core code

A second start at removing them from kernel/*.c and fs/*.c.

Note that module_put is fine for a NULL argument.
parent 2cdea215
...@@ -29,8 +29,7 @@ static inline int crypto_alg_get(struct crypto_alg *alg) ...@@ -29,8 +29,7 @@ static inline int crypto_alg_get(struct crypto_alg *alg)
static inline void crypto_alg_put(struct crypto_alg *alg) static inline void crypto_alg_put(struct crypto_alg *alg)
{ {
if (alg->cra_module) module_put(alg->cra_module);
__MOD_DEC_USE_COUNT(alg->cra_module);
} }
struct crypto_alg *crypto_alg_lookup(const char *name) struct crypto_alg *crypto_alg_lookup(const char *name)
......
...@@ -168,15 +168,13 @@ get_gendisk(dev_t dev, int *part) ...@@ -168,15 +168,13 @@ get_gendisk(dev_t dev, int *part)
best = p->range; best = p->range;
*part = dev - p->dev; *part = dev - p->dev;
if (p->lock && p->lock(dev, data) < 0) { if (p->lock && p->lock(dev, data) < 0) {
if (owner) module_put(owner);
__MOD_DEC_USE_COUNT(owner);
continue; continue;
} }
read_unlock(&gendisk_lock); read_unlock(&gendisk_lock);
disk = probe(dev, part, data); disk = probe(dev, part, data);
/* Currently ->owner protects _only_ ->probe() itself. */ /* Currently ->owner protects _only_ ->probe() itself. */
if (owner) module_put(owner);
__MOD_DEC_USE_COUNT(owner);
if (disk) if (disk)
return disk; return disk;
goto retry; goto retry;
......
...@@ -623,8 +623,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file * ...@@ -623,8 +623,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file *
} }
} else { } else {
put_disk(disk); put_disk(disk);
if (owner) module_put(owner);
__MOD_DEC_USE_COUNT(owner);
if (bdev->bd_contains == bdev) { if (bdev->bd_contains == bdev) {
if (bdev->bd_disk->fops->open) { if (bdev->bd_disk->fops->open) {
ret = bdev->bd_disk->fops->open(inode, file); ret = bdev->bd_disk->fops->open(inode, file);
...@@ -651,8 +650,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file * ...@@ -651,8 +650,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file *
blkdev_put(bdev->bd_contains, BDEV_RAW); blkdev_put(bdev->bd_contains, BDEV_RAW);
bdev->bd_contains = NULL; bdev->bd_contains = NULL;
put_disk(disk); put_disk(disk);
if (owner) module_put(owner);
__MOD_DEC_USE_COUNT(owner);
out: out:
up(&bdev->bd_sem); up(&bdev->bd_sem);
unlock_kernel(); unlock_kernel();
...@@ -723,9 +721,10 @@ int blkdev_put(struct block_device *bdev, int kind) ...@@ -723,9 +721,10 @@ int blkdev_put(struct block_device *bdev, int kind)
} }
if (!bdev->bd_openers) { if (!bdev->bd_openers) {
struct module *owner = disk->fops->owner; struct module *owner = disk->fops->owner;
put_disk(disk); put_disk(disk);
if (owner) module_put(owner);
__MOD_DEC_USE_COUNT(owner);
bdev->bd_disk = NULL; bdev->bd_disk = NULL;
bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
if (bdev != bdev->bd_contains) { if (bdev != bdev->bd_contains) {
......
...@@ -111,8 +111,7 @@ static struct quota_format_type *find_quota_format(int id) ...@@ -111,8 +111,7 @@ static struct quota_format_type *find_quota_format(int id)
static void put_quota_format(struct quota_format_type *fmt) static void put_quota_format(struct quota_format_type *fmt)
{ {
if (fmt->qf_owner) module_put(fmt->qf_owner);
__MOD_DEC_USE_COUNT(fmt->qf_owner);
} }
/* /*
......
...@@ -102,8 +102,7 @@ int unregister_binfmt(struct linux_binfmt * fmt) ...@@ -102,8 +102,7 @@ int unregister_binfmt(struct linux_binfmt * fmt)
static inline void put_binfmt(struct linux_binfmt * fmt) static inline void put_binfmt(struct linux_binfmt * fmt)
{ {
if (fmt->module) module_put(fmt->module);
__MOD_DEC_USE_COUNT(fmt->module);
} }
/* /*
...@@ -1108,14 +1107,18 @@ int do_execve(char * filename, char ** argv, char ** envp, struct pt_regs * regs ...@@ -1108,14 +1107,18 @@ int do_execve(char * filename, char ** argv, char ** envp, struct pt_regs * regs
return retval; return retval;
} }
void set_binfmt(struct linux_binfmt *new) int set_binfmt(struct linux_binfmt *new)
{ {
struct linux_binfmt *old = current->binfmt; struct linux_binfmt *old = current->binfmt;
if (new && new->module)
__MOD_INC_USE_COUNT(new->module); if (new) {
if (!try_module_get(new->module))
return -1;
}
current->binfmt = new; current->binfmt = new;
if (old && old->module) if (old)
__MOD_DEC_USE_COUNT(old->module); module_put(old->module);
return 0;
} }
#define CORENAME_MAX_SIZE 64 #define CORENAME_MAX_SIZE 64
......
...@@ -245,8 +245,7 @@ struct nls_table *load_nls(char *charset) ...@@ -245,8 +245,7 @@ struct nls_table *load_nls(char *charset)
void unload_nls(struct nls_table *nls) void unload_nls(struct nls_table *nls)
{ {
if (nls->owner) module_put(nls->owner);
__MOD_DEC_USE_COUNT(nls->owner);
} }
wchar_t charset2uni[256] = { wchar_t charset2uni[256] = {
......
...@@ -565,8 +565,7 @@ char *partition_name(dev_t dev) ...@@ -565,8 +565,7 @@ char *partition_name(dev_t dev)
dname->name = NULL; dname->name = NULL;
if (hd) { if (hd) {
dname->name = disk_name(hd, part, dname->namebuf); dname->name = disk_name(hd, part, dname->namebuf);
if (hd->fops->owner) module_put(hd->fops->owner);
__MOD_DEC_USE_COUNT(hd->fops->owner);
put_disk(hd); put_disk(hd);
} }
if (!dname->name) { if (!dname->name) {
......
...@@ -58,13 +58,7 @@ extern int copy_strings(int argc,char ** argv,struct linux_binprm *bprm); ...@@ -58,13 +58,7 @@ extern int copy_strings(int argc,char ** argv,struct linux_binprm *bprm);
extern int copy_strings_kernel(int argc,char ** argv,struct linux_binprm *bprm); extern int copy_strings_kernel(int argc,char ** argv,struct linux_binprm *bprm);
extern void compute_creds(struct linux_binprm *binprm); extern void compute_creds(struct linux_binprm *binprm);
extern int do_coredump(long signr, int exit_code, struct pt_regs * regs); extern int do_coredump(long signr, int exit_code, struct pt_regs * regs);
extern void set_binfmt(struct linux_binfmt *new); extern int set_binfmt(struct linux_binfmt *new);
#if 0
/* this went away now */
#define change_ldt(a,b) setup_arg_pages(a,b)
#endif
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* _LINUX_BINFMTS_H */ #endif /* _LINUX_BINFMTS_H */
...@@ -983,13 +983,13 @@ struct super_block *get_sb_pseudo(struct file_system_type *, char *, ...@@ -983,13 +983,13 @@ struct super_block *get_sb_pseudo(struct file_system_type *, char *,
/* Alas, no aliases. Too much hassle with bringing module.h everywhere */ /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
#define fops_get(fops) \ #define fops_get(fops) \
(((fops) && (fops)->owner) \ (((fops) && (fops)->owner) \
? ( try_inc_mod_count((fops)->owner) ? (fops) : NULL ) \ ? (try_inc_mod_count((fops)->owner) ? (fops) : NULL) \
: (fops)) : (fops))
#define fops_put(fops) \ #define fops_put(fops) \
do { \ do { \
if ((fops) && (fops)->owner) \ if ((fops) && (fops)->owner) \
__MOD_DEC_USE_COUNT((fops)->owner); \ module_put((fops)->owner); \
} while(0) } while(0)
extern int register_filesystem(struct file_system_type *); extern int register_filesystem(struct file_system_type *);
......
...@@ -107,22 +107,4 @@ struct exec_domain { ...@@ -107,22 +107,4 @@ struct exec_domain {
#define set_personality(pers) \ #define set_personality(pers) \
((current->personality == pers) ? 0 : __set_personality(pers)) ((current->personality == pers) ? 0 : __set_personality(pers))
/*
* Load an execution domain.
*/
#define get_exec_domain(ep) \
do { \
if (ep != NULL && ep->module != NULL) \
__MOD_INC_USE_COUNT(ep->module); \
} while (0)
/*
* Unload an execution domain.
*/
#define put_exec_domain(ep) \
do { \
if (ep != NULL && ep->module != NULL) \
__MOD_DEC_USE_COUNT(ep->module); \
} while (0)
#endif /* _LINUX_PERSONALITY_H */ #endif /* _LINUX_PERSONALITY_H */
...@@ -172,7 +172,7 @@ __set_personality(u_long personality) ...@@ -172,7 +172,7 @@ __set_personality(u_long personality)
fsp = copy_fs_struct(current->fs); fsp = copy_fs_struct(current->fs);
if (fsp == NULL) { if (fsp == NULL) {
put_exec_domain(ep); module_put(ep->module);
return -ENOMEM;; return -ENOMEM;;
} }
...@@ -194,10 +194,7 @@ __set_personality(u_long personality) ...@@ -194,10 +194,7 @@ __set_personality(u_long personality)
current_thread_info()->exec_domain = ep; current_thread_info()->exec_domain = ep;
set_fs_altroot(); set_fs_altroot();
put_exec_domain(oep); module_put(oep->module);
printk(KERN_DEBUG "[%s:%d]: set personality to %lx\n",
current->comm, current->pid, personality);
return 0; return 0;
} }
......
...@@ -664,9 +664,9 @@ NORET_TYPE void do_exit(long code) ...@@ -664,9 +664,9 @@ NORET_TYPE void do_exit(long code)
if (current->leader) if (current->leader)
disassociate_ctty(1); disassociate_ctty(1);
put_exec_domain(tsk->thread_info->exec_domain); module_put(tsk->thread_info->exec_domain->module);
if (tsk->binfmt && tsk->binfmt->module) if (tsk->binfmt)
__MOD_DEC_USE_COUNT(tsk->binfmt->module); module_put(tsk->binfmt->module);
tsk->exit_code = code; tsk->exit_code = code;
exit_notify(); exit_notify();
......
...@@ -743,10 +743,11 @@ static struct task_struct *copy_process(unsigned long clone_flags, ...@@ -743,10 +743,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
if (nr_threads >= max_threads) if (nr_threads >= max_threads)
goto bad_fork_cleanup_count; goto bad_fork_cleanup_count;
get_exec_domain(p->thread_info->exec_domain); if (!try_module_get(p->thread_info->exec_domain->module))
goto bad_fork_cleanup_count;
if (p->binfmt && p->binfmt->module) if (p->binfmt && !try_module_get(p->binfmt->module))
__MOD_INC_USE_COUNT(p->binfmt->module); goto bad_fork_cleanup_put_domain;
#ifdef CONFIG_PREEMPT #ifdef CONFIG_PREEMPT
/* /*
...@@ -958,9 +959,10 @@ static struct task_struct *copy_process(unsigned long clone_flags, ...@@ -958,9 +959,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,
bad_fork_cleanup: bad_fork_cleanup:
if (p->pid > 0) if (p->pid > 0)
free_pidmap(p->pid); free_pidmap(p->pid);
put_exec_domain(p->thread_info->exec_domain); if (p->binfmt)
if (p->binfmt && p->binfmt->module) module_put(p->binfmt->module);
__MOD_DEC_USE_COUNT(p->binfmt->module); bad_fork_cleanup_put_domain:
module_put(p->thread_info->exec_domain->module);
bad_fork_cleanup_count: bad_fork_cleanup_count:
atomic_dec(&p->user->processes); atomic_dec(&p->user->processes);
free_uid(p->user); free_uid(p->user);
......
...@@ -166,7 +166,7 @@ void inter_module_put(const char *im_name) ...@@ -166,7 +166,7 @@ void inter_module_put(const char *im_name)
ime = list_entry(tmp, struct inter_module_entry, list); ime = list_entry(tmp, struct inter_module_entry, list);
if (strcmp(ime->im_name, im_name) == 0) { if (strcmp(ime->im_name, im_name) == 0) {
if (ime->owner) if (ime->owner)
__MOD_DEC_USE_COUNT(ime->owner); module_put(ime->owner);
spin_unlock(&ime_lock); spin_unlock(&ime_lock);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment