From patchwork Sun May 22 14:18:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12858355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DFF0C433F5 for ; Sun, 22 May 2022 21:24:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABC6A8D0007; Sun, 22 May 2022 17:24:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A45488D0006; Sun, 22 May 2022 17:24:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90E868D0007; Sun, 22 May 2022 17:24:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 79E418D0006 for ; Sun, 22 May 2022 17:24:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id BE7A11206DD for ; Sun, 22 May 2022 14:18:59 +0000 (UTC) X-FDA: 79493585598.23.63AB99F Received: from smtp.smtpout.orange.fr (smtp01.smtpout.orange.fr [80.12.242.123]) by imf09.hostedemail.com (Postfix) with ESMTP id 77F6A140009 for ; Sun, 22 May 2022 14:18:47 +0000 (UTC) Received: from pop-os.home ([86.243.180.246]) by smtp.orange.fr with ESMTPA id smQ0ncTUqeg3psmQ1nn8Nq; Sun, 22 May 2022 16:18:57 +0200 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sun, 22 May 2022 16:18:57 +0200 X-ME-IP: 86.243.180.246 From: Christophe JAILLET To: dan.carpenter@oracle.com, Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Tejun Heo , Zefan Li , Shuah Khan , David Vernet , Andrew Morton Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [PATCH] cgroup: Fix an error handling path in alloc_pagecache_max_30M() Date: Sun, 22 May 2022 16:18:51 +0200 Message-Id: <628312312eb40e0e39463a2c06415fde5295c716.1653229120.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of christophe.jaillet@wanadoo.fr designates 80.12.242.123 as permitted sender) smtp.mailfrom=christophe.jaillet@wanadoo.fr X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 77F6A140009 X-Stat-Signature: mc4np1in9isypk3zxd7i3ipncdzq7y1z X-HE-Tag: 1653229127-268266 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000036, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If the first goto is taken, 'fd' is not opened yet (and is un-initialized). So a direct return is safer. Fixes: c1a31a2f7a9c ("cgroup: fix racy check in alloc_pagecache_max_30M() helper function") Signed-off-by: Christophe JAILLET Acked-by: David Vernet Acked-by: Muchun Song --- tools/testing/selftests/cgroup/test_memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index c3d0d5f7b19c..8833359556f3 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -448,7 +448,7 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg) high = cg_read_long(cgroup, "memory.high"); max = cg_read_long(cgroup, "memory.max"); if (high != MB(30) && max != MB(30)) - goto cleanup; + return -1; fd = get_temp_fd(); if (fd < 0)