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

Cleanup the 4 duplicate "get_files_struct" implementations into one
get_files_struct() function to compliment put_files_struct().


---

 25-akpm/fs/proc/base.c       |   24 ++++--------------------
 25-akpm/include/linux/file.h |    4 ++++
 25-akpm/kernel/exit.c        |   13 +++++++++++++
 3 files changed, 21 insertions(+), 20 deletions(-)

diff -puN fs/proc/base.c~get_files_struct fs/proc/base.c
--- 25/fs/proc/base.c~get_files_struct	2004-04-10 13:15:21.097079408 -0700
+++ 25-akpm/fs/proc/base.c	2004-04-10 13:15:21.104078344 -0700
@@ -189,11 +189,7 @@ static int proc_fd_link(struct inode *in
 	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 * fil
 				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 dent
 	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(stru
 	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;
diff -puN include/linux/file.h~get_files_struct include/linux/file.h
--- 25/include/linux/file.h~get_files_struct	2004-04-10 13:15:21.098079256 -0700
+++ 25-akpm/include/linux/file.h	2004-04-10 13:15:21.106078040 -0700
@@ -75,6 +75,10 @@ static inline struct file * fcheck_files
 #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 */
diff -puN kernel/exit.c~get_files_struct kernel/exit.c
--- 25/kernel/exit.c~get_files_struct	2004-04-10 13:15:21.099079104 -0700
+++ 25-akpm/kernel/exit.c	2004-04-10 13:15:21.105078192 -0700
@@ -385,6 +385,19 @@ static inline void close_files(struct fi
 	}
 }
 
+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)) {

_