Commit e7a6e291 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

proc: faster open/close of files without ->release hook

The whole point of code in fs/proc/inode.c is to make sure ->release
hook is called either at close() or at rmmod time.

All if it is unnecessary if there is no ->release hook.

Save allocation+list manipulations under spinlock in that case.

Link: http://lkml.kernel.org/r/20180214063033.GA15579@avx2Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e74a0eff
...@@ -342,21 +342,24 @@ static int proc_reg_open(struct inode *inode, struct file *file) ...@@ -342,21 +342,24 @@ static int proc_reg_open(struct inode *inode, struct file *file)
* *
* Save every "struct file" with custom ->release hook. * Save every "struct file" with custom ->release hook.
*/ */
pdeo = kmalloc(sizeof(struct pde_opener), GFP_KERNEL); if (!use_pde(pde))
if (!pdeo)
return -ENOMEM;
if (!use_pde(pde)) {
kfree(pdeo);
return -ENOENT; return -ENOENT;
}
open = pde->proc_fops->open;
release = pde->proc_fops->release; release = pde->proc_fops->release;
if (release) {
pdeo = kmalloc(sizeof(struct pde_opener), GFP_KERNEL);
if (!pdeo) {
rv = -ENOMEM;
goto out_unuse;
}
}
open = pde->proc_fops->open;
if (open) if (open)
rv = open(inode, file); rv = open(inode, file);
if (rv == 0 && release) { if (release) {
if (rv == 0) {
/* To know what to release. */ /* To know what to release. */
pdeo->file = file; pdeo->file = file;
pdeo->closing = false; pdeo->closing = false;
...@@ -366,7 +369,9 @@ static int proc_reg_open(struct inode *inode, struct file *file) ...@@ -366,7 +369,9 @@ static int proc_reg_open(struct inode *inode, struct file *file)
spin_unlock(&pde->pde_unload_lock); spin_unlock(&pde->pde_unload_lock);
} else } else
kfree(pdeo); kfree(pdeo);
}
out_unuse:
unuse_pde(pde); unuse_pde(pde);
return rv; return rv;
} }
......
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