Commit a16129b8 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] get_files_struct cleanup

From: Russell King <rmk@arm.linux.org.uk>

Cleanup the 4 duplicate "get_files_struct" implementations into one
get_files_struct() function to compliment put_files_struct().
parent c2bd1247
......@@ -189,11 +189,7 @@ static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsm
struct file *file;
int fd = proc_type(inode) - PROC_TID_FD_DIR;
task_lock(task);
files = task->files;
if (files)
atomic_inc(&files->count);
task_unlock(task);
files = get_files_struct(task);
if (files) {
spin_lock(&files->file_lock);
file = fcheck_files(files, fd);
......@@ -806,11 +802,7 @@ static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
goto out;
filp->f_pos++;
default:
task_lock(p);
files = p->files;
if (files)
atomic_inc(&files->count);
task_unlock(p);
files = get_files_struct(p);
if (!files)
goto out;
spin_lock(&files->file_lock);
......@@ -1009,11 +1001,7 @@ static int tid_fd_revalidate(struct dentry *dentry, struct nameidata *nd)
int fd = proc_type(inode) - PROC_TID_FD_DIR;
struct files_struct *files;
task_lock(task);
files = task->files;
if (files)
atomic_inc(&files->count);
task_unlock(task);
files = get_files_struct(task);
if (files) {
spin_lock(&files->file_lock);
if (fcheck_files(files, fd)) {
......@@ -1117,11 +1105,7 @@ static struct dentry *proc_lookupfd(struct inode * dir, struct dentry * dentry,
if (!inode)
goto out;
ei = PROC_I(inode);
task_lock(task);
files = task->files;
if (files)
atomic_inc(&files->count);
task_unlock(task);
files = get_files_struct(task);
if (!files)
goto out_unlock;
inode->i_mode = S_IFLNK;
......
......@@ -75,6 +75,10 @@ static inline struct file * fcheck_files(struct files_struct *files, unsigned in
#define fcheck(fd) fcheck_files(current->files, fd)
extern void FASTCALL(fd_install(unsigned int fd, struct file * file));
struct task_struct;
struct files_struct *get_files_struct(struct task_struct *);
void FASTCALL(put_files_struct(struct files_struct *fs));
#endif /* __LINUX_FILE_H */
......@@ -385,6 +385,19 @@ static inline void close_files(struct files_struct * files)
}
}
struct files_struct *get_files_struct(struct task_struct *task)
{
struct files_struct *files;
task_lock(task);
files = task->files;
if (files)
atomic_inc(&files->count);
task_unlock(task);
return files;
}
void fastcall put_files_struct(struct files_struct *files)
{
if (atomic_dec_and_test(&files->count)) {
......
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