From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07BD8EB64DA for ; Sun, 2 Jul 2023 19:39:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231260AbjGBTjy (ORCPT ); Sun, 2 Jul 2023 15:39:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbjGBTjt (ORCPT ); Sun, 2 Jul 2023 15:39:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F8E910F8; Sun, 2 Jul 2023 12:39:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B6BA960C7A; Sun, 2 Jul 2023 19:39:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DB1AC433C9; Sun, 2 Jul 2023 19:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688326742; bh=zoqRFyKFzbksP21+pdzLOmw6DiAmo5NhTPCpktIbKRY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ukRw6/JPWOXW8adLebCiBverfrRRi4ZtQ8wnVWmJ6SbC4oneCPHou9XybBGs5pczU kHKLYIH/bMvPSGXNV9t+AMWc/JqCuifvE/CLaLB6IMHSod8nUd9iq8xFwiH+EMA66H 3GJ6vlPTrzY53RkLfY7at9UHu0I8zeTOSjKD8Q9xt0RE/ATEa9FMVAn907EVSin6EA BNc3gtTe8GiQi6WDIkBnIjuUxDQq0hbpGe5BSU9zLBM1wdk7QFHRWrV+QnPlcRnM7H bdZgLzKg8QKHnrs2oLvKhrhV18Doxjn4HnPVAcvdcmHU2NrQjODr1+Jto9D3EvDIcF xTqBRfa2h6KoA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ivan Orlov , Muchun Song , Shakeel Butt , Roman Gushchin , Shuah Khan , Sasha Levin , hannes@cmpxchg.org, mhocko@kernel.org, tj@kernel.org, lizefan.x@bytedance.com, shuah@kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 6.3 2/3] selftests: cgroup: Add 'malloc' failures checks in test_memcontrol Date: Sun, 2 Jul 2023 15:38:54 -0400 Message-Id: <20230702193855.1775909-2-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230702193855.1775909-1-sashal@kernel.org> References: <20230702193855.1775909-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.3.11 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ivan Orlov [ Upstream commit c83f320e55a49abd90629f42a72897afd579e0de ] There are several 'malloc' calls in test_memcontrol, which can be unsuccessful. This patch will add 'malloc' failures checking to give more details about test's fail reasons and avoid possible undefined behavior during the future null dereference (like the one in alloc_anon_50M_check_swap function). Signed-off-by: Ivan Orlov Reviewed-by: Muchun Song Acked-by: Shakeel Butt Acked-by: Roman Gushchin Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- tools/testing/selftests/cgroup/test_memcontrol.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index 1e616a8c6a9cf..f4f7c0aef702b 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -98,6 +98,11 @@ static int alloc_anon_50M_check(const char *cgroup, void *arg) int ret = -1; buf = malloc(size); + if (buf == NULL) { + fprintf(stderr, "malloc() failed\n"); + return -1; + } + for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE) *ptr = 0; @@ -211,6 +216,11 @@ static int alloc_anon_noexit(const char *cgroup, void *arg) char *buf, *ptr; buf = malloc(size); + if (buf == NULL) { + fprintf(stderr, "malloc() failed\n"); + return -1; + } + for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE) *ptr = 0; @@ -778,6 +788,11 @@ static int alloc_anon_50M_check_swap(const char *cgroup, void *arg) int ret = -1; buf = malloc(size); + if (buf == NULL) { + fprintf(stderr, "malloc() failed\n"); + return -1; + } + for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE) *ptr = 0; -- 2.39.2