diff options
| author | Roman Gushchin <guro@fb.com> | 2019-04-08 18:12:30 -0400 |
|---|---|---|
| committer | Shuah Khan <shuah@kernel.org> | 2019-04-08 18:44:22 -0400 |
| commit | e14d314c7a489f060d6d691866fef5f131281718 (patch) | |
| tree | 64e018ae764324140b73f0f751973c579f653bea | |
| parent | f8a0590f0e01402873ec28a0da46f979f6bc56f1 (diff) | |
selftests: cgroup: fix cleanup path in test_memcg_subtree_control()
Dan reported, that cleanup path in test_memcg_subtree_control()
triggers a static checker warning:
./tools/testing/selftests/cgroup/test_memcontrol.c:76 \
test_memcg_subtree_control()
error: uninitialized symbol 'child2'.
Fix this by initializing child2 and parent2 variables and
split the cleanup path into few stages.
Signed-off-by: Roman Gushchin <guro@fb.com>
Fixes: 84092dbcf901 ("selftests: cgroup: add memory controller self-tests")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Shuah Khan (Samsung OSG) <shuah@kernel.org>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Shuah Khan <shuah@kernel.org>
| -rw-r--r-- | tools/testing/selftests/cgroup/test_memcontrol.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index 28d321ba311b..6f339882a6ca 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c | |||
| @@ -26,7 +26,7 @@ | |||
| 26 | */ | 26 | */ |
| 27 | static int test_memcg_subtree_control(const char *root) | 27 | static int test_memcg_subtree_control(const char *root) |
| 28 | { | 28 | { |
| 29 | char *parent, *child, *parent2, *child2; | 29 | char *parent, *child, *parent2 = NULL, *child2 = NULL; |
| 30 | int ret = KSFT_FAIL; | 30 | int ret = KSFT_FAIL; |
| 31 | char buf[PAGE_SIZE]; | 31 | char buf[PAGE_SIZE]; |
| 32 | 32 | ||
| @@ -34,50 +34,54 @@ static int test_memcg_subtree_control(const char *root) | |||
| 34 | parent = cg_name(root, "memcg_test_0"); | 34 | parent = cg_name(root, "memcg_test_0"); |
| 35 | child = cg_name(root, "memcg_test_0/memcg_test_1"); | 35 | child = cg_name(root, "memcg_test_0/memcg_test_1"); |
| 36 | if (!parent || !child) | 36 | if (!parent || !child) |
| 37 | goto cleanup; | 37 | goto cleanup_free; |
| 38 | 38 | ||
| 39 | if (cg_create(parent)) | 39 | if (cg_create(parent)) |
| 40 | goto cleanup; | 40 | goto cleanup_free; |
| 41 | 41 | ||
| 42 | if (cg_write(parent, "cgroup.subtree_control", "+memory")) | 42 | if (cg_write(parent, "cgroup.subtree_control", "+memory")) |
| 43 | goto cleanup; | 43 | goto cleanup_parent; |
| 44 | 44 | ||
| 45 | if (cg_create(child)) | 45 | if (cg_create(child)) |
| 46 | goto cleanup; | 46 | goto cleanup_parent; |
| 47 | 47 | ||
| 48 | if (cg_read_strstr(child, "cgroup.controllers", "memory")) | 48 | if (cg_read_strstr(child, "cgroup.controllers", "memory")) |
| 49 | goto cleanup; | 49 | goto cleanup_child; |
| 50 | 50 | ||
| 51 | /* Create two nested cgroups without enabling memory controller */ | 51 | /* Create two nested cgroups without enabling memory controller */ |
| 52 | parent2 = cg_name(root, "memcg_test_1"); | 52 | parent2 = cg_name(root, "memcg_test_1"); |
| 53 | child2 = cg_name(root, "memcg_test_1/memcg_test_1"); | 53 | child2 = cg_name(root, "memcg_test_1/memcg_test_1"); |
| 54 | if (!parent2 || !child2) | 54 | if (!parent2 || !child2) |
| 55 | goto cleanup; | 55 | goto cleanup_free2; |
| 56 | 56 | ||
| 57 | if (cg_create(parent2)) | 57 | if (cg_create(parent2)) |
| 58 | goto cleanup; | 58 | goto cleanup_free2; |
| 59 | 59 | ||
| 60 | if (cg_create(child2)) | 60 | if (cg_create(child2)) |
| 61 | goto cleanup; | 61 | goto cleanup_parent2; |
| 62 | 62 | ||
| 63 | if (cg_read(child2, "cgroup.controllers", buf, sizeof(buf))) | 63 | if (cg_read(child2, "cgroup.controllers", buf, sizeof(buf))) |
| 64 | goto cleanup; | 64 | goto cleanup_all; |
| 65 | 65 | ||
| 66 | if (!cg_read_strstr(child2, "cgroup.controllers", "memory")) | 66 | if (!cg_read_strstr(child2, "cgroup.controllers", "memory")) |
| 67 | goto cleanup; | 67 | goto cleanup_all; |
| 68 | 68 | ||
| 69 | ret = KSFT_PASS; | 69 | ret = KSFT_PASS; |
| 70 | 70 | ||
| 71 | cleanup: | 71 | cleanup_all: |
| 72 | cg_destroy(child); | ||
| 73 | cg_destroy(parent); | ||
| 74 | free(parent); | ||
| 75 | free(child); | ||
| 76 | |||
| 77 | cg_destroy(child2); | 72 | cg_destroy(child2); |
| 73 | cleanup_parent2: | ||
| 78 | cg_destroy(parent2); | 74 | cg_destroy(parent2); |
| 75 | cleanup_free2: | ||
| 79 | free(parent2); | 76 | free(parent2); |
| 80 | free(child2); | 77 | free(child2); |
| 78 | cleanup_child: | ||
| 79 | cg_destroy(child); | ||
| 80 | cleanup_parent: | ||
| 81 | cg_destroy(parent); | ||
| 82 | cleanup_free: | ||
| 83 | free(parent); | ||
| 84 | free(child); | ||
| 81 | 85 | ||
| 82 | return ret; | 86 | return ret; |
| 83 | } | 87 | } |
