linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: kernel-janitors@vger.kernel.org, linux-kselftest@vger.kernel.org,
	cgroups@vger.kernel.org, linux-mm@kvack.org,
	Jay Kamat <jgkamat@fb.com>, Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Shakeel Butt <shakeelb@google.com>, Shuah Khan <shuah@kernel.org>,
	Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>
Cc: cocci@inria.fr, LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] selftests: cgroup: Fix exception handling in test_memcg_oom_group_score_events()
Date: Sat, 25 Mar 2023 19:30:21 +0100	[thread overview]
Message-ID: <c383bdca-6f0d-4a75-e788-e1920faa0a62@web.de> (raw)
In-Reply-To: <f9303bdc-b1a7-be5e-56c6-dfa8232b8b55@web.de>

Date: Sat, 25 Mar 2023 19:11:13 +0100

The label “cleanup” was used to jump to another pointer check despite of
the detail in the implementation of the function
“test_memcg_oom_group_score_events” that it was determined already
that a corresponding variable contained a null pointer.

1. Thus return directly after a call of the function “cg_name” failed.

2. Use an additional label.

3. Delete a questionable check.


This issue was detected by using the Coccinelle software.

Fixes: a987785dcd6c8ae2915460582aebd6481c81eb67 ("Add tests for memory.oom.group")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 tools/testing/selftests/cgroup/test_memcontrol.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
index f4f7c0aef702..afcd1752413e 100644
--- a/tools/testing/selftests/cgroup/test_memcontrol.c
+++ b/tools/testing/selftests/cgroup/test_memcontrol.c
@@ -1242,12 +1242,11 @@ static int test_memcg_oom_group_score_events(const char *root)
 	int safe_pid;

 	memcg = cg_name(root, "memcg_test_0");
-
 	if (!memcg)
-		goto cleanup;
+		return ret;

 	if (cg_create(memcg))
-		goto cleanup;
+		goto free_cg;

 	if (cg_write(memcg, "memory.max", "50M"))
 		goto cleanup;
@@ -1275,8 +1274,8 @@ static int test_memcg_oom_group_score_events(const char *root)
 	ret = KSFT_PASS;

 cleanup:
-	if (memcg)
-		cg_destroy(memcg);
+	cg_destroy(memcg);
+free_cg:
 	free(memcg);

 	return ret;
--
2.40.0



  parent reply	other threads:[~2023-03-25 18:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <f9303bdc-b1a7-be5e-56c6-dfa8232b8b55@web.de>
2023-03-23 17:30 ` [PATCH] mm/mempolicy: Fix exception handling in shared_policy_replace() Markus Elfring
2023-03-24 17:30   ` Vlastimil Babka
2023-03-24 18:03     ` Markus Elfring
2023-03-25 18:30 ` Markus Elfring [this message]
2023-03-25 19:24   ` [PATCH] selftests: cgroup: Fix exception handling in test_memcg_oom_group_score_events() Lorenzo Stoakes
2023-03-26  8:15     ` Markus Elfring
2023-03-26 21:39       ` David Vernet
2023-03-27  5:56         ` Markus Elfring
2023-03-27  9:13           ` David Vernet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c383bdca-6f0d-4a75-e788-e1920faa0a62@web.de \
    --to=markus.elfring@web.de \
    --cc=cgroups@vger.kernel.org \
    --cc=cocci@inria.fr \
    --cc=hannes@cmpxchg.org \
    --cc=jgkamat@fb.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizefan.x@bytedance.com \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeelb@google.com \
    --cc=shuah@kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox