Skip to contentSkip to conversation

rcu/rcutorture: Improve error handling in rcu_torture_fwd_prog_init()

PATCH In review Kaushlendra Kumar 2 participants 2 messages Sep 10, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 rcu/rcutorture: Improve error handling in rcu_torture_fwd_prog_init()

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 of allocated resources.
- Remove redundant kfree(fwd_prog_tasks) since it would be NULL on allocation failure.

---
Changes in v3:
- Fixed word wrapping to eliminate orphaned words (runts).
- Removed duplicate marker line in changelog.
Changes in v2:
- Fixed word wrapping in commit message to follow kernel guidelines

 kernel/rcu/rcutorture.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/rcu/rcutorture.c +3 -3
index 807fbf6123a7..6af0d207adba 100644
@@ -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;
 	}
Signature · 1 line
2.34.1
#1 lore raw

…> The improved approach:

Quoted 1 line

- Check rfp allocation immediately and return early on failure.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.17-rc5#n532

Quoted 4 lines

- Separately handle fwd_prog_tasks allocation failure with proper cleanup of allocated resources.
- Remove redundant kfree(fwd_prog_tasks) since it would be NULL on allocation failure.

Would it be cleaner to offer desirable changes by separate update steps?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc5#n81

How do you think about to increase the application of scope-based resource management?

Regards,
Markus