Skip to content

Commit ce623f8

Browse files
cypharAl Viro
authored andcommitted
nsfs: clean-up ns_get_path() signature to return int
ns_get_path() and ns_get_path_cb() only ever return either NULL or an ERR_PTR. It is far more idiomatic to simply return an integer, and it makes all of the callers of ns_get_path() more straightforward to read. Fixes: e149ed2 ("take the targets of /proc/*/ns/* symlinks to separate fs") Signed-off-by: Aleksa Sarai <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 2b98149 commit ce623f8

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

fs/nsfs.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void nsfs_evict(struct inode *inode)
5252
ns->ops->put(ns);
5353
}
5454

55-
static void *__ns_get_path(struct path *path, struct ns_common *ns)
55+
static int __ns_get_path(struct path *path, struct ns_common *ns)
5656
{
5757
struct vfsmount *mnt = nsfs_mnt;
5858
struct dentry *dentry;
@@ -71,13 +71,13 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
7171
got_it:
7272
path->mnt = mntget(mnt);
7373
path->dentry = dentry;
74-
return NULL;
74+
return 0;
7575
slow:
7676
rcu_read_unlock();
7777
inode = new_inode_pseudo(mnt->mnt_sb);
7878
if (!inode) {
7979
ns->ops->put(ns);
80-
return ERR_PTR(-ENOMEM);
80+
return -ENOMEM;
8181
}
8282
inode->i_ino = ns->inum;
8383
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
@@ -89,7 +89,7 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
8989
dentry = d_alloc_anon(mnt->mnt_sb);
9090
if (!dentry) {
9191
iput(inode);
92-
return ERR_PTR(-ENOMEM);
92+
return -ENOMEM;
9393
}
9494
d_instantiate(dentry, inode);
9595
dentry->d_fsdata = (void *)ns->ops;
@@ -98,23 +98,22 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
9898
d_delete(dentry); /* make sure ->d_prune() does nothing */
9999
dput(dentry);
100100
cpu_relax();
101-
return ERR_PTR(-EAGAIN);
101+
return -EAGAIN;
102102
}
103103
goto got_it;
104104
}
105105

106-
void *ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb,
106+
int ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb,
107107
void *private_data)
108108
{
109-
void *ret;
109+
int ret;
110110

111111
do {
112112
struct ns_common *ns = ns_get_cb(private_data);
113113
if (!ns)
114-
return ERR_PTR(-ENOENT);
115-
114+
return -ENOENT;
116115
ret = __ns_get_path(path, ns);
117-
} while (ret == ERR_PTR(-EAGAIN));
116+
} while (ret == -EAGAIN);
118117

119118
return ret;
120119
}
@@ -131,7 +130,7 @@ static struct ns_common *ns_get_path_task(void *private_data)
131130
return args->ns_ops->get(args->task);
132131
}
133132

134-
void *ns_get_path(struct path *path, struct task_struct *task,
133+
int ns_get_path(struct path *path, struct task_struct *task,
135134
const struct proc_ns_operations *ns_ops)
136135
{
137136
struct ns_get_path_task_args args = {
@@ -147,7 +146,7 @@ int open_related_ns(struct ns_common *ns,
147146
{
148147
struct path path = {};
149148
struct file *f;
150-
void *err;
149+
int err;
151150
int fd;
152151

153152
fd = get_unused_fd_flags(O_CLOEXEC);
@@ -164,11 +163,11 @@ int open_related_ns(struct ns_common *ns,
164163
}
165164

166165
err = __ns_get_path(&path, relative);
167-
} while (err == ERR_PTR(-EAGAIN));
166+
} while (err == -EAGAIN);
168167

169-
if (IS_ERR(err)) {
168+
if (err) {
170169
put_unused_fd(fd);
171-
return PTR_ERR(err);
170+
return err;
172171
}
173172

174173
f = dentry_open(&path, O_RDONLY, current_cred());

fs/proc/namespaces.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ static const char *proc_ns_get_link(struct dentry *dentry,
4242
const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops;
4343
struct task_struct *task;
4444
struct path ns_path;
45-
void *error = ERR_PTR(-EACCES);
45+
int error = -EACCES;
4646

4747
if (!dentry)
4848
return ERR_PTR(-ECHILD);
4949

5050
task = get_proc_task(inode);
5151
if (!task)
52-
return error;
52+
return ERR_PTR(-EACCES);
5353

5454
if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) {
5555
error = ns_get_path(&ns_path, task, ns_ops);
5656
if (!error)
5757
nd_jump_link(&ns_path);
5858
}
5959
put_task_struct(task);
60-
return error;
60+
return ERR_PTR(error);
6161
}
6262

6363
static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int buflen)

include/linux/proc_ns.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ static inline int ns_alloc_inum(struct ns_common *ns)
7676

7777
extern struct file *proc_ns_fget(int fd);
7878
#define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
79-
extern void *ns_get_path(struct path *path, struct task_struct *task,
79+
extern int ns_get_path(struct path *path, struct task_struct *task,
8080
const struct proc_ns_operations *ns_ops);
8181
typedef struct ns_common *ns_get_path_helper_t(void *);
82-
extern void *ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb,
82+
extern int ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb,
8383
void *private_data);
8484

8585
extern int ns_get_name(char *buf, size_t size, struct task_struct *task,

kernel/bpf/offload.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,14 @@ int bpf_prog_offload_info_fill(struct bpf_prog_info *info,
302302
struct inode *ns_inode;
303303
struct path ns_path;
304304
char __user *uinsns;
305-
void *res;
305+
int res;
306306
u32 ulen;
307307

308308
res = ns_get_path_cb(&ns_path, bpf_prog_offload_info_fill_ns, &args);
309-
if (IS_ERR(res)) {
309+
if (res) {
310310
if (!info->ifindex)
311311
return -ENODEV;
312-
return PTR_ERR(res);
312+
return res;
313313
}
314314

315315
down_read(&bpf_devs_lock);
@@ -526,13 +526,13 @@ int bpf_map_offload_info_fill(struct bpf_map_info *info, struct bpf_map *map)
526526
};
527527
struct inode *ns_inode;
528528
struct path ns_path;
529-
void *res;
529+
int res;
530530

531531
res = ns_get_path_cb(&ns_path, bpf_map_offload_info_fill_ns, &args);
532-
if (IS_ERR(res)) {
532+
if (res) {
533533
if (!info->ifindex)
534534
return -ENODEV;
535-
return PTR_ERR(res);
535+
return res;
536536
}
537537

538538
ns_inode = ns_path.dentry->d_inode;

kernel/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7495,7 +7495,7 @@ static void perf_fill_ns_link_info(struct perf_ns_link_info *ns_link_info,
74957495
{
74967496
struct path ns_path;
74977497
struct inode *ns_inode;
7498-
void *error;
7498+
int error;
74997499

75007500
error = ns_get_path(&ns_path, task, ns_ops);
75017501
if (!error) {

0 commit comments

Comments
 (0)