From patchwork Fri Sep 7 21:34:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jay Kamat X-Patchwork-Id: 10592555 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 4D56E6CB for ; Fri, 7 Sep 2018 21:35:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DC682B6BD for ; Fri, 7 Sep 2018 21:35:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31D252B6C5; Fri, 7 Sep 2018 21:35:09 +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 8E4A22B6BD for ; Fri, 7 Sep 2018 21:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729519AbeIHCR4 (ORCPT ); Fri, 7 Sep 2018 22:17:56 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:45088 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728060AbeIHCRz (ORCPT ); Fri, 7 Sep 2018 22:17:55 -0400 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w87LYmWZ020102; Fri, 7 Sep 2018 14:35:00 -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=9gr3Rbo11zoyW0Xs3bAyGP8QsHlFdH6LdNsN1G9NhRM=; b=RSBXlDy+s2ICqJD//aqnVRzmIDB8NNboZAgHlRY9r1uCcL87MCjq/e0BzAaspQf5vZhC yOW5VBw5uzuMfumi/o1QZVbJbefof68Zu/kPN/8ex1S9g856IiunuYt1AAjHoUxggoRD g5SWXOjoykxeQObq/YNiQ6SJR/M/QVFr8DA= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2mc1b3g072-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 07 Sep 2018 14:35:00 -0700 Received: from NAM05-BY2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.24) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 7 Sep 2018 17:34:58 -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=9gr3Rbo11zoyW0Xs3bAyGP8QsHlFdH6LdNsN1G9NhRM=; b=YhpWIYBt5zJ5bVkanhwivdSN2qOTagXkmBm0ePMy7C5sJfuSdwZSEgISJiShcl9/hJ3+RWJdTcWWEyDF81obRuR6gMoLOZ2MI3QXtjc9uOsRwldnkj+GM7j1R+ORv4GfxdtUmgUtNRIhkVxDDScgFJiNns2JmpudFmuMB8Kz6uY= Received: from vall.thefacebook.com (2620:10d:c090:200::7:36ec) by MWHPR15MB1230.namprd15.prod.outlook.com (2603:10b6:320:23::20) 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 21:34:55 +0000 From: To: CC: , Roman Gushchin , Tejun Heo , , , , Subject: [PATCH v3 1/2] Fix cg_read_strcmp() Date: Fri, 7 Sep 2018 14:34:04 -0700 Message-ID: <20180907213405.31574-2-jgkamat@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180907213405.31574-1-jgkamat@fb.com> References: <20180907164924.13789-1-jgkamat@fb.com> <20180907213405.31574-1-jgkamat@fb.com> MIME-Version: 1.0 X-Originating-IP: [2620:10d:c090:200::7:36ec] X-ClientProxiedBy: BN6PR18CA0017.namprd18.prod.outlook.com (2603:10b6:404:121::27) To MWHPR15MB1230.namprd15.prod.outlook.com (2603:10b6:320:23::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e2037575-4b80-451c-3940-08d61509c1a9 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:MWHPR15MB1230; X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1230;3:kP8DpJipedoPsY5lciG6SJ+OleGQfV3KZ4PyhOFlshk/OeQ4vU7kW7Ztq8ZW25fCHh7QFKWZVCR7rIxQr4McY2PIJoCR1AKZ+O2GKPM3lqgQurcSOIEbRNmxQpb2yrVouo5THQtxCiI1FP9nO/7YtlXcfsMmC8GQ/RIPia0xWu20bI5DwMkjLlOJeDWcVDY7wHR27cZVOLuNKuQJGvPs9WaMYgpSE2KSr8XHCmv0n38yDA61+HeiV0l2jBIy5aUF;25:Sm0qvhG94vw+7+v7ATJhJmJPMczitdTs66cOm3fmAah/jA9IuzTGWPH6UPgMqli8sEYGqsGmsMuxxIWe0mThsbFBhVypyN/X7VzoMuh+ks70hHGC+iWIs8yrCJVLoZ05Uzs/A83XGuXuJQzbOZtTmN5tsTdt9ZE/qNF/dukWtEg6tE6JoIt2pyhYc+YzVLNmtmWlyRtqsP++LhGfsXfcpR4dH/Hn3ps3q4CLPRpZnJkpDExIQp7fnc/nDjl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YhMnGJ4gDq+o631mTbaPZAKhD1mNaqiXDoTq3X7SEGMwzTw1BDF2L4VXqwZ+zecO8h4BQIq15gfjPXKKPitU6N0wIuCtDZzbgzYxWv18gVWtewuPWuzIhfyBx7zQAmFwjp7ENX39r9DOuUobwz7RlhmF3q/WR3d 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)(8121501046)(5005006)(823301075)(93006095)(93001095)(3002001)(10201501046)(3231311)(11241501184)(944501410)(52105095)(149027)(150027)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699050);SRVR:MWHPR15MB1230;BCL:0;PCL:0;RULEID:;SRVR:MWHPR15MB1230; X-Forefront-PRVS: 07880C4932 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(136003)(396003)(376002)(346002)(189003)(199004)(446003)(105586002)(11346002)(53416004)(25786009)(69596002)(52396003)(76176011)(97736004)(52116002)(16526019)(51416003)(85782001)(186003)(486006)(4326008)(47776003)(478600001)(54906003)(1076002)(16586007)(6506007)(316002)(386003)(6116002)(2351001)(39060400002)(106356001)(50226002)(476003)(6486002)(2616005)(5660300001)(36756003)(81156014)(7736002)(305945005)(9686003)(6512007)(2361001)(50466002)(53936002)(81166006)(8676002)(33896004)(6666003)(48376002)(46003)(86362001)(6916009)(2906002)(68736007)(8936002)(85772001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR15MB1230;H:vall.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1230;23:ncA5r26CIsTXz8y0qEKvGTV6RJ4xgshtTF176Bg8J4g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VmvR+ctIPNjDhbvEe6CbQlgq8zFqTd0ZaBPDxqEAQthetJmJq+3zj9tBZld2zonXe3Kf6+ShA==;5:yiRc66T/Qqyu+o/4/P8IbBzl6laKujSFV3Kbggqpe1l0e0EQpPew8ufZqImLwj4fstvIJfRZ4FmYXCwhy5RlSY2PUgSW5h1+Co1mgZb/TIqD1tTdU1R+vTLoNvTUtVGq5BMOJcsLhnlsxdraQLImPK6ggjurMkTM3OOp5oxF0oo=;7:e8KvatPm60adHGSHXANXp0Wo3BlcmKCjh3q5+iVdpeJrUbBJ+PoJhfOI7+TvpJ7vz1tb4HWZDbulRQZ1uos8zakTJyQLljSH6mft16K+tPHzkXkx+ZQwRcyJ6nsC/N02aYuZFJhiSOuVJwzA81PUFudniLCKBs9TvQlFVSJECRoabh+op1ag2LODfy2XJa6oJhez61lR79a/1DgMjUjc8ZAkBtGTYwtzAie5D3NwX6Kj6g6T1hIY68XJUO9Pw5Im SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1230;20:PygjbWEmXt2C4aU4zcKbtlC7hvesncytTyNuo8y9UMWUMgqv61aVX7O1PW9aBl/4jtmxaSGpFwHdR9Y7cRJFv3JZjVXgJTk418XCgzCn/99m6586OeJvude46KOaUHKvZURhuyDudhdOoAoKEA6YvSanwSExrfmnTTcienXXkd4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2018 21:34:55.0881 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2037575-4b80-451c-3940-08d61509c1a9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1230 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-07_11:,, 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. Previously, this function read to a size = 1 buffer when comparing against empty strings, which would lead to cg_read_strcmp() comparing two empty 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)