rcutorture: Use ARRAY_SIZE macro when appropriate
PATCH 1/3 rcutorture: Use ARRAY_SIZE macro when appropriate
Replace open-coded array size calculation with standard ARRAY_SIZE macro.
--- kernel/rcutorture.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/rcutorture.c +1 -1
@@ -899,7 +899,7 @@ rcu_torture_init(void)/* Set up the freelist. */ INIT_LIST_HEAD (&rcu_torture_freelist); -for (i =0 ; i <sizeof (rcu_tortures) /sizeof (rcu_tortures[0 ]); i++) { +for (i =0 ; i <ARRAY_SIZE (rcu_tortures); i++) { rcu_tortures[i].rtort_mbtest =0 ;list_add_tail (&rcu_tortures[i].rtort_free, &rcu_torture_freelist);
PATCH 2/3 rcutorture: style cleanup: avoid != NULL in boolean tests
--- kernel/rcutorture.c | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-)
kernel/rcutorture.c +14 -14
@@ -534,7 +534,7 @@ rcu_torture_writer(void *arg) rp->rtort_mbtest =1 ;rcu_assign_pointer (rcu_torture_current, rp);smp_wmb (); -if (old_rp !=NULL ) { +if (old_rp) { i = old_rp->rtort_pipe_count;if (i >RCU_TORTURE_PIPE_LEN ) i =RCU_TORTURE_PIPE_LEN ;
@@ -685,7 +685,7 @@ rcu_torture_printk(char *page) atomic_read(&rcu_torture_wcount[i])); } cnt +=sprintf (&page[cnt],"\n" ); -if (cur_ops->stats !=NULL ) +if (cur_ops->stats) cnt += cur_ops->stats (&page[cnt]);return cnt; }
@@ -749,13 +749,13 @@ static void rcu_torture_shuffle_tasks(void)set_cpus_allowed (current, tmp_mask); -if (reader_tasks !=NULL ) { +if (reader_tasks) {for (i =0 ; i < nrealreaders; i++)if (reader_tasks[i])set_cpus_allowed (reader_tasks[i], tmp_mask); } -if (fakewriter_tasks !=NULL ) { +if (fakewriter_tasks) {for (i =0 ; i < nfakewriters; i++)if (fakewriter_tasks[i])set_cpus_allowed (fakewriter_tasks[i], tmp_mask);
@@ -808,21 +808,21 @@ rcu_torture_cleanup(void)int i; fullstop =1 ; -if (shuffler_task !=NULL ) { +if (shuffler_task) {VERBOSE_PRINTK_STRING ("Stopping rcu_torture_shuffle task" );kthread_stop (shuffler_task); } shuffler_task =NULL ; -if (writer_task !=NULL ) { +if (writer_task) {VERBOSE_PRINTK_STRING ("Stopping rcu_torture_writer task" );kthread_stop (writer_task); } writer_task =NULL ; -if (reader_tasks !=NULL ) { +if (reader_tasks) {for (i =0 ; i < nrealreaders; i++) { -if (reader_tasks[i] !=NULL ) { +if (reader_tasks[i]) {VERBOSE_PRINTK_STRING ("Stopping rcu_torture_reader task" );kthread_stop (reader_tasks[i]);
@@ -834,9 +834,9 @@ rcu_torture_cleanup(void) } rcu_torture_current =NULL ; -if (fakewriter_tasks !=NULL ) { +if (fakewriter_tasks) {for (i =0 ; i < nfakewriters; i++) { -if (fakewriter_tasks[i] !=NULL ) { +if (fakewriter_tasks[i]) {VERBOSE_PRINTK_STRING ("Stopping rcu_torture_fakewriter task" );kthread_stop (fakewriter_tasks[i]);
@@ -847,7 +847,7 @@ rcu_torture_cleanup(void) fakewriter_tasks =NULL ; } -if (stats_task !=NULL ) { +if (stats_task) {VERBOSE_PRINTK_STRING ("Stopping rcu_torture_stats task" );kthread_stop (stats_task); }
@@ -858,7 +858,7 @@ rcu_torture_cleanup(void)rcu_torture_stats_print ();/* -After- the stats thread is stopped! */ -if (cur_ops->cleanup !=NULL ) +if (cur_ops->cleanup) cur_ops->cleanup ();if (atomic_read (&n_rcu_torture_error))rcu_torture_print_module_parms ("End of test: FAILURE" );
@@ -875,7 +875,7 @@ rcu_torture_init(void)/* Process args and tell the world that the torturer is on the job. */ -for (i =0 ; cur_ops = torture_ops[i], cur_ops !=NULL ; i++) { +for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++) { cur_ops = torture_ops[i];if (strcmp (torture_type, cur_ops->name) ==0 ) {break ;
@@ -886,7 +886,7 @@ rcu_torture_init(void) torture_type);return (-EINVAL ); } -if (cur_ops->init !=NULL ) +if (cur_ops->init) cur_ops->init ();/* no "goto unwind" prior to this point!!! */ if (nreaders >=0 )
PATCH 3/3 rcutorture: Remove redundant assignment to cur_ops in for loop
In reply to Josh TriplettThe for loop in rcutorture_init uses the conditioncur_ops = torture_ops[i], cur_ops
but then makes the same assignment to cur_ops inside the loop. Remove the redundant assignment inside the loop, and remove now-unnecessary braces.
--- kernel/rcutorture.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
kernel/rcutorture.c +2 -5
@@ -875,12 +875,9 @@ rcu_torture_init(void)/* Process args and tell the world that the torturer is on the job. */ -for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++) { - cur_ops = torture_ops[i]; -if (strcmp (torture_type, cur_ops->name) ==0 ) { +for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++) +if (strcmp (torture_type, cur_ops->name) ==0 )break ; - } - }if (cur_ops ==NULL ) {printk (KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n" , torture_type);
Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop
Quoted 15 lines · Josh Triplett
The for loop in
rcutorture_inituses the conditioncur_ops= torture_ops[i],cur_ops
but then makes the same assignment tocur_opsinside the loop. Remove the redundant assignment inside the loop, and remove now-unnecessary braces.Signed-off-by Josh Triplett <[email protected]>--- kernel/rcutorture.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)kernel/rcutorture.c +0
-0
kernel/rcutorture.c rcu_torture_init(void) · line 879
Quoted 8 lines
kernel/rcutorture.c +1
-3@@ -875,12 +875,9 @@ rcu_torture_init(void)/* Process args and tell the world that the torturer is on the job. */ -for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++) { - cur_ops = torture_ops[i]; -if (strcmp (torture_type, cur_ops->name) ==0 ) { +for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++)
May be tired right now, but wouldn't it be more logical with:
for (i = 0; cur_ops = torture_ops[i], i++)
Right now it seems to have two conditions for cur_ops.
Just my 2cent
Richard Knutsson
Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop
Quoted 26 lines · On Thu, 08 Feb 2007 00:56:01 +0100 Richard Knutsson <[email protected]>…
Quoted 15 lines · Josh Triplett
The for loop in
rcutorture_inituses the conditioncur_ops= torture_ops[i],cur_ops
but then makes the same assignment tocur_opsinside the loop. Remove the redundant assignment inside the loop, and remove now-unnecessary braces.Signed-off-by Josh Triplett <[email protected]>--- kernel/rcutorture.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)kernel/rcutorture.c +0
-0kernel/rcutorture.c rcu_torture_init(void) · line 879
Quoted 8 lines
kernel/rcutorture.c +1
-3@@ -875,12 +875,9 @@ rcu_torture_init(void)/* Process args and tell the world that the torturer is on the job. */ -for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++) { - cur_ops = torture_ops[i]; -if (strcmp (torture_type, cur_ops->name) ==0 ) { +for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++)May be tired right now, but wouldn't it be more logical with:
Quoted 4 lines
for (i = 0;
cur_ops= torture_ops[i], i++)Right now it seems to have two conditions for
cur_ops.
I suspect we can do better than that...
kernel/rcutorture.c renamed from kernel/rcutorture.c~rcutorture-remove-redundant-assignment-to-cur_ops-in +5 -8
@@ -569,10 +569,6 @@ static struct rcu_torture_ops sched_ops .name = "sched" }; -static struct rcu_torture_ops *torture_ops[] = - { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, - &srcu_ops, &qrcu_ops, &sched_ops,NULL }; -/* * RCU torture writer kthread. Repeatedly substitutes a new structure * for that pointed to by rcu_torture_current, freeing the old structure
@@ -939,14 +935,15 @@ rcu_torture_init(void)int i;int cpu;int firsterr =0 ; +static struct rcu_torture_ops *torture_ops[] = + { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, + &srcu_ops, &qrcu_ops, &sched_ops, };/* Process args and tell the world that the torturer is on the job. */ - -for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++) { +for (i =0 ; i <ARRAY_SIZE (torture_ops); i++) { cur_ops = torture_ops[i]; -if (strcmp (torture_type, cur_ops->name) ==0 ) { +if (strcmp (torture_type, cur_ops->name) ==0 )break ; - } }if (cur_ops ==NULL ) { printk(KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n",
_
Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop
Quoted 1 line · On Wed, 7 Feb 2007 16:22:28 -0800 Andrew Morton <[email protected]>…
I suspect we can do better than that...
err,,
kernel/rcutorture.c renamed from kernel/rcutorture.c~rcutorture-remove-redundant-assignment-to-cur_ops-in +6 -9
@@ -569,10 +569,6 @@ static struct rcu_torture_ops sched_ops .name = "sched" }; -static struct rcu_torture_ops *torture_ops[] = - { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, - &srcu_ops, &qrcu_ops, &sched_ops,NULL }; -/* * RCU torture writer kthread. Repeatedly substitutes a new structure * for that pointed to by rcu_torture_current, freeing the old structure
@@ -939,16 +935,17 @@ rcu_torture_init(void)int i;int cpu;int firsterr =0 ; +static struct rcu_torture_ops *torture_ops[] = + { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, + &srcu_ops, &qrcu_ops, &sched_ops, };/* Process args and tell the world that the torturer is on the job. */ - -for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++) { +for (i =0 ; i <ARRAY_SIZE (torture_ops); i++) { cur_ops = torture_ops[i]; -if (strcmp (torture_type, cur_ops->name) ==0 ) { +if (strcmp (torture_type, cur_ops->name) ==0 )break ; - } } -if (cur_ops ==NULL ) { +if (i ==ARRAY_SIZE (torture_ops)) {printk (KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n" , torture_type);return (-EINVAL );
_
Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop
Quoted 3 lines · Andrew Morton
Quoted 1 line · On Wed, 7 Feb 2007 16:22:28 -0800 Andrew Morton <[email protected]>…
I suspect we can do better than that...
[...]
Much better; please go ahead and replace my patch with this one.
- Josh Triplett
Quoted 40 lines
kernel/rcutorture.c renamed from kernel/rcutorture.c~rcutorture-remove-redundant-assignment-to-cur_ops-in +6
-9@@ -569,10 +569,6 @@ static struct rcu_torture_ops sched_ops .name = "sched" }; -static struct rcu_torture_ops *torture_ops[] = - { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, - &srcu_ops, &qrcu_ops, &sched_ops,NULL }; -/* * RCU torture writer kthread. Repeatedly substitutes a new structure * for that pointed to by rcu_torture_current, freeing the old structure @@ -939,16 +935,17 @@ rcu_torture_init(void)int i;int cpu;int firsterr =0 ; +static struct rcu_torture_ops *torture_ops[] = + { &rcu_ops, &rcu_sync_ops, &rcu_bh_ops, &rcu_bh_sync_ops, + &srcu_ops, &qrcu_ops, &sched_ops, };/* Process args and tell the world that the torturer is on the job. */ - -for (i =0 ; cur_ops = torture_ops[i], cur_ops; i++) { +for (i =0 ; i <ARRAY_SIZE (torture_ops); i++) { cur_ops = torture_ops[i]; -if (strcmp (torture_type, cur_ops->name) ==0 ) { +if (strcmp (torture_type, cur_ops->name) ==0 )break ; - } } -if (cur_ops ==NULL ) { +if (i ==ARRAY_SIZE (torture_ops)) {printk (KERN_ALERT "rcutorture: invalid torture type: \"%s\"\n" , torture_type);return (-EINVAL );_