Skip to content

Commit

Permalink
selftests: cgroup: fix cleanup path in test_memcg_subtree_control()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Fixes: 84092db ("selftests: cgroup: add memory controller self-tests")
Reported-by: Dan Carpenter <[email protected]>
Cc: Dan Carpenter <[email protected]>
Cc: Shuah Khan (Samsung OSG) <[email protected]>
Cc: Mike Rapoport <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
  • Loading branch information
rgushchin authored and Shuah Khan committed Apr 8, 2019
1 parent f8a0590 commit e14d314
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions tools/testing/selftests/cgroup/test_memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,62 @@
*/
static int test_memcg_subtree_control(const char *root)
{
char *parent, *child, *parent2, *child2;
char *parent, *child, *parent2 = NULL, *child2 = NULL;
int ret = KSFT_FAIL;
char buf[PAGE_SIZE];

/* Create two nested cgroups with the memory controller enabled */
parent = cg_name(root, "memcg_test_0");
child = cg_name(root, "memcg_test_0/memcg_test_1");
if (!parent || !child)
goto cleanup;
goto cleanup_free;

if (cg_create(parent))
goto cleanup;
goto cleanup_free;

if (cg_write(parent, "cgroup.subtree_control", "+memory"))
goto cleanup;
goto cleanup_parent;

if (cg_create(child))
goto cleanup;
goto cleanup_parent;

if (cg_read_strstr(child, "cgroup.controllers", "memory"))
goto cleanup;
goto cleanup_child;

/* Create two nested cgroups without enabling memory controller */
parent2 = cg_name(root, "memcg_test_1");
child2 = cg_name(root, "memcg_test_1/memcg_test_1");
if (!parent2 || !child2)
goto cleanup;
goto cleanup_free2;

if (cg_create(parent2))
goto cleanup;
goto cleanup_free2;

if (cg_create(child2))
goto cleanup;
goto cleanup_parent2;

if (cg_read(child2, "cgroup.controllers", buf, sizeof(buf)))
goto cleanup;
goto cleanup_all;

if (!cg_read_strstr(child2, "cgroup.controllers", "memory"))
goto cleanup;
goto cleanup_all;

ret = KSFT_PASS;

cleanup:
cg_destroy(child);
cg_destroy(parent);
free(parent);
free(child);

cleanup_all:
cg_destroy(child2);
cleanup_parent2:
cg_destroy(parent2);
cleanup_free2:
free(parent2);
free(child2);
cleanup_child:
cg_destroy(child);
cleanup_parent:
cg_destroy(parent);
cleanup_free:
free(parent);
free(child);

return ret;
}
Expand Down

0 comments on commit e14d314

Please sign in to comment.