get_files_struct
PATCH 1/1 get_files_struct
Cleanup the 4 duplicate "get_files_struct" implementations into one get_files_struct() function to compliment put_files_struct().
I'm not particularly bothered about this patch; it builds and works for me, though I don't have a particular reason to keep it around.
It may be useful for the -tiny tree.
Whatever, if someone thinks its useful...
fs/proc/base.c +4 -20
@@ -189,11 +189,7 @@ static int proc_fd_link(struct inode *instruct 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 dentint 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(struif (!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 ;
kernel/exit.c +13 -0
@@ -386,6 +386,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)) {
include/linux/file.h +4 -0
@@ -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 */
Signature · 4 lines
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial core