[PATCH v2 1/2] procfs: avoid some usages of seq_file private data
From: Stas Sergeev
Date: Fri Nov 08 2024 - 05:14:01 EST
seq_file private data carries the inode pointer here.
Replace
`struct inode *inode = m->private;`
with:
`struct inode *inode = file_inode(m->file);`
to avoid the reliance on private data.
This is needed so that `proc_single_show()` can be used by
custom fops that utilize seq_file private data for other things.
This is used in the next patch.
Signed-off-by: Stas Sergeev <stsp2@xxxxxxxxx>
CC: Eric Biederman <ebiederm@xxxxxxxxxxxx>
CC: Andy Lutomirski <luto@xxxxxxxxxx>
CC: Aleksa Sarai <cyphar@xxxxxxxxxx>
CC: Christian Brauner <brauner@xxxxxxxxxx>
CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CC: Jeff Layton <jlayton@xxxxxxxxxx>
CC: Kees Cook <kees@xxxxxxxxxx>
CC: "Peter Zijlstra (Intel)" <peterz@xxxxxxxxxxxxx>
CC: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
CC: Felix Moessbauer <felix.moessbauer@xxxxxxxxxxx>
CC: Adrian Ratiu <adrian.ratiu@xxxxxxxxxxxxx>
CC: Casey Schaufler <casey@xxxxxxxxxxxxxxxx>
CC: linux-kernel@xxxxxxxxxxxxxxx
CC: linux-fsdevel@xxxxxxxxxxxxxxx
CC: Jan Kara <jack@xxxxxxx>
CC: Chengming Zhou <chengming.zhou@xxxxxxxxx>
CC: Jens Axboe <axboe@xxxxxxxxx>
CC: Oleg Nesterov <oleg@xxxxxxxxxx>
Cc: "Serge E. Hallyn" <serge@xxxxxxxxxx>
---
fs/proc/base.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index b31283d81c52..015db8752a99 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -528,7 +528,7 @@ static int proc_pid_schedstat(struct seq_file *m, struct pid_namespace *ns,
static int lstats_show_proc(struct seq_file *m, void *v)
{
int i;
- struct inode *inode = m->private;
+ struct inode *inode = file_inode(m->file);
struct task_struct *task = get_proc_task(inode);
if (!task)
@@ -800,7 +800,7 @@ static const struct inode_operations proc_def_inode_operations = {
static int proc_single_show(struct seq_file *m, void *v)
{
- struct inode *inode = m->private;
+ struct inode *inode = file_inode(m->file);
struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
struct pid *pid = proc_pid(inode);
struct task_struct *task;
@@ -1494,7 +1494,7 @@ static const struct file_operations proc_fail_nth_operations = {
*/
static int sched_show(struct seq_file *m, void *v)
{
- struct inode *inode = m->private;
+ struct inode *inode = file_inode(m->file);
struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
struct task_struct *p;
@@ -1546,7 +1546,7 @@ static const struct file_operations proc_pid_sched_operations = {
*/
static int sched_autogroup_show(struct seq_file *m, void *v)
{
- struct inode *inode = m->private;
+ struct inode *inode = file_inode(m->file);
struct task_struct *p;
p = get_proc_task(inode);
@@ -1745,7 +1745,7 @@ static ssize_t comm_write(struct file *file, const char __user *buf,
static int comm_show(struct seq_file *m, void *v)
{
- struct inode *inode = m->private;
+ struct inode *inode = file_inode(m->file);
struct task_struct *p;
p = get_proc_task(inode);
@@ -2641,7 +2641,7 @@ static ssize_t timerslack_ns_write(struct file *file, const char __user *buf,
static int timerslack_ns_show(struct seq_file *m, void *v)
{
- struct inode *inode = m->private;
+ struct inode *inode = file_inode(m->file);
struct task_struct *p;
int err = 0;
--
2.47.0