diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2018-05-03 09:21:05 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-05-26 14:20:50 -0400 |
commit | 0168b9e38c4213e162b15444c071d4198ff470e8 (patch) | |
tree | 151cef9ad46ce8fda8a088ef14a3dc7da302cee6 | |
parent | 988363864132f86d5722dddd7f765080ef271519 (diff) |
procfs: switch instantiate_t to d_splice_alias()
... and get rid of pointless struct inode *dir argument of those,
while we are at it.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/proc/base.c | 93 | ||||
-rw-r--r-- | fs/proc/fd.c | 30 | ||||
-rw-r--r-- | fs/proc/internal.h | 2 | ||||
-rw-r--r-- | fs/proc/namespaces.c | 19 |
4 files changed, 65 insertions, 79 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 6e0875505898..de22c2002b38 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -1878,8 +1878,8 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx, | |||
1878 | struct dentry *child, *dir = file->f_path.dentry; | 1878 | struct dentry *child, *dir = file->f_path.dentry; |
1879 | struct qstr qname = QSTR_INIT(name, len); | 1879 | struct qstr qname = QSTR_INIT(name, len); |
1880 | struct inode *inode; | 1880 | struct inode *inode; |
1881 | unsigned type; | 1881 | unsigned type = DT_UNKNOWN; |
1882 | ino_t ino; | 1882 | ino_t ino = 1; |
1883 | 1883 | ||
1884 | child = d_hash_and_lookup(dir, &qname); | 1884 | child = d_hash_and_lookup(dir, &qname); |
1885 | if (!child) { | 1885 | if (!child) { |
@@ -1888,22 +1888,23 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx, | |||
1888 | if (IS_ERR(child)) | 1888 | if (IS_ERR(child)) |
1889 | goto end_instantiate; | 1889 | goto end_instantiate; |
1890 | if (d_in_lookup(child)) { | 1890 | if (d_in_lookup(child)) { |
1891 | int err = instantiate(d_inode(dir), child, task, ptr); | 1891 | struct dentry *res; |
1892 | res = instantiate(child, task, ptr); | ||
1892 | d_lookup_done(child); | 1893 | d_lookup_done(child); |
1893 | if (err < 0) { | 1894 | if (IS_ERR(res)) |
1894 | dput(child); | ||
1895 | goto end_instantiate; | 1895 | goto end_instantiate; |
1896 | if (unlikely(res)) { | ||
1897 | dput(child); | ||
1898 | child = res; | ||
1896 | } | 1899 | } |
1897 | } | 1900 | } |
1898 | } | 1901 | } |
1899 | inode = d_inode(child); | 1902 | inode = d_inode(child); |
1900 | ino = inode->i_ino; | 1903 | ino = inode->i_ino; |
1901 | type = inode->i_mode >> 12; | 1904 | type = inode->i_mode >> 12; |
1905 | end_instantiate: | ||
1902 | dput(child); | 1906 | dput(child); |
1903 | return dir_emit(ctx, name, len, ino, type); | 1907 | return dir_emit(ctx, name, len, ino, type); |
1904 | |||
1905 | end_instantiate: | ||
1906 | return dir_emit(ctx, name, len, 1, DT_UNKNOWN); | ||
1907 | } | 1908 | } |
1908 | 1909 | ||
1909 | /* | 1910 | /* |
@@ -2065,19 +2066,19 @@ static const struct inode_operations proc_map_files_link_inode_operations = { | |||
2065 | .setattr = proc_setattr, | 2066 | .setattr = proc_setattr, |
2066 | }; | 2067 | }; |
2067 | 2068 | ||
2068 | static int | 2069 | static struct dentry * |
2069 | proc_map_files_instantiate(struct inode *dir, struct dentry *dentry, | 2070 | proc_map_files_instantiate(struct dentry *dentry, |
2070 | struct task_struct *task, const void *ptr) | 2071 | struct task_struct *task, const void *ptr) |
2071 | { | 2072 | { |
2072 | fmode_t mode = (fmode_t)(unsigned long)ptr; | 2073 | fmode_t mode = (fmode_t)(unsigned long)ptr; |
2073 | struct proc_inode *ei; | 2074 | struct proc_inode *ei; |
2074 | struct inode *inode; | 2075 | struct inode *inode; |
2075 | 2076 | ||
2076 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFLNK | | 2077 | inode = proc_pid_make_inode(dentry->d_sb, task, S_IFLNK | |
2077 | ((mode & FMODE_READ ) ? S_IRUSR : 0) | | 2078 | ((mode & FMODE_READ ) ? S_IRUSR : 0) | |
2078 | ((mode & FMODE_WRITE) ? S_IWUSR : 0)); | 2079 | ((mode & FMODE_WRITE) ? S_IWUSR : 0)); |
2079 | if (!inode) | 2080 | if (!inode) |
2080 | return -ENOENT; | 2081 | return ERR_PTR(-ENOENT); |
2081 | 2082 | ||
2082 | ei = PROC_I(inode); | 2083 | ei = PROC_I(inode); |
2083 | ei->op.proc_get_link = map_files_get_link; | 2084 | ei->op.proc_get_link = map_files_get_link; |
@@ -2086,9 +2087,7 @@ proc_map_files_instantiate(struct inode *dir, struct dentry *dentry, | |||
2086 | inode->i_size = 64; | 2087 | inode->i_size = 64; |
2087 | 2088 | ||
2088 | d_set_d_op(dentry, &tid_map_files_dentry_operations); | 2089 | d_set_d_op(dentry, &tid_map_files_dentry_operations); |
2089 | d_add(dentry, inode); | 2090 | return d_splice_alias(inode, dentry); |
2090 | |||
2091 | return 0; | ||
2092 | } | 2091 | } |
2093 | 2092 | ||
2094 | static struct dentry *proc_map_files_lookup(struct inode *dir, | 2093 | static struct dentry *proc_map_files_lookup(struct inode *dir, |
@@ -2097,19 +2096,19 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, | |||
2097 | unsigned long vm_start, vm_end; | 2096 | unsigned long vm_start, vm_end; |
2098 | struct vm_area_struct *vma; | 2097 | struct vm_area_struct *vma; |
2099 | struct task_struct *task; | 2098 | struct task_struct *task; |
2100 | int result; | 2099 | struct dentry *result; |
2101 | struct mm_struct *mm; | 2100 | struct mm_struct *mm; |
2102 | 2101 | ||
2103 | result = -ENOENT; | 2102 | result = ERR_PTR(-ENOENT); |
2104 | task = get_proc_task(dir); | 2103 | task = get_proc_task(dir); |
2105 | if (!task) | 2104 | if (!task) |
2106 | goto out; | 2105 | goto out; |
2107 | 2106 | ||
2108 | result = -EACCES; | 2107 | result = ERR_PTR(-EACCES); |
2109 | if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) | 2108 | if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) |
2110 | goto out_put_task; | 2109 | goto out_put_task; |
2111 | 2110 | ||
2112 | result = -ENOENT; | 2111 | result = ERR_PTR(-ENOENT); |
2113 | if (dname_to_vma_addr(dentry, &vm_start, &vm_end)) | 2112 | if (dname_to_vma_addr(dentry, &vm_start, &vm_end)) |
2114 | goto out_put_task; | 2113 | goto out_put_task; |
2115 | 2114 | ||
@@ -2123,7 +2122,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, | |||
2123 | goto out_no_vma; | 2122 | goto out_no_vma; |
2124 | 2123 | ||
2125 | if (vma->vm_file) | 2124 | if (vma->vm_file) |
2126 | result = proc_map_files_instantiate(dir, dentry, task, | 2125 | result = proc_map_files_instantiate(dentry, task, |
2127 | (void *)(unsigned long)vma->vm_file->f_mode); | 2126 | (void *)(unsigned long)vma->vm_file->f_mode); |
2128 | 2127 | ||
2129 | out_no_vma: | 2128 | out_no_vma: |
@@ -2132,7 +2131,7 @@ out_no_vma: | |||
2132 | out_put_task: | 2131 | out_put_task: |
2133 | put_task_struct(task); | 2132 | put_task_struct(task); |
2134 | out: | 2133 | out: |
2135 | return ERR_PTR(result); | 2134 | return result; |
2136 | } | 2135 | } |
2137 | 2136 | ||
2138 | static const struct inode_operations proc_map_files_inode_operations = { | 2137 | static const struct inode_operations proc_map_files_inode_operations = { |
@@ -2433,16 +2432,16 @@ static const struct file_operations proc_pid_set_timerslack_ns_operations = { | |||
2433 | .release = single_release, | 2432 | .release = single_release, |
2434 | }; | 2433 | }; |
2435 | 2434 | ||
2436 | static int proc_pident_instantiate(struct inode *dir, | 2435 | static struct dentry *proc_pident_instantiate(struct dentry *dentry, |
2437 | struct dentry *dentry, struct task_struct *task, const void *ptr) | 2436 | struct task_struct *task, const void *ptr) |
2438 | { | 2437 | { |
2439 | const struct pid_entry *p = ptr; | 2438 | const struct pid_entry *p = ptr; |
2440 | struct inode *inode; | 2439 | struct inode *inode; |
2441 | struct proc_inode *ei; | 2440 | struct proc_inode *ei; |
2442 | 2441 | ||
2443 | inode = proc_pid_make_inode(dir->i_sb, task, p->mode); | 2442 | inode = proc_pid_make_inode(dentry->d_sb, task, p->mode); |
2444 | if (!inode) | 2443 | if (!inode) |
2445 | return -ENOENT; | 2444 | return ERR_PTR(-ENOENT); |
2446 | 2445 | ||
2447 | ei = PROC_I(inode); | 2446 | ei = PROC_I(inode); |
2448 | if (S_ISDIR(inode->i_mode)) | 2447 | if (S_ISDIR(inode->i_mode)) |
@@ -2454,8 +2453,7 @@ static int proc_pident_instantiate(struct inode *dir, | |||
2454 | ei->op = p->op; | 2453 | ei->op = p->op; |
2455 | pid_update_inode(task, inode); | 2454 | pid_update_inode(task, inode); |
2456 | d_set_d_op(dentry, &pid_dentry_operations); | 2455 | d_set_d_op(dentry, &pid_dentry_operations); |
2457 | d_add(dentry, inode); | 2456 | return d_splice_alias(inode, dentry); |
2458 | return 0; | ||
2459 | } | 2457 | } |
2460 | 2458 | ||
2461 | static struct dentry *proc_pident_lookup(struct inode *dir, | 2459 | static struct dentry *proc_pident_lookup(struct inode *dir, |
@@ -2463,11 +2461,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir, | |||
2463 | const struct pid_entry *ents, | 2461 | const struct pid_entry *ents, |
2464 | unsigned int nents) | 2462 | unsigned int nents) |
2465 | { | 2463 | { |
2466 | int error; | ||
2467 | struct task_struct *task = get_proc_task(dir); | 2464 | struct task_struct *task = get_proc_task(dir); |
2468 | const struct pid_entry *p, *last; | 2465 | const struct pid_entry *p, *last; |
2469 | 2466 | struct dentry *res = ERR_PTR(-ENOENT); | |
2470 | error = -ENOENT; | ||
2471 | 2467 | ||
2472 | if (!task) | 2468 | if (!task) |
2473 | goto out_no_task; | 2469 | goto out_no_task; |
@@ -2486,11 +2482,11 @@ static struct dentry *proc_pident_lookup(struct inode *dir, | |||
2486 | if (p >= last) | 2482 | if (p >= last) |
2487 | goto out; | 2483 | goto out; |
2488 | 2484 | ||
2489 | error = proc_pident_instantiate(dir, dentry, task, p); | 2485 | res = proc_pident_instantiate(dentry, task, p); |
2490 | out: | 2486 | out: |
2491 | put_task_struct(task); | 2487 | put_task_struct(task); |
2492 | out_no_task: | 2488 | out_no_task: |
2493 | return ERR_PTR(error); | 2489 | return res; |
2494 | } | 2490 | } |
2495 | 2491 | ||
2496 | static int proc_pident_readdir(struct file *file, struct dir_context *ctx, | 2492 | static int proc_pident_readdir(struct file *file, struct dir_context *ctx, |
@@ -3133,15 +3129,14 @@ void proc_flush_task(struct task_struct *task) | |||
3133 | } | 3129 | } |
3134 | } | 3130 | } |
3135 | 3131 | ||
3136 | static int proc_pid_instantiate(struct inode *dir, | 3132 | static struct dentry *proc_pid_instantiate(struct dentry * dentry, |
3137 | struct dentry * dentry, | ||
3138 | struct task_struct *task, const void *ptr) | 3133 | struct task_struct *task, const void *ptr) |
3139 | { | 3134 | { |
3140 | struct inode *inode; | 3135 | struct inode *inode; |
3141 | 3136 | ||
3142 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFDIR | S_IRUGO | S_IXUGO); | 3137 | inode = proc_pid_make_inode(dentry->d_sb, task, S_IFDIR | S_IRUGO | S_IXUGO); |
3143 | if (!inode) | 3138 | if (!inode) |
3144 | return -ENOENT; | 3139 | return ERR_PTR(-ENOENT); |
3145 | 3140 | ||
3146 | inode->i_op = &proc_tgid_base_inode_operations; | 3141 | inode->i_op = &proc_tgid_base_inode_operations; |
3147 | inode->i_fop = &proc_tgid_base_operations; | 3142 | inode->i_fop = &proc_tgid_base_operations; |
@@ -3151,16 +3146,15 @@ static int proc_pid_instantiate(struct inode *dir, | |||
3151 | pid_update_inode(task, inode); | 3146 | pid_update_inode(task, inode); |
3152 | 3147 | ||
3153 | d_set_d_op(dentry, &pid_dentry_operations); | 3148 | d_set_d_op(dentry, &pid_dentry_operations); |
3154 | d_add(dentry, inode); | 3149 | return d_splice_alias(inode, dentry); |
3155 | return 0; | ||
3156 | } | 3150 | } |
3157 | 3151 | ||
3158 | struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) | 3152 | struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) |
3159 | { | 3153 | { |
3160 | int result = -ENOENT; | ||
3161 | struct task_struct *task; | 3154 | struct task_struct *task; |
3162 | unsigned tgid; | 3155 | unsigned tgid; |
3163 | struct pid_namespace *ns; | 3156 | struct pid_namespace *ns; |
3157 | struct dentry *result = ERR_PTR(-ENOENT); | ||
3164 | 3158 | ||
3165 | tgid = name_to_int(&dentry->d_name); | 3159 | tgid = name_to_int(&dentry->d_name); |
3166 | if (tgid == ~0U) | 3160 | if (tgid == ~0U) |
@@ -3175,10 +3169,10 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign | |||
3175 | if (!task) | 3169 | if (!task) |
3176 | goto out; | 3170 | goto out; |
3177 | 3171 | ||
3178 | result = proc_pid_instantiate(dir, dentry, task, NULL); | 3172 | result = proc_pid_instantiate(dentry, task, NULL); |
3179 | put_task_struct(task); | 3173 | put_task_struct(task); |
3180 | out: | 3174 | out: |
3181 | return ERR_PTR(result); | 3175 | return result; |
3182 | } | 3176 | } |
3183 | 3177 | ||
3184 | /* | 3178 | /* |
@@ -3426,13 +3420,13 @@ static const struct inode_operations proc_tid_base_inode_operations = { | |||
3426 | .setattr = proc_setattr, | 3420 | .setattr = proc_setattr, |
3427 | }; | 3421 | }; |
3428 | 3422 | ||
3429 | static int proc_task_instantiate(struct inode *dir, | 3423 | static struct dentry *proc_task_instantiate(struct dentry *dentry, |
3430 | struct dentry *dentry, struct task_struct *task, const void *ptr) | 3424 | struct task_struct *task, const void *ptr) |
3431 | { | 3425 | { |
3432 | struct inode *inode; | 3426 | struct inode *inode; |
3433 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFDIR | S_IRUGO | S_IXUGO); | 3427 | inode = proc_pid_make_inode(dentry->d_sb, task, S_IFDIR | S_IRUGO | S_IXUGO); |
3434 | if (!inode) | 3428 | if (!inode) |
3435 | return -ENOENT; | 3429 | return ERR_PTR(-ENOENT); |
3436 | 3430 | ||
3437 | inode->i_op = &proc_tid_base_inode_operations; | 3431 | inode->i_op = &proc_tid_base_inode_operations; |
3438 | inode->i_fop = &proc_tid_base_operations; | 3432 | inode->i_fop = &proc_tid_base_operations; |
@@ -3442,17 +3436,16 @@ static int proc_task_instantiate(struct inode *dir, | |||
3442 | pid_update_inode(task, inode); | 3436 | pid_update_inode(task, inode); |
3443 | 3437 | ||
3444 | d_set_d_op(dentry, &pid_dentry_operations); | 3438 | d_set_d_op(dentry, &pid_dentry_operations); |
3445 | d_add(dentry, inode); | 3439 | return d_splice_alias(inode, dentry); |
3446 | return 0; | ||
3447 | } | 3440 | } |
3448 | 3441 | ||
3449 | static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) | 3442 | static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) |
3450 | { | 3443 | { |
3451 | int result = -ENOENT; | ||
3452 | struct task_struct *task; | 3444 | struct task_struct *task; |
3453 | struct task_struct *leader = get_proc_task(dir); | 3445 | struct task_struct *leader = get_proc_task(dir); |
3454 | unsigned tid; | 3446 | unsigned tid; |
3455 | struct pid_namespace *ns; | 3447 | struct pid_namespace *ns; |
3448 | struct dentry *result = ERR_PTR(-ENOENT); | ||
3456 | 3449 | ||
3457 | if (!leader) | 3450 | if (!leader) |
3458 | goto out_no_task; | 3451 | goto out_no_task; |
@@ -3472,13 +3465,13 @@ static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry | |||
3472 | if (!same_thread_group(leader, task)) | 3465 | if (!same_thread_group(leader, task)) |
3473 | goto out_drop_task; | 3466 | goto out_drop_task; |
3474 | 3467 | ||
3475 | result = proc_task_instantiate(dir, dentry, task, NULL); | 3468 | result = proc_task_instantiate(dentry, task, NULL); |
3476 | out_drop_task: | 3469 | out_drop_task: |
3477 | put_task_struct(task); | 3470 | put_task_struct(task); |
3478 | out: | 3471 | out: |
3479 | put_task_struct(leader); | 3472 | put_task_struct(leader); |
3480 | out_no_task: | 3473 | out_no_task: |
3481 | return ERR_PTR(result); | 3474 | return result; |
3482 | } | 3475 | } |
3483 | 3476 | ||
3484 | /* | 3477 | /* |
diff --git a/fs/proc/fd.c b/fs/proc/fd.c index f5de22a9e9e0..05b9893e9a22 100644 --- a/fs/proc/fd.c +++ b/fs/proc/fd.c | |||
@@ -179,17 +179,16 @@ struct fd_data { | |||
179 | unsigned fd; | 179 | unsigned fd; |
180 | }; | 180 | }; |
181 | 181 | ||
182 | static int | 182 | static struct dentry *proc_fd_instantiate(struct dentry *dentry, |
183 | proc_fd_instantiate(struct inode *dir, struct dentry *dentry, | 183 | struct task_struct *task, const void *ptr) |
184 | struct task_struct *task, const void *ptr) | ||
185 | { | 184 | { |
186 | const struct fd_data *data = ptr; | 185 | const struct fd_data *data = ptr; |
187 | struct proc_inode *ei; | 186 | struct proc_inode *ei; |
188 | struct inode *inode; | 187 | struct inode *inode; |
189 | 188 | ||
190 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFLNK); | 189 | inode = proc_pid_make_inode(dentry->d_sb, task, S_IFLNK); |
191 | if (!inode) | 190 | if (!inode) |
192 | return -ENOENT; | 191 | return ERR_PTR(-ENOENT); |
193 | 192 | ||
194 | ei = PROC_I(inode); | 193 | ei = PROC_I(inode); |
195 | ei->fd = data->fd; | 194 | ei->fd = data->fd; |
@@ -201,8 +200,7 @@ proc_fd_instantiate(struct inode *dir, struct dentry *dentry, | |||
201 | tid_fd_update_inode(task, inode, data->mode); | 200 | tid_fd_update_inode(task, inode, data->mode); |
202 | 201 | ||
203 | d_set_d_op(dentry, &tid_fd_dentry_operations); | 202 | d_set_d_op(dentry, &tid_fd_dentry_operations); |
204 | d_add(dentry, inode); | 203 | return d_splice_alias(inode, dentry); |
205 | return 0; | ||
206 | } | 204 | } |
207 | 205 | ||
208 | static struct dentry *proc_lookupfd_common(struct inode *dir, | 206 | static struct dentry *proc_lookupfd_common(struct inode *dir, |
@@ -210,8 +208,8 @@ static struct dentry *proc_lookupfd_common(struct inode *dir, | |||
210 | instantiate_t instantiate) | 208 | instantiate_t instantiate) |
211 | { | 209 | { |
212 | struct task_struct *task = get_proc_task(dir); | 210 | struct task_struct *task = get_proc_task(dir); |
213 | int result = -ENOENT; | ||
214 | struct fd_data data = {.fd = name_to_int(&dentry->d_name)}; | 211 | struct fd_data data = {.fd = name_to_int(&dentry->d_name)}; |
212 | struct dentry *result = ERR_PTR(-ENOENT); | ||
215 | 213 | ||
216 | if (!task) | 214 | if (!task) |
217 | goto out_no_task; | 215 | goto out_no_task; |
@@ -220,11 +218,11 @@ static struct dentry *proc_lookupfd_common(struct inode *dir, | |||
220 | if (!tid_fd_mode(task, data.fd, &data.mode)) | 218 | if (!tid_fd_mode(task, data.fd, &data.mode)) |
221 | goto out; | 219 | goto out; |
222 | 220 | ||
223 | result = instantiate(dir, dentry, task, &data); | 221 | result = instantiate(dentry, task, &data); |
224 | out: | 222 | out: |
225 | put_task_struct(task); | 223 | put_task_struct(task); |
226 | out_no_task: | 224 | out_no_task: |
227 | return ERR_PTR(result); | 225 | return result; |
228 | } | 226 | } |
229 | 227 | ||
230 | static int proc_readfd_common(struct file *file, struct dir_context *ctx, | 228 | static int proc_readfd_common(struct file *file, struct dir_context *ctx, |
@@ -320,17 +318,16 @@ const struct inode_operations proc_fd_inode_operations = { | |||
320 | .setattr = proc_setattr, | 318 | .setattr = proc_setattr, |
321 | }; | 319 | }; |
322 | 320 | ||
323 | static int | 321 | static struct dentry *proc_fdinfo_instantiate(struct dentry *dentry, |
324 | proc_fdinfo_instantiate(struct inode *dir, struct dentry *dentry, | 322 | struct task_struct *task, const void *ptr) |
325 | struct task_struct *task, const void *ptr) | ||
326 | { | 323 | { |
327 | const struct fd_data *data = ptr; | 324 | const struct fd_data *data = ptr; |
328 | struct proc_inode *ei; | 325 | struct proc_inode *ei; |
329 | struct inode *inode; | 326 | struct inode *inode; |
330 | 327 | ||
331 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFREG | S_IRUSR); | 328 | inode = proc_pid_make_inode(dentry->d_sb, task, S_IFREG | S_IRUSR); |
332 | if (!inode) | 329 | if (!inode) |
333 | return -ENOENT; | 330 | return ERR_PTR(-ENOENT); |
334 | 331 | ||
335 | ei = PROC_I(inode); | 332 | ei = PROC_I(inode); |
336 | ei->fd = data->fd; | 333 | ei->fd = data->fd; |
@@ -339,8 +336,7 @@ proc_fdinfo_instantiate(struct inode *dir, struct dentry *dentry, | |||
339 | tid_fd_update_inode(task, inode, 0); | 336 | tid_fd_update_inode(task, inode, 0); |
340 | 337 | ||
341 | d_set_d_op(dentry, &tid_fd_dentry_operations); | 338 | d_set_d_op(dentry, &tid_fd_dentry_operations); |
342 | d_add(dentry, inode); | 339 | return d_splice_alias(inode, dentry); |
343 | return 0; | ||
344 | } | 340 | } |
345 | 341 | ||
346 | static struct dentry * | 342 | static struct dentry * |
diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 04a455b9ae69..275b062e58af 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h | |||
@@ -154,7 +154,7 @@ extern struct dentry *proc_pid_lookup(struct inode *, struct dentry *, unsigned | |||
154 | extern loff_t mem_lseek(struct file *, loff_t, int); | 154 | extern loff_t mem_lseek(struct file *, loff_t, int); |
155 | 155 | ||
156 | /* Lookups */ | 156 | /* Lookups */ |
157 | typedef int instantiate_t(struct inode *, struct dentry *, | 157 | typedef struct dentry *instantiate_t(struct dentry *, |
158 | struct task_struct *, const void *); | 158 | struct task_struct *, const void *); |
159 | extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, int, | 159 | extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, int, |
160 | instantiate_t, struct task_struct *, const void *); | 160 | instantiate_t, struct task_struct *, const void *); |
diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c index ad1adce6541d..dd2b35f78b09 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c | |||
@@ -87,16 +87,16 @@ static const struct inode_operations proc_ns_link_inode_operations = { | |||
87 | .setattr = proc_setattr, | 87 | .setattr = proc_setattr, |
88 | }; | 88 | }; |
89 | 89 | ||
90 | static int proc_ns_instantiate(struct inode *dir, | 90 | static struct dentry *proc_ns_instantiate(struct dentry *dentry, |
91 | struct dentry *dentry, struct task_struct *task, const void *ptr) | 91 | struct task_struct *task, const void *ptr) |
92 | { | 92 | { |
93 | const struct proc_ns_operations *ns_ops = ptr; | 93 | const struct proc_ns_operations *ns_ops = ptr; |
94 | struct inode *inode; | 94 | struct inode *inode; |
95 | struct proc_inode *ei; | 95 | struct proc_inode *ei; |
96 | 96 | ||
97 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFLNK | S_IRWXUGO); | 97 | inode = proc_pid_make_inode(dentry->d_sb, task, S_IFLNK | S_IRWXUGO); |
98 | if (!inode) | 98 | if (!inode) |
99 | return -ENOENT; | 99 | return ERR_PTR(-ENOENT); |
100 | 100 | ||
101 | ei = PROC_I(inode); | 101 | ei = PROC_I(inode); |
102 | inode->i_op = &proc_ns_link_inode_operations; | 102 | inode->i_op = &proc_ns_link_inode_operations; |
@@ -104,8 +104,7 @@ static int proc_ns_instantiate(struct inode *dir, | |||
104 | pid_update_inode(task, inode); | 104 | pid_update_inode(task, inode); |
105 | 105 | ||
106 | d_set_d_op(dentry, &pid_dentry_operations); | 106 | d_set_d_op(dentry, &pid_dentry_operations); |
107 | d_add(dentry, inode); | 107 | return d_splice_alias(inode, dentry); |
108 | return 0; | ||
109 | } | 108 | } |
110 | 109 | ||
111 | static int proc_ns_dir_readdir(struct file *file, struct dir_context *ctx) | 110 | static int proc_ns_dir_readdir(struct file *file, struct dir_context *ctx) |
@@ -144,12 +143,10 @@ const struct file_operations proc_ns_dir_operations = { | |||
144 | static struct dentry *proc_ns_dir_lookup(struct inode *dir, | 143 | static struct dentry *proc_ns_dir_lookup(struct inode *dir, |
145 | struct dentry *dentry, unsigned int flags) | 144 | struct dentry *dentry, unsigned int flags) |
146 | { | 145 | { |
147 | int error; | ||
148 | struct task_struct *task = get_proc_task(dir); | 146 | struct task_struct *task = get_proc_task(dir); |
149 | const struct proc_ns_operations **entry, **last; | 147 | const struct proc_ns_operations **entry, **last; |
150 | unsigned int len = dentry->d_name.len; | 148 | unsigned int len = dentry->d_name.len; |
151 | 149 | struct dentry *res = ERR_PTR(-ENOENT); | |
152 | error = -ENOENT; | ||
153 | 150 | ||
154 | if (!task) | 151 | if (!task) |
155 | goto out_no_task; | 152 | goto out_no_task; |
@@ -164,11 +161,11 @@ static struct dentry *proc_ns_dir_lookup(struct inode *dir, | |||
164 | if (entry == last) | 161 | if (entry == last) |
165 | goto out; | 162 | goto out; |
166 | 163 | ||
167 | error = proc_ns_instantiate(dir, dentry, task, *entry); | 164 | res = proc_ns_instantiate(dentry, task, *entry); |
168 | out: | 165 | out: |
169 | put_task_struct(task); | 166 | put_task_struct(task); |
170 | out_no_task: | 167 | out_no_task: |
171 | return ERR_PTR(error); | 168 | return res; |
172 | } | 169 | } |
173 | 170 | ||
174 | const struct inode_operations proc_ns_dir_inode_operations = { | 171 | const struct inode_operations proc_ns_dir_inode_operations = { |