Skip to content

Commit 2a07a1f

Browse files
author
Miklos Szeredi
committed
proc/self: use generic_readlink
The /proc/self and /proc/self-thread symlinks have separate but identical functionality for reading and following. This cleanup utilizes generic_readlink to remove the duplication. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 6c988f5 commit 2a07a1f

2 files changed

Lines changed: 2 additions & 27 deletions

File tree

‎fs/proc/self.c‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66
/*
77
* /proc/self:
88
*/
9-
static int proc_self_readlink(struct dentry *dentry, char __user *buffer,
10-
int buflen)
11-
{
12-
struct pid_namespace *ns = dentry->d_sb->s_fs_info;
13-
pid_t tgid = task_tgid_nr_ns(current, ns);
14-
char tmp[PROC_NUMBUF];
15-
if (!tgid)
16-
return -ENOENT;
17-
sprintf(tmp, "%d", tgid);
18-
return readlink_copy(buffer, buflen, tmp);
19-
}
20-
219
static const char *proc_self_get_link(struct dentry *dentry,
2210
struct inode *inode,
2311
struct delayed_call *done)
@@ -38,7 +26,7 @@ static const char *proc_self_get_link(struct dentry *dentry,
3826
}
3927

4028
static const struct inode_operations proc_self_inode_operations = {
41-
.readlink = proc_self_readlink,
29+
.readlink = generic_readlink,
4230
.get_link = proc_self_get_link,
4331
};
4432

‎fs/proc/thread_self.c‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66
/*
77
* /proc/thread_self:
88
*/
9-
static int proc_thread_self_readlink(struct dentry *dentry, char __user *buffer,
10-
int buflen)
11-
{
12-
struct pid_namespace *ns = dentry->d_sb->s_fs_info;
13-
pid_t tgid = task_tgid_nr_ns(current, ns);
14-
pid_t pid = task_pid_nr_ns(current, ns);
15-
char tmp[PROC_NUMBUF + 6 + PROC_NUMBUF];
16-
if (!pid)
17-
return -ENOENT;
18-
sprintf(tmp, "%d/task/%d", tgid, pid);
19-
return readlink_copy(buffer, buflen, tmp);
20-
}
21-
229
static const char *proc_thread_self_get_link(struct dentry *dentry,
2310
struct inode *inode,
2411
struct delayed_call *done)
@@ -40,7 +27,7 @@ static const char *proc_thread_self_get_link(struct dentry *dentry,
4027
}
4128

4229
static const struct inode_operations proc_thread_self_inode_operations = {
43-
.readlink = proc_thread_self_readlink,
30+
.readlink = generic_readlink,
4431
.get_link = proc_thread_self_get_link,
4532
};
4633

0 commit comments

Comments
 (0)