Declare the seq_operations and the size of the private state and let
procfs open and free the seq_file. ->proc_open() and ->proc_release()
only set up and destroy the ioctl lock now.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 mm/alloc_tag.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/mm/alloc_tag.c b/mm/alloc_tag.c
index 82e2c3448dcf..788c9d7f7151 100644
--- a/mm/alloc_tag.c
+++ b/mm/alloc_tag.c
@@ -151,27 +151,21 @@ static const struct seq_operations allocinfo_seq_op = {
 };
 
 /*
- * Initializes seq_file operations and allocates private state when opening
- * the /proc/allocinfo procfs entry.
+ * Initializes the private state when opening the /proc/allocinfo procfs
+ * entry. procfs opened the seq_file and allocated the state.
  */
 static int allocinfo_open(struct inode *inode, struct file *file)
 {
-       int ret;
-
-       ret = seq_open_private(file, &allocinfo_seq_op,
-                              sizeof(struct allocinfo_private));
-       if (!ret) {
-               struct seq_file *m = file->private_data;
-               struct allocinfo_private *priv = m->private;
+       struct seq_file *m = file->private_data;
+       struct allocinfo_private *priv = m->private;
 
-               mutex_init(&priv->ioctl_lock);
-       }
-       return ret;
+       mutex_init(&priv->ioctl_lock);
+       return 0;
 }
 
 /*
- * Cleans up the seq_file state and frees up the private state allocated in
- * allocinfo_open() when closing the /proc/allocinfo file descriptor.
+ * Undoes allocinfo_open() when closing the /proc/allocinfo file descriptor.
+ * procfs frees the seq_file and the private state.
  */
 static int allocinfo_release(struct inode *inode, struct file *file)
 {
@@ -179,7 +173,7 @@ static int allocinfo_release(struct inode *inode, struct 
file *file)
        struct allocinfo_private *priv = m->private;
 
        mutex_destroy(&priv->ioctl_lock);
-       return seq_release_private(inode, file);
+       return 0;
 }
 
 /*
@@ -474,9 +468,9 @@ static long allocinfo_compat_ioctl(struct file *file, 
unsigned int cmd,
 #endif
 
 static const struct proc_ops allocinfo_proc_ops = {
+       .proc_seq_ops           = &allocinfo_seq_op,
+       .proc_state_size        = sizeof(struct allocinfo_private),
        .proc_open              = allocinfo_open,
-       .proc_read_iter         = seq_read_iter,
-       .proc_lseek             = seq_lseek,
        .proc_release           = allocinfo_release,
        .proc_ioctl             = allocinfo_ioctl,
 #ifdef CONFIG_COMPAT

-- 
2.53.0


Reply via email to