@@ -1652,46 +1652,12 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
16521652 return error ;
16531653}
16541654
1655- static int proc_pid_fd_link_getattr (struct vfsmount * mnt , struct dentry * dentry ,
1656- struct kstat * stat )
1657- {
1658- struct inode * inode = dentry -> d_inode ;
1659- struct task_struct * task = get_proc_task (inode );
1660- int rc ;
1661-
1662- if (task == NULL )
1663- return - ESRCH ;
1664-
1665- rc = - EACCES ;
1666- if (lock_trace (task ))
1667- goto out_task ;
1668-
1669- generic_fillattr (inode , stat );
1670- unlock_trace (task );
1671- rc = 0 ;
1672- out_task :
1673- put_task_struct (task );
1674- return rc ;
1675- }
1676-
16771655static const struct inode_operations proc_pid_link_inode_operations = {
16781656 .readlink = proc_pid_readlink ,
16791657 .follow_link = proc_pid_follow_link ,
16801658 .setattr = proc_setattr ,
16811659};
16821660
1683- static const struct inode_operations proc_fdinfo_link_inode_operations = {
1684- .setattr = proc_setattr ,
1685- .getattr = proc_pid_fd_link_getattr ,
1686- };
1687-
1688- static const struct inode_operations proc_fd_link_inode_operations = {
1689- .readlink = proc_pid_readlink ,
1690- .follow_link = proc_pid_follow_link ,
1691- .setattr = proc_setattr ,
1692- .getattr = proc_pid_fd_link_getattr ,
1693- };
1694-
16951661
16961662/* building an inode */
16971663
@@ -1923,61 +1889,49 @@ static unsigned name_to_int(struct dentry *dentry)
19231889
19241890static int proc_fd_info (struct inode * inode , struct path * path , char * info )
19251891{
1926- struct task_struct * task ;
1927- struct files_struct * files ;
1892+ struct task_struct * task = get_proc_task ( inode ) ;
1893+ struct files_struct * files = NULL ;
19281894 struct file * file ;
19291895 int fd = proc_fd (inode );
1930- int rc ;
1931-
1932- task = get_proc_task (inode );
1933- if (!task )
1934- return - ENOENT ;
1935-
1936- rc = - EACCES ;
1937- if (lock_trace (task ))
1938- goto out_task ;
1939-
1940- rc = - ENOENT ;
1941- files = get_files_struct (task );
1942- if (files == NULL )
1943- goto out_unlock ;
19441896
1945- /*
1946- * We are not taking a ref to the file structure, so we must
1947- * hold ->file_lock.
1948- */
1949- spin_lock (& files -> file_lock );
1950- file = fcheck_files (files , fd );
1951- if (file ) {
1952- unsigned int f_flags ;
1953- struct fdtable * fdt ;
1954-
1955- fdt = files_fdtable (files );
1956- f_flags = file -> f_flags & ~O_CLOEXEC ;
1957- if (FD_ISSET (fd , fdt -> close_on_exec ))
1958- f_flags |= O_CLOEXEC ;
1959-
1960- if (path ) {
1961- * path = file -> f_path ;
1962- path_get (& file -> f_path );
1897+ if (task ) {
1898+ files = get_files_struct (task );
1899+ put_task_struct (task );
1900+ }
1901+ if (files ) {
1902+ /*
1903+ * We are not taking a ref to the file structure, so we must
1904+ * hold ->file_lock.
1905+ */
1906+ spin_lock (& files -> file_lock );
1907+ file = fcheck_files (files , fd );
1908+ if (file ) {
1909+ unsigned int f_flags ;
1910+ struct fdtable * fdt ;
1911+
1912+ fdt = files_fdtable (files );
1913+ f_flags = file -> f_flags & ~O_CLOEXEC ;
1914+ if (FD_ISSET (fd , fdt -> close_on_exec ))
1915+ f_flags |= O_CLOEXEC ;
1916+
1917+ if (path ) {
1918+ * path = file -> f_path ;
1919+ path_get (& file -> f_path );
1920+ }
1921+ if (info )
1922+ snprintf (info , PROC_FDINFO_MAX ,
1923+ "pos:\t%lli\n"
1924+ "flags:\t0%o\n" ,
1925+ (long long ) file -> f_pos ,
1926+ f_flags );
1927+ spin_unlock (& files -> file_lock );
1928+ put_files_struct (files );
1929+ return 0 ;
19631930 }
1964- if (info )
1965- snprintf (info , PROC_FDINFO_MAX ,
1966- "pos:\t%lli\n"
1967- "flags:\t0%o\n" ,
1968- (long long ) file -> f_pos ,
1969- f_flags );
1970- rc = 0 ;
1971- } else
1972- rc = - ENOENT ;
1973- spin_unlock (& files -> file_lock );
1974- put_files_struct (files );
1975-
1976- out_unlock :
1977- unlock_trace (task );
1978- out_task :
1979- put_task_struct (task );
1980- return rc ;
1931+ spin_unlock (& files -> file_lock );
1932+ put_files_struct (files );
1933+ }
1934+ return - ENOENT ;
19811935}
19821936
19831937static int proc_fd_link (struct inode * inode , struct path * path )
@@ -2072,7 +2026,7 @@ static struct dentry *proc_fd_instantiate(struct inode *dir,
20722026 spin_unlock (& files -> file_lock );
20732027 put_files_struct (files );
20742028
2075- inode -> i_op = & proc_fd_link_inode_operations ;
2029+ inode -> i_op = & proc_pid_link_inode_operations ;
20762030 inode -> i_size = 64 ;
20772031 ei -> op .proc_get_link = proc_fd_link ;
20782032 d_set_d_op (dentry , & tid_fd_dentry_operations );
@@ -2104,12 +2058,7 @@ static struct dentry *proc_lookupfd_common(struct inode *dir,
21042058 if (fd == ~0U )
21052059 goto out ;
21062060
2107- result = ERR_PTR (- EACCES );
2108- if (lock_trace (task ))
2109- goto out ;
2110-
21112061 result = instantiate (dir , dentry , task , & fd );
2112- unlock_trace (task );
21132062out :
21142063 put_task_struct (task );
21152064out_no_task :
@@ -2129,28 +2078,23 @@ static int proc_readfd_common(struct file * filp, void * dirent,
21292078 retval = - ENOENT ;
21302079 if (!p )
21312080 goto out_no_task ;
2132-
2133- retval = - EACCES ;
2134- if (lock_trace (p ))
2135- goto out ;
2136-
21372081 retval = 0 ;
21382082
21392083 fd = filp -> f_pos ;
21402084 switch (fd ) {
21412085 case 0 :
21422086 if (filldir (dirent , "." , 1 , 0 , inode -> i_ino , DT_DIR ) < 0 )
2143- goto out_unlock ;
2087+ goto out ;
21442088 filp -> f_pos ++ ;
21452089 case 1 :
21462090 ino = parent_ino (dentry );
21472091 if (filldir (dirent , ".." , 2 , 1 , ino , DT_DIR ) < 0 )
2148- goto out_unlock ;
2092+ goto out ;
21492093 filp -> f_pos ++ ;
21502094 default :
21512095 files = get_files_struct (p );
21522096 if (!files )
2153- goto out_unlock ;
2097+ goto out ;
21542098 rcu_read_lock ();
21552099 for (fd = filp -> f_pos - 2 ;
21562100 fd < files_fdtable (files )-> max_fds ;
@@ -2174,9 +2118,6 @@ static int proc_readfd_common(struct file * filp, void * dirent,
21742118 rcu_read_unlock ();
21752119 put_files_struct (files );
21762120 }
2177-
2178- out_unlock :
2179- unlock_trace (p );
21802121out :
21812122 put_task_struct (p );
21822123out_no_task :
@@ -2254,7 +2195,6 @@ static struct dentry *proc_fdinfo_instantiate(struct inode *dir,
22542195 ei -> fd = fd ;
22552196 inode -> i_mode = S_IFREG | S_IRUSR ;
22562197 inode -> i_fop = & proc_fdinfo_file_operations ;
2257- inode -> i_op = & proc_fdinfo_link_inode_operations ;
22582198 d_set_d_op (dentry , & tid_fd_dentry_operations );
22592199 d_add (dentry , inode );
22602200 /* Close the race of the process dying before we return the dentry */
0 commit comments