You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
UPSTREAM: 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(). Bug: 254441685 Link: https://lkml.kernel.org/r/20220902191149.112434-1-sj@kernel.org Fixes:75c1c2b53c("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> (cherry picked from commit1552fd3ef7) Signed-off-by: Lee Jones <joneslee@google.com> Change-Id: I7f2e8fa0167b3e44c4c251a51df341a6a7d98fd2
This commit is contained in:
committed by
Treehugger Robot
parent
3093f8b52c
commit
ed91943b48
@@ -787,6 +787,7 @@ static int dbgfs_rm_context(char *name)
|
||||
struct dentry *root, *dir, **new_dirs;
|
||||
struct damon_ctx **new_ctxs;
|
||||
int i, j;
|
||||
int ret = 0;
|
||||
|
||||
if (damon_nr_running_ctxs())
|
||||
return -EBUSY;
|
||||
@@ -801,14 +802,16 @@ static int dbgfs_rm_context(char *name)
|
||||
|
||||
new_dirs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_dirs),
|
||||
GFP_KERNEL);
|
||||
if (!new_dirs)
|
||||
return -ENOMEM;
|
||||
if (!new_dirs) {
|
||||
ret = -ENOMEM;
|
||||
goto out_dput;
|
||||
}
|
||||
|
||||
new_ctxs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_ctxs),
|
||||
GFP_KERNEL);
|
||||
if (!new_ctxs) {
|
||||
kfree(new_dirs);
|
||||
return -ENOMEM;
|
||||
ret = -ENOMEM;
|
||||
goto out_new_dirs;
|
||||
}
|
||||
|
||||
for (i = 0, j = 0; i < dbgfs_nr_ctxs; i++) {
|
||||
@@ -828,7 +831,13 @@ static int dbgfs_rm_context(char *name)
|
||||
dbgfs_ctxs = new_ctxs;
|
||||
dbgfs_nr_ctxs--;
|
||||
|
||||
return 0;
|
||||
goto out_dput;
|
||||
|
||||
out_new_dirs:
|
||||
kfree(new_dirs);
|
||||
out_dput:
|
||||
dput(dir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t dbgfs_rm_context_write(struct file *file,
|
||||
|
||||
Reference in New Issue
Block a user