damon.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH mm-unstable 0/2] two fixups for DAMON sysfs' scheme filters support
@ 2022-12-19 17:18 SeongJae Park
  2022-12-19 17:18 ` [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: Fix leaking a filter for wrong cgroup path SeongJae Park
  2022-12-19 17:18 ` [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: Return an error for filter memcg path id lookup failure SeongJae Park
  0 siblings, 2 replies; 3+ messages in thread
From: SeongJae Park @ 2022-12-19 17:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, damon, linux-mm, linux-kernel

This patchset contains two fixups of DAMON sysfs' scheme filters
support, which is in mm-unstable.

SeongJae Park (2):
  mm/damon/sysfs-schemes: Fix leaking a filter for wrong cgroup path
  mm/damon/sysfs-schemes: Return an error for filter memcg path id
    lookup failure

 mm/damon/sysfs-schemes.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: Fix leaking a filter for wrong cgroup path
  2022-12-19 17:18 [PATCH mm-unstable 0/2] two fixups for DAMON sysfs' scheme filters support SeongJae Park
@ 2022-12-19 17:18 ` SeongJae Park
  2022-12-19 17:18 ` [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: Return an error for filter memcg path id lookup failure SeongJae Park
  1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2022-12-19 17:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: damon, linux-mm, linux-kernel, SeongJae Park

Commit f36f860207efa ("mm/damon/sysfs-schemes: implement scheme
filters") on mm-unstable introduced 'damon_syfs_set_scheme_filters()',
which does not free newly allocated filter when it fails setting memcg
id for the filter.  As a result, the memory for the filter leaks.  Fix
it by freeing the filter before returning the error.

Coverity CID: 1530032

Fixes: f36f860207ef ("mm/damon/sysfs-schemes: implement scheme filters") on mm-unstable
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 0501862534f2..5d3ac3107927 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1464,8 +1464,10 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme,
 			err = damon_sysfs_memcg_path_to_id(
 					sysfs_filter->memcg_path,
 					&filter->memcg_id);
-			if (err)
+			if (err) {
+				damos_destroy_filter(filter);
 				return err;
+			}
 		}
 		damos_add_filter(scheme, filter);
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: Return an error for filter memcg path id lookup failure
  2022-12-19 17:18 [PATCH mm-unstable 0/2] two fixups for DAMON sysfs' scheme filters support SeongJae Park
  2022-12-19 17:18 ` [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: Fix leaking a filter for wrong cgroup path SeongJae Park
@ 2022-12-19 17:18 ` SeongJae Park
  1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2022-12-19 17:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: damon, linux-mm, linux-kernel, SeongJae Park

Commit f36f860207ef ("mm/damon/sysfs-schemes: implement scheme filters")
on mm-unstable introduced damon_sysfs_memcg_path_to_id(), which returns
non-error even if it didn't find the memcg of the given path.  Caller
could check the failure by seeing if the 'id' has really set or not, but
it's unnecessarily complicated.  Return an error for the case instead.

Fixes: f36f860207ef ("mm/damon/sysfs-schemes: implement scheme filters") on mm-unstable
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 5d3ac3107927..f0dabe3e2dc0 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1418,6 +1418,7 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id)
 {
 	struct mem_cgroup *memcg;
 	char *path;
+	bool found = false;
 
 	if (!memcg_path)
 		return -EINVAL;
@@ -1433,12 +1434,13 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id)
 			continue;
 		if (damon_sysfs_memcg_path_eq(memcg, path, memcg_path)) {
 			*id = mem_cgroup_id(memcg);
+			found = true;
 			break;
 		}
 	}
 
 	kfree(path);
-	return 0;
+	return found ? 0 : -EINVAL;
 }
 
 static int damon_sysfs_set_scheme_filters(struct damos *scheme,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-19 17:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 17:18 [PATCH mm-unstable 0/2] two fixups for DAMON sysfs' scheme filters support SeongJae Park
2022-12-19 17:18 ` [PATCH mm-unstable 1/2] mm/damon/sysfs-schemes: Fix leaking a filter for wrong cgroup path SeongJae Park
2022-12-19 17:18 ` [PATCH mm-unstable 2/2] mm/damon/sysfs-schemes: Return an error for filter memcg path id lookup failure SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).