rcu/rcutorture: Improve error handling in rcu_torture_fwd_prog_init()
Subsystems (2)
PATCH v2 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
- Remove redundant kfree(fwd_prog_tasks) since it would be NULL on failure
---
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
@@ -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
Paul E. McKenney
maintainerQuoted 11 lines · Kaushlendra Kumar
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 handlefwd_prog_tasksallocation failure with proper cleanup
- Remove redundantkfree(fwd_prog_tasks)since it would be NULL on failure
First, thank you for your interest in Linux-kernel RCU!
However, you lost me on this one. Please see below.
Quoted 13 lines
Signed-off-by Kaushlendra Kumar <[email protected]>---
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 +0
-0
kernel/rcu/rcutorture.c static int __init rcu_torture_fwd_prog_init(void) · line 2999
Quoted 5 lines
kernel/rcu/rcutorture.c +2
-0@@ -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 ;
Don't we still need to set fwd_progress to zero?
kernel/rcu/rcutorture.c static int __init rcu_torture_fwd_prog_init(void) · line 3000
Quoted 1 line
kernel/rcu/rcutorture.c +0
-0fwd_prog_tasks =kcalloc (fwd_progress,sizeof (*fwd_prog_tasks),GFP_KERNEL );
Although this change does avoid the doomed kcalloc() attempt, why are we optimizing an infrequent failure case?
kernel/rcu/rcutorture.c static int __init rcu_torture_fwd_prog_init(void) · line 3001
Quoted 4 lines
kernel/rcu/rcutorture.c +1
-2-if (!rfp || !fwd_prog_tasks) { +if (!fwd_prog_tasks) {kfree (rfp); -kfree (fwd_prog_tasks);
Invoking kfree() on a NULL pointer is a well-defined no-op.
kernel/rcu/rcutorture.c static int __init rcu_torture_fwd_prog_init(void) · line 3005
Quoted 4 lines
kernel/rcu/rcutorture.c +0
-1- fwd_prog_tasks =NULL ; fwd_progress =0 ;return -ENOMEM ; }
I don't see where this is helping the common-case success path, nor am I seeing need need to optimize this initialization-time-only code path. Adding the zeroing of fwd_progress will result in a net increase in the number of lines of code.
So what am I missing here?
Thanx, Paul