Skip to content

Commit c52a47a

Browse files
author
Al Viro
committed
proc_fill_cache(): just make instantiate_t return int
all instances always return ERR_PTR(-E...) or NULL, anyway Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent db96316 commit c52a47a

4 files changed

Lines changed: 43 additions & 49 deletions

File tree

‎fs/proc/base.c‎

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx,
17001700
struct dentry *new;
17011701
new = d_alloc(dir, &qname);
17021702
if (new) {
1703-
child = instantiate(dir->d_inode, new, task, ptr);
1703+
child = ERR_PTR(instantiate(dir->d_inode, new, task, ptr));
17041704
if (child)
17051705
dput(new);
17061706
else
@@ -1844,7 +1844,7 @@ struct map_files_info {
18441844
unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */
18451845
};
18461846

1847-
static struct dentry *
1847+
static int
18481848
proc_map_files_instantiate(struct inode *dir, struct dentry *dentry,
18491849
struct task_struct *task, const void *ptr)
18501850
{
@@ -1854,7 +1854,7 @@ proc_map_files_instantiate(struct inode *dir, struct dentry *dentry,
18541854

18551855
inode = proc_pid_make_inode(dir->i_sb, task);
18561856
if (!inode)
1857-
return ERR_PTR(-ENOENT);
1857+
return -ENOENT;
18581858

18591859
ei = PROC_I(inode);
18601860
ei->op.proc_get_link = proc_map_files_get_link;
@@ -1871,7 +1871,7 @@ proc_map_files_instantiate(struct inode *dir, struct dentry *dentry,
18711871
d_set_d_op(dentry, &tid_map_files_dentry_operations);
18721872
d_add(dentry, inode);
18731873

1874-
return NULL;
1874+
return 0;
18751875
}
18761876

18771877
static struct dentry *proc_map_files_lookup(struct inode *dir,
@@ -1880,23 +1880,23 @@ static struct dentry *proc_map_files_lookup(struct inode *dir,
18801880
unsigned long vm_start, vm_end;
18811881
struct vm_area_struct *vma;
18821882
struct task_struct *task;
1883-
struct dentry *result;
1883+
int result;
18841884
struct mm_struct *mm;
18851885

1886-
result = ERR_PTR(-EPERM);
1886+
result = -EPERM;
18871887
if (!capable(CAP_SYS_ADMIN))
18881888
goto out;
18891889

1890-
result = ERR_PTR(-ENOENT);
1890+
result = -ENOENT;
18911891
task = get_proc_task(dir);
18921892
if (!task)
18931893
goto out;
18941894

1895-
result = ERR_PTR(-EACCES);
1895+
result = -EACCES;
18961896
if (!ptrace_may_access(task, PTRACE_MODE_READ))
18971897
goto out_put_task;
18981898

1899-
result = ERR_PTR(-ENOENT);
1899+
result = -ENOENT;
19001900
if (dname_to_vma_addr(dentry, &vm_start, &vm_end))
19011901
goto out_put_task;
19021902

@@ -1919,7 +1919,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir,
19191919
out_put_task:
19201920
put_task_struct(task);
19211921
out:
1922-
return result;
1922+
return ERR_PTR(result);
19231923
}
19241924

19251925
static const struct inode_operations proc_map_files_inode_operations = {
@@ -2133,13 +2133,12 @@ static const struct file_operations proc_timers_operations = {
21332133
};
21342134
#endif /* CONFIG_CHECKPOINT_RESTORE */
21352135

2136-
static struct dentry *proc_pident_instantiate(struct inode *dir,
2136+
static int proc_pident_instantiate(struct inode *dir,
21372137
struct dentry *dentry, struct task_struct *task, const void *ptr)
21382138
{
21392139
const struct pid_entry *p = ptr;
21402140
struct inode *inode;
21412141
struct proc_inode *ei;
2142-
struct dentry *error = ERR_PTR(-ENOENT);
21432142

21442143
inode = proc_pid_make_inode(dir->i_sb, task);
21452144
if (!inode)
@@ -2158,21 +2157,21 @@ static struct dentry *proc_pident_instantiate(struct inode *dir,
21582157
d_add(dentry, inode);
21592158
/* Close the race of the process dying before we return the dentry */
21602159
if (pid_revalidate(dentry, 0))
2161-
error = NULL;
2160+
return 0;
21622161
out:
2163-
return error;
2162+
return -ENOENT;
21642163
}
21652164

21662165
static struct dentry *proc_pident_lookup(struct inode *dir,
21672166
struct dentry *dentry,
21682167
const struct pid_entry *ents,
21692168
unsigned int nents)
21702169
{
2171-
struct dentry *error;
2170+
int error;
21722171
struct task_struct *task = get_proc_task(dir);
21732172
const struct pid_entry *p, *last;
21742173

2175-
error = ERR_PTR(-ENOENT);
2174+
error = -ENOENT;
21762175

21772176
if (!task)
21782177
goto out_no_task;
@@ -2195,7 +2194,7 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
21952194
out:
21962195
put_task_struct(task);
21972196
out_no_task:
2198-
return error;
2197+
return ERR_PTR(error);
21992198
}
22002199

22012200
static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
@@ -2778,11 +2777,10 @@ void proc_flush_task(struct task_struct *task)
27782777
}
27792778
}
27802779

2781-
static struct dentry *proc_pid_instantiate(struct inode *dir,
2782-
struct dentry * dentry,
2783-
struct task_struct *task, const void *ptr)
2780+
static int proc_pid_instantiate(struct inode *dir,
2781+
struct dentry * dentry,
2782+
struct task_struct *task, const void *ptr)
27842783
{
2785-
struct dentry *error = ERR_PTR(-ENOENT);
27862784
struct inode *inode;
27872785

27882786
inode = proc_pid_make_inode(dir->i_sb, task);
@@ -2802,14 +2800,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
28022800
d_add(dentry, inode);
28032801
/* Close the race of the process dying before we return the dentry */
28042802
if (pid_revalidate(dentry, 0))
2805-
error = NULL;
2803+
return 0;
28062804
out:
2807-
return error;
2805+
return -ENOENT;
28082806
}
28092807

28102808
struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags)
28112809
{
2812-
struct dentry *result = NULL;
2810+
int result = 0;
28132811
struct task_struct *task;
28142812
unsigned tgid;
28152813
struct pid_namespace *ns;
@@ -2830,7 +2828,7 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
28302828
result = proc_pid_instantiate(dir, dentry, task, NULL);
28312829
put_task_struct(task);
28322830
out:
2833-
return result;
2831+
return ERR_PTR(result);
28342832
}
28352833

28362834
/*
@@ -3025,10 +3023,9 @@ static const struct inode_operations proc_tid_base_inode_operations = {
30253023
.setattr = proc_setattr,
30263024
};
30273025

3028-
static struct dentry *proc_task_instantiate(struct inode *dir,
3026+
static int proc_task_instantiate(struct inode *dir,
30293027
struct dentry *dentry, struct task_struct *task, const void *ptr)
30303028
{
3031-
struct dentry *error = ERR_PTR(-ENOENT);
30323029
struct inode *inode;
30333030
inode = proc_pid_make_inode(dir->i_sb, task);
30343031

@@ -3047,14 +3044,14 @@ static struct dentry *proc_task_instantiate(struct inode *dir,
30473044
d_add(dentry, inode);
30483045
/* Close the race of the process dying before we return the dentry */
30493046
if (pid_revalidate(dentry, 0))
3050-
error = NULL;
3047+
return 0;
30513048
out:
3052-
return error;
3049+
return -ENOENT;
30533050
}
30543051

30553052
static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags)
30563053
{
3057-
struct dentry *result = ERR_PTR(-ENOENT);
3054+
int result = -ENOENT;
30583055
struct task_struct *task;
30593056
struct task_struct *leader = get_proc_task(dir);
30603057
unsigned tid;
@@ -3084,7 +3081,7 @@ static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry
30843081
out:
30853082
put_task_struct(leader);
30863083
out_no_task:
3087-
return result;
3084+
return ERR_PTR(result);
30883085
}
30893086

30903087
/*

‎fs/proc/fd.c‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,10 @@ static int proc_fd_link(struct dentry *dentry, struct path *path)
167167
return ret;
168168
}
169169

170-
static struct dentry *
170+
static int
171171
proc_fd_instantiate(struct inode *dir, struct dentry *dentry,
172172
struct task_struct *task, const void *ptr)
173173
{
174-
struct dentry *error = ERR_PTR(-ENOENT);
175174
unsigned fd = (unsigned long)ptr;
176175
struct proc_inode *ei;
177176
struct inode *inode;
@@ -194,17 +193,17 @@ proc_fd_instantiate(struct inode *dir, struct dentry *dentry,
194193

195194
/* Close the race of the process dying before we return the dentry */
196195
if (tid_fd_revalidate(dentry, 0))
197-
error = NULL;
196+
return 0;
198197
out:
199-
return error;
198+
return -ENOENT;
200199
}
201200

202201
static struct dentry *proc_lookupfd_common(struct inode *dir,
203202
struct dentry *dentry,
204203
instantiate_t instantiate)
205204
{
206205
struct task_struct *task = get_proc_task(dir);
207-
struct dentry *result = ERR_PTR(-ENOENT);
206+
int result = -ENOENT;
208207
unsigned fd = name_to_int(dentry);
209208

210209
if (!task)
@@ -216,7 +215,7 @@ static struct dentry *proc_lookupfd_common(struct inode *dir,
216215
out:
217216
put_task_struct(task);
218217
out_no_task:
219-
return result;
218+
return ERR_PTR(result);
220219
}
221220

222221
static int proc_readfd_common(struct file *file, struct dir_context *ctx,
@@ -300,11 +299,10 @@ const struct inode_operations proc_fd_inode_operations = {
300299
.setattr = proc_setattr,
301300
};
302301

303-
static struct dentry *
302+
static int
304303
proc_fdinfo_instantiate(struct inode *dir, struct dentry *dentry,
305304
struct task_struct *task, const void *ptr)
306305
{
307-
struct dentry *error = ERR_PTR(-ENOENT);
308306
unsigned fd = (unsigned long)ptr;
309307
struct proc_inode *ei;
310308
struct inode *inode;
@@ -324,9 +322,9 @@ proc_fdinfo_instantiate(struct inode *dir, struct dentry *dentry,
324322

325323
/* Close the race of the process dying before we return the dentry */
326324
if (tid_fd_revalidate(dentry, 0))
327-
error = NULL;
325+
return 0;
328326
out:
329-
return error;
327+
return -ENOENT;
330328
}
331329

332330
static struct dentry *

‎fs/proc/internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ extern struct dentry *proc_pid_lookup(struct inode *, struct dentry *, unsigned
170170
extern loff_t mem_lseek(struct file *, loff_t, int);
171171

172172
/* Lookups */
173-
typedef struct dentry *instantiate_t(struct inode *, struct dentry *,
173+
typedef int instantiate_t(struct inode *, struct dentry *,
174174
struct task_struct *, const void *);
175175
extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, int,
176176
instantiate_t, struct task_struct *, const void *);

‎fs/proc/namespaces.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,12 @@ static const struct inode_operations proc_ns_link_inode_operations = {
187187
.setattr = proc_setattr,
188188
};
189189

190-
static struct dentry *proc_ns_instantiate(struct inode *dir,
190+
static int proc_ns_instantiate(struct inode *dir,
191191
struct dentry *dentry, struct task_struct *task, const void *ptr)
192192
{
193193
const struct proc_ns_operations *ns_ops = ptr;
194194
struct inode *inode;
195195
struct proc_inode *ei;
196-
struct dentry *error = ERR_PTR(-ENOENT);
197196

198197
inode = proc_pid_make_inode(dir->i_sb, task);
199198
if (!inode)
@@ -208,9 +207,9 @@ static struct dentry *proc_ns_instantiate(struct inode *dir,
208207
d_add(dentry, inode);
209208
/* Close the race of the process dying before we return the dentry */
210209
if (pid_revalidate(dentry, 0))
211-
error = NULL;
210+
return 0;
212211
out:
213-
return error;
212+
return -ENOENT;
214213
}
215214

216215
static int proc_ns_dir_readdir(struct file *file, struct dir_context *ctx)
@@ -248,12 +247,12 @@ const struct file_operations proc_ns_dir_operations = {
248247
static struct dentry *proc_ns_dir_lookup(struct inode *dir,
249248
struct dentry *dentry, unsigned int flags)
250249
{
251-
struct dentry *error;
250+
int error;
252251
struct task_struct *task = get_proc_task(dir);
253252
const struct proc_ns_operations **entry, **last;
254253
unsigned int len = dentry->d_name.len;
255254

256-
error = ERR_PTR(-ENOENT);
255+
error = -ENOENT;
257256

258257
if (!task)
259258
goto out_no_task;
@@ -272,7 +271,7 @@ static struct dentry *proc_ns_dir_lookup(struct inode *dir,
272271
out:
273272
put_task_struct(task);
274273
out_no_task:
275-
return error;
274+
return ERR_PTR(error);
276275
}
277276

278277
const struct inode_operations proc_ns_dir_inode_operations = {

0 commit comments

Comments
 (0)