From patchwork Fri Sep 7 16:49:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jay Kamat X-Patchwork-Id: 10592383 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 F0EE5112B for ; Fri, 7 Sep 2018 16:54:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DABF82B74B for ; Fri, 7 Sep 2018 16:54:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEAA62B761; Fri, 7 Sep 2018 16:54:18 +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,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 338E42B74B for ; Fri, 7 Sep 2018 16:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727125AbeIGVgD (ORCPT ); Fri, 7 Sep 2018 17:36:03 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:56150 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbeIGVgC (ORCPT ); Fri, 7 Sep 2018 17:36:02 -0400 Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w87GmCJW001033; Fri, 7 Sep 2018 09:54:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=IHd+o/y27bcNh11PbhX79Xxdw+65wKbS+IufV3cHfkU=; b=CNNaPLTfhUdKIHpfRVQzh7PaJbWys5wh910MqeEgDbuCMNA5CFYpJv6RllLm5MsAiLxS 9Cph48TSZ2p8IN/eos2Q0s4HZtycOuuE8dXcu/XRab/yARW/cwonCiR/VWPlEStCqUVf M2iYlSudqq7f/rVMhzqncJ/lHWvJtvYMaoA= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2mbv1wg7y0-11 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 07 Sep 2018 09:54:12 -0700 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.34) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 7 Sep 2018 12:52:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IHd+o/y27bcNh11PbhX79Xxdw+65wKbS+IufV3cHfkU=; b=QGK3RfU1/ftfHTzyp5EN59paj/Trj9IUfAxdRrBdszz+hu1WO2Lp4oIWSPFUo2fsMn4s0YF0JN9ZL1gK54PNhKIOgFS7u9PB/oEtbX0ANF2upCxHYPY3vidoXFrR6JhDvFwg3eHP1RwOREXmhZZW2ikfxbnpbQVFSNUkOGCh8qY= Received: from vall.thefacebook.com (2620:10d:c090:200::4:cd5) by CY4PR15MB1223.namprd15.prod.outlook.com (2603:10b6:903:10a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.15; Fri, 7 Sep 2018 16:52:44 +0000 From: To: CC: , Roman Gushchin , Tejun Heo , , , , Subject: [PATCH 1/2] Fix cg_read_strcmp() Date: Fri, 7 Sep 2018 09:49:23 -0700 Message-ID: <20180907164924.13789-2-jgkamat@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180907164924.13789-1-jgkamat@fb.com> References: <20180905010827.27743-1-jgkamat@fb.com> <20180907164924.13789-1-jgkamat@fb.com> MIME-Version: 1.0 X-Originating-IP: [2620:10d:c090:200::4:cd5] X-ClientProxiedBy: AM6PR06CA0004.eurprd06.prod.outlook.com (2603:10a6:20b:14::17) To CY4PR15MB1223.namprd15.prod.outlook.com (2603:10b6:903:10a::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1f0bc7ee-e6b5-4173-519b-08d614e2573f X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:CY4PR15MB1223; X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1223;3:oasVOySsYLxO7EJUkV4bIkztA0g584GqOpFgTob/MNqPojmIgQgZiurCCW3x977Ht3Cte5TZLmQWkTYXJh4bnnH3bd8xu0/erXsysn1CFBGO7N4SZyXPyv7KKIiFr3CbRDTZzZEAnT+UNjITDXcCK2x+VkwwJf4Kc8S1+eA2k14zpRBphhFD7v/2JH6NHB3AsOeU1WLKQX4/ofZeKLRX22L+D0q4IWQnRclUtMlY10BiiF2qWpOiTaNwFjMR+o+j;25:HLA5K1x07ztjjmzTxrh2N4zVT6PhEaOdTSXGymPMLEn396Nk5Z08DukUwETt2ArJbhU6vMTB2ZUQg77mlaG6fsc37UCm1OnA0hjiqW6leUWz8MRk++XmcBVuXtt+jCho+5tq/2ahiKDO8HMtmxvXhgkXNv6WNnPGWgMxDukDAdpXOVczoJ7OWnOjIMYgkk/kCV07274vCDqBJXYaCLhsdkKFDxNZGvi78MzPY98Zyl0cNiVjgCzATzbn7AG2SlwzBortbz3T6mx/BFA3E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rVKm8OLFZx7G5dA3dvuezhWiO7D5RGUsSClL1ay/4EsEjSvEyczO/rbfDUWoBhklZhfnZimRlK6SuKsn+3BQNJipUqTPluUqAQtMXjDlj4ZJG9GdgbGHqDPQXYRLMC8XPimxuCiYgkRhbSAYAr/P/y X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(93006095)(93001095)(3231311)(11241501184)(944501410)(52105095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201708071742011)(7699050);SRVR:CY4PR15MB1223;BCL:0;PCL:0;RULEID:;SRVR:CY4PR15MB1223; X-Forefront-PRVS: 07880C4932 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(346002)(366004)(396003)(136003)(376002)(39860400002)(199004)(189003)(46003)(11346002)(97736004)(446003)(53416004)(5660300001)(6486002)(7736002)(85782001)(6512007)(9686003)(52396003)(105586002)(305945005)(106356001)(8676002)(476003)(186003)(86362001)(52116002)(53936002)(16526019)(1076002)(6116002)(2616005)(51416003)(36756003)(69596002)(386003)(6506007)(48376002)(33896004)(2351001)(25786009)(47776003)(316002)(50226002)(76176011)(68736007)(50466002)(54906003)(4326008)(16586007)(2906002)(2361001)(486006)(8936002)(39060400002)(478600001)(81156014)(6666003)(81166006)(6916009)(85772001);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR15MB1223;H:vall.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1223;23:/SPP/RJ+y73eGTled43z8kj7QNlQivIDizx3KR9OG+CRXl0PeGhdAB5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k4gQa/ve5GWBDg8rjSlTkyG8+Y4w==;5:jKhAieDN0O2yyguT2yARfhj1NfEikzRQOA9cJuKlovcHVGwI+eDXP3ObEMhuQJiZl79tHTrdLhbuGwkmOknaI6OjUvDUE28Vp0B91a1EX8nvOXsKb1pxB6Ng/Uh4ScKwAm/nuIt0SzzKgzJac6kwym+LmKdC3gJaYMb3X2/bt8A=;7:2m655iS+o99K6GAmMcoXluCadpDNMBWH5TT6BkrQUwsmcm2Mt1qPdDQxq1sQuDVLGL3HYJeBQwKEHs/mpsruTINa2hpGX+FqBseg5mo1egmo3mqk4Dw2FClio4Z7EyNJTzjXnLiRaxPBBOdQv3mu0djNbCNNbaoY6OkjJkqUsF0v7WC8wXW+8zjOIv8x7bggSy/26JoXYiOD01ZSK+oLrJ8vg6AY4JBxRsunTdyRgcf7Je3ccmitFFIfqR3LdGs0 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1223;20:7t1e3VYZlHZZ2sCf3I7K3kfEuSSr70jjpUOLJzYO/XJkEVJBWcXKSSMaRsXLUTgms/v9L69ANO01CSnAMpPSQMcbfuyGg5KtYZm60hz1vGPXbUJatsRrfa8du2dakzVToRlAVcBzeZ63jEf68YC5DlcB6XIwlIGKGXflBLZcd7Q= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2018 16:52:44.8931 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f0bc7ee-e6b5-4173-519b-08d614e2573f X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1223 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-07_08:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe 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 From: Jay Kamat Fix a couple issues with cg_read_strcmp(), to improve correctness of cgroup tests - Fix cg_read_strcmp() always returning 0 for empty "needle" strings - Fix a memory leak in cg_read_strcmp() Fixes: 84092dbcf901 ("selftests: cgroup: add memory controller self-tests") Signed-off-by: Jay Kamat Acked-by: Roman Gushchin --- tools/testing/selftests/cgroup/cgroup_util.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index 1e9e3c470561..8b644ea39725 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -89,17 +89,28 @@ int cg_read(const char *cgroup, const char *control, char *buf, size_t len) int cg_read_strcmp(const char *cgroup, const char *control, const char *expected) { - size_t size = strlen(expected) + 1; + size_t size; char *buf; + int ret; + + /* Handle the case of comparing against empty string */ + if (!expected) + size = 32; + else + size = strlen(expected) + 1; buf = malloc(size); if (!buf) return -1; - if (cg_read(cgroup, control, buf, size)) + if (cg_read(cgroup, control, buf, size)) { + free(buf); return -1; + } - return strcmp(expected, buf); + ret = strcmp(expected, buf); + free(buf); + return ret; } int cg_read_strstr(const char *cgroup, const char *control, const char *needle)