rcu.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
To: dave@stgolabs.net, paulmck@kernel.org, josh@joshtriplett.org,
	frederic@kernel.org, neeraj.upadhyay@kernel.org,
	rostedt@goodmis.org
Cc: linux-kernel@vger.kernel.org, rcu@vger.kernel.org,
	Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Subject: [PATCH] rcu/rcutorture: Improve error handling in rcu_torture_fwd_prog_init()
Date: Wed, 10 Sep 2025 14:06:30 +0530	[thread overview]
Message-ID: <20250910083630.3735022-1-kaushlendra.kumar@intel.com> (raw)

Restructure error handling in rcu_torture_fwd_prog_init() to provide
cleaner allocation failure paths. The current code checks both
allocations
in a single condition, making error handling less efficient and clear.

The improved approach:
- Check rfp allocation immediately and return early on failure
- Separately handle fwd_prog_tasks allocation failure with proper
  cleanup
- Remove redundant kfree(fwd_prog_tasks) since it would be NULL on
  failure

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
 kernel/rcu/rcutorture.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 807fbf6123a7..6af0d207adba 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -2995,11 +2995,11 @@ static int __init rcu_torture_fwd_prog_init(void)
 	if (fwd_progress_div <= 0)
 		fwd_progress_div = 4;
 	rfp = kcalloc(fwd_progress, sizeof(*rfp), GFP_KERNEL);
+	if (!rfp)
+		return -ENOMEM;
 	fwd_prog_tasks = kcalloc(fwd_progress, sizeof(*fwd_prog_tasks), GFP_KERNEL);
-	if (!rfp || !fwd_prog_tasks) {
+	if (!fwd_prog_tasks) {
 		kfree(rfp);
-		kfree(fwd_prog_tasks);
-		fwd_prog_tasks = NULL;
 		fwd_progress = 0;
 		return -ENOMEM;
 	}
-- 
2.34.1


             reply	other threads:[~2025-09-10  8:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-10  8:36 Kaushlendra Kumar [this message]
2025-09-10  9:07 ` [PATCH] rcu/rcutorture: Improve error handling in rcu_torture_fwd_prog_init() Markus Elfring
2025-09-10  9:32   ` Kumar, Kaushlendra

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=20250910083630.3735022-1-kaushlendra.kumar@intel.com \
    --to=kaushlendra.kumar@intel.com \
    --cc=dave@stgolabs.net \
    --cc=frederic@kernel.org \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).