Skip to contentSkip to conversation

selftests: memcg: don't close an uninitialized fd

PATCH Applied Sasha Levin 5 participants 5 messages Oct 11 – Oct 12

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: memcg: don't close an uninitialized fd

test_memcg_inotify_delete_file() and test_memcg_inotify_delete_dir() jump to cleanup before the inotify fd is created when cg_name() or cg_create() fails, and cleanup then closes whatever fd holds:

test_memcontrol.c:1685:6: warning: variable 'fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

Initialize fd to -1.

Fixes 2de27980e1d46 ("selftests: memcg: Add tests for IN_DELETE_SELF and IN_IGNORED")
Assisted-by LLM
---
 tools/testing/selftests/cgroup/test_memcontrol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/cgroup/test_memcontrol.c +2 -2
index 0ed82347044ed..047d487f6dd57 100644
@@ -1678,7 +1678,7 @@ static int test_memcg_inotify_delete_file(const char *root)
 {
 	int ret = KSFT_FAIL;
 	char *memcg = NULL;
-	int fd, wd;
+	int fd = -1, wd;
 
 	memcg = cg_name(root, "memcg_test_0");
 
@@ -1723,7 +1723,7 @@ static int test_memcg_inotify_delete_dir(const char *root)
 {
 	int ret = KSFT_FAIL;
 	char *memcg = NULL;
-	int fd, wd;
+	int fd = -1, wd;
 
 	memcg = cg_name(root, "memcg_test_0");
 
Signature · 1 line
2.53.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Sasha Levin

test_memcg_inotify_delete_file() and test_memcg_inotify_delete_dir() jump to cleanup before the inotify fd is created when cg_name() or cg_create() fails, and cleanup then closes whatever fd holds:

test_memcontrol.c:1685:6: warning: variable 'fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

Quoted 8 lines

Initialize fd to -1.

Fixes 2de27980e1d46 ("selftests: memcg: Add tests for IN_DELETE_SELF and IN_IGNORED")
Assisted-by LLM
---
 tools/testing/selftests/cgroup/test_memcontrol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Thanks too,

Reviewed-by on v1 1/1
#2 lore raw
In reply to Sasha Levin
Quoted 5 lines · Sasha Levin

test_memcg_inotify_delete_file() and test_memcg_inotify_delete_dir() jump to cleanup before the inotify fd is created when cg_name() or cg_create() fails, and cleanup then closes whatever fd holds:

Quoted 7 lines

test_memcontrol.c:1685:6: warning: variable 'fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

Initialize fd to -1.

Fixes 2de27980e1d46 ("selftests: memcg: Add tests for IN_DELETE_SELF and IN_IGNORED")
Assisted-by LLM
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Sasha Levin
Quoted 11 lines · Sasha Levin

test_memcg_inotify_delete_file() and test_memcg_inotify_delete_dir() jump to cleanup before the inotify fd is created when cg_name() or cg_create() fails, and cleanup then closes whatever fd holds:

test_memcontrol.c:1685:6: warning: variable 'fd' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

Initialize fd to -1.

Fixes 2de27980e1d46 ("selftests: memcg: Add tests for IN_DELETE_SELF and IN_IGNORED")
Assisted-by LLM