Declare the seq_operations and let procfs open and free the seq_file.
->proc_open() only takes the snapshot of the statistics now and
->proc_release() frees it.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 kernel/locking/lockdep_proc.c | 48 +++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 1916db9aa46b..9b034b5b94bd 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -638,40 +638,35 @@ static const struct seq_operations lockstat_ops = {
        .show   = ls_show,
 };
 
+/* procfs opens the seq_file */
 static int lock_stat_open(struct inode *inode, struct file *file)
 {
-       int res;
-       struct lock_class *class;
        struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq));
+       struct lock_stat_data *iter;
+       struct seq_file *m = file->private_data;
+       struct lock_class *class;
+       unsigned long idx;
 
        if (!data)
                return -ENOMEM;
 
-       res = seq_open(file, &lockstat_ops);
-       if (!res) {
-               struct lock_stat_data *iter = data->stats;
-               struct seq_file *m = file->private_data;
-               unsigned long idx;
-
-               iterate_lock_classes(idx, class) {
-                       if (!test_bit(idx, lock_classes_in_use))
-                               continue;
-                       iter->class = class;
-                       lock_stats(class, &iter->stats);
-                       iter++;
-               }
-
-               data->iter_end = iter;
+       iter = data->stats;
+       iterate_lock_classes(idx, class) {
+               if (!test_bit(idx, lock_classes_in_use))
+                       continue;
+               iter->class = class;
+               lock_stats(class, &iter->stats);
+               iter++;
+       }
 
-               sort(data->stats, data->iter_end - data->stats,
-                               sizeof(struct lock_stat_data),
-                               lock_stat_cmp, NULL);
+       data->iter_end = iter;
 
-               m->private = data;
-       } else
-               vfree(data);
+       sort(data->stats, data->iter_end - data->stats,
+                       sizeof(struct lock_stat_data),
+                       lock_stat_cmp, NULL);
 
-       return res;
+       m->private = data;
+       return 0;
 }
 
 static ssize_t lock_stat_write(struct file *file, const char __user *buf,
@@ -702,14 +697,13 @@ static int lock_stat_release(struct inode *inode, struct 
file *file)
        struct seq_file *seq = file->private_data;
 
        vfree(seq->private);
-       return seq_release(inode, file);
+       return 0;
 }
 
 static const struct proc_ops lock_stat_proc_ops = {
+       .proc_seq_ops   = &lockstat_ops,
        .proc_open      = lock_stat_open,
        .proc_write     = lock_stat_write,
-       .proc_read      = seq_read,
-       .proc_lseek     = seq_lseek,
        .proc_release   = lock_stat_release,
 };
 #endif /* CONFIG_LOCK_STAT */

-- 
2.53.0


Reply via email to