Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/dbgfs: fix memory leak when using debugfs_lookup()

When calling debugfs_lookup() the result must have dput() called on it,
otherwise the memory will leak over time. Fix this up by properly calling
dput().

Link: https://lkml.kernel.org/r/20220902191149.112434-1-sj@kernel.org
Fixes: 75c1c2b53c78b ("mm/damon/dbgfs: support multiple contexts")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Greg Kroah-Hartman and committed by
Andrew Morton
1552fd3e fd35ca3d

+14 -5
+14 -5
mm/damon/dbgfs.c
··· 884 884 struct dentry *root, *dir, **new_dirs; 885 885 struct damon_ctx **new_ctxs; 886 886 int i, j; 887 + int ret = 0; 887 888 888 889 if (damon_nr_running_ctxs()) 889 890 return -EBUSY; ··· 899 898 900 899 new_dirs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_dirs), 901 900 GFP_KERNEL); 902 - if (!new_dirs) 903 - return -ENOMEM; 901 + if (!new_dirs) { 902 + ret = -ENOMEM; 903 + goto out_dput; 904 + } 904 905 905 906 new_ctxs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_ctxs), 906 907 GFP_KERNEL); 907 908 if (!new_ctxs) { 908 - kfree(new_dirs); 909 - return -ENOMEM; 909 + ret = -ENOMEM; 910 + goto out_new_dirs; 910 911 } 911 912 912 913 for (i = 0, j = 0; i < dbgfs_nr_ctxs; i++) { ··· 928 925 dbgfs_ctxs = new_ctxs; 929 926 dbgfs_nr_ctxs--; 930 927 931 - return 0; 928 + goto out_dput; 929 + 930 + out_new_dirs: 931 + kfree(new_dirs); 932 + out_dput: 933 + dput(dir); 934 + return ret; 932 935 } 933 936 934 937 static ssize_t dbgfs_rm_context_write(struct file *file,