From patchwork Thu Mar 28 02:56:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 10874439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DB9D1390 for ; Thu, 28 Mar 2019 02:57:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0528B28BAF for ; Thu, 28 Mar 2019 02:57:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED0F328BF2; Thu, 28 Mar 2019 02:57:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D3B328BAF for ; Thu, 28 Mar 2019 02:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728238AbfC1C5Q (ORCPT ); Wed, 27 Mar 2019 22:57:16 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45734 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725601AbfC1C5P (ORCPT ); Wed, 27 Mar 2019 22:57:15 -0400 Received: by mail-pf1-f194.google.com with SMTP id e24so9787940pfi.12; Wed, 27 Mar 2019 19:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ITdC+1ADsiB4y9MMRmP6Bmclm291PtUrCVKrjn/cGuY=; b=sHd5Xnk2TX/SxhXIXdfId7qONl55fRdC2JETfc8X4jEllj1Vzu1cw83f9fpAN90zjY v8qNj0Gz5Ax3UDfTWw/nWs1KeSw5ek+ZMcljfs7Vyrlw5IAUCshKN0TrcBABfoPY20Fw 2LqTLewGMzrbrnPHIPIoYT3LS8sdXvc4MOBRW0Ddz0ntGg8J2tm41YCceSOFNQK6qeQO gb0/2IrEyjCx3BXNsRN0auJmw9OopTD96hJWd9fRr9fxiFRemSgEu3lySnLTiOxL72Il g++T4CLWvWpFzwBiNK+ux2C+PAO1iUZsNd4AnNJOKvB3sSPh4i1mSMnJBB+Z6nEF911F HYHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ITdC+1ADsiB4y9MMRmP6Bmclm291PtUrCVKrjn/cGuY=; b=BtMxM4UxArsbpStia2CyXqCwICjZQ2+jyOC4EkQ0/vA3jFnHtr7EFUntOWU2fvaBa5 scAb/JkzyDqniO6GpBLH2MMLq6OF1aVA7nUaVGJ33trwqRKZ6Pah3qApjuxjCTghiize A7HEXzL97JUu47aywdi9Wm+4HczBwMM53bXvFUZgdHgxysjYd4SGDoQvaRAsGucCG3OA jLr+vtwY4pRcaH46QHb1T/MEPq+shJgEBFBh5KRWhBmc9cCVK0EdRBb4pXMb6tJ2f0lJ W7lV6GlsPOzYtdrgh7C6xpj7awkIqWgeZ0S3NRQMB812/3rlptt76ikpU4aULdbe/YcA PHGg== X-Gm-Message-State: APjAAAUNy9J5N+7m+Rbu2GB2t+LtZH4a9vegD2iTi3pL8YOCf+QvAuIk P2ClinATPMaaG1jk3n5ZH4TFLfEsAIk= X-Google-Smtp-Source: APXvYqw1DkA44OCD3cybhXDcR0c7kBBf+fEFjN8edsaX+WmPRj2rfuJlhqLXp4VOJ9dnOK/yJQ+UCQ== X-Received: by 2002:a62:1197:: with SMTP id 23mr38515737pfr.210.1553741835113; Wed, 27 Mar 2019 19:57:15 -0700 (PDT) Received: from castle.tfbnw.net ([2620:10d:c090:180::2396]) by smtp.gmail.com with ESMTPSA id a3sm16853813pfn.182.2019.03.27.19.57.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 Mar 2019 19:57:14 -0700 (PDT) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Roman Gushchin , Dan Carpenter , Shuah Khan , Mike Rapoport Subject: [PATCH kselftest-next] selftests: cgroup: fix cleanup path in test_memcg_subtree_control() Date: Wed, 27 Mar 2019 19:56:59 -0700 Message-Id: <20190328025659.25684-1-guro@fb.com> X-Mailer: git-send-email 2.17.2 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Fixes: 84092dbcf901 ("selftests: cgroup: add memory controller self-tests") Reported-by: Dan Carpenter Cc: Dan Carpenter Cc: Shuah Khan (Samsung OSG) Cc: Mike Rapoport --- .../selftests/cgroup/test_memcontrol.c | 38 ++++++++++--------- 1 file 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 @@ */ 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]; @@ -34,50 +34,54 @@ static int test_memcg_subtree_control(const char *root) 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; }