* [PATCH 1/3] rcutorture: Use ARRAY_SIZE macro when appropriate @ 2007-02-07 18:54 Josh Triplett 2007-02-07 18:56 ` [PATCH 2/3] rcutorture: style cleanup: avoid != NULL in boolean tests Josh Triplett 2007-02-07 18:57 ` [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop Josh Triplett 0 siblings, 2 replies; 7+ messages in thread From: Josh Triplett @ 2007-02-07 18:54 UTC (permalink / raw) To: Andrew Morton; +Cc: Ahmed S. Darwish, linux-kernel Replace open-coded array size calculation with standard ARRAY_SIZE macro. Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com> Signed-off-by: Josh Triplett <josh@kernel.org> --- kernel/rcutorture.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c index 482b11f..97c2277 100644 --- a/kernel/rcutorture.c +++ b/kernel/rcutorture.c @@ -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); ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] rcutorture: style cleanup: avoid != NULL in boolean tests 2007-02-07 18:54 [PATCH 1/3] rcutorture: Use ARRAY_SIZE macro when appropriate Josh Triplett @ 2007-02-07 18:56 ` Josh Triplett 2007-02-07 18:57 ` [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop Josh Triplett 1 sibling, 0 replies; 7+ messages in thread From: Josh Triplett @ 2007-02-07 18:56 UTC (permalink / raw) To: Andrew Morton; +Cc: linux-kernel Signed-off-by: Josh Triplett <josh@kernel.org> --- kernel/rcutorture.c | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-) diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c index 97c2277..0c7bf0c 100644 --- a/kernel/rcutorture.c +++ b/kernel/rcutorture.c @@ -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) ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop 2007-02-07 18:54 [PATCH 1/3] rcutorture: Use ARRAY_SIZE macro when appropriate Josh Triplett 2007-02-07 18:56 ` [PATCH 2/3] rcutorture: style cleanup: avoid != NULL in boolean tests Josh Triplett @ 2007-02-07 18:57 ` Josh Triplett 2007-02-07 23:56 ` Richard Knutsson 1 sibling, 1 reply; 7+ messages in thread From: Josh Triplett @ 2007-02-07 18:57 UTC (permalink / raw) To: Andrew Morton; +Cc: linux-kernel The for loop in rcutorture_init uses the condition cur_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. Signed-off-by: Josh Triplett <josh@kernel.org> --- kernel/rcutorture.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-) diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c index 0c7bf0c..7258bcb 100644 --- a/kernel/rcutorture.c +++ b/kernel/rcutorture.c @@ -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); ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop 2007-02-07 18:57 ` [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop Josh Triplett @ 2007-02-07 23:56 ` Richard Knutsson 2007-02-08 0:22 ` Andrew Morton 0 siblings, 1 reply; 7+ messages in thread From: Richard Knutsson @ 2007-02-07 23:56 UTC (permalink / raw) To: Josh Triplett; +Cc: Andrew Morton, linux-kernel Josh Triplett wrote: > The for loop in rcutorture_init uses the condition > cur_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. > > Signed-off-by: Josh Triplett <josh@kernel.org> > --- > kernel/rcutorture.c | 7 ++----- > 1 files changed, 2 insertions(+), 5 deletions(-) > > diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c > index 0c7bf0c..7258bcb 100644 > --- a/kernel/rcutorture.c > +++ b/kernel/rcutorture.c > @@ -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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop 2007-02-07 23:56 ` Richard Knutsson @ 2007-02-08 0:22 ` Andrew Morton 2007-02-08 0:24 ` Andrew Morton 0 siblings, 1 reply; 7+ messages in thread From: Andrew Morton @ 2007-02-08 0:22 UTC (permalink / raw) To: Richard Knutsson; +Cc: Josh Triplett, linux-kernel, Paul E. McKenney On Thu, 08 Feb 2007 00:56:01 +0100 Richard Knutsson <ricknu-0@student.ltu.se> wrote: > Josh Triplett wrote: > > The for loop in rcutorture_init uses the condition > > cur_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. > > > > Signed-off-by: Josh Triplett <josh@kernel.org> > > --- > > kernel/rcutorture.c | 7 ++----- > > 1 files changed, 2 insertions(+), 5 deletions(-) > > > > diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c > > index 0c7bf0c..7258bcb 100644 > > --- a/kernel/rcutorture.c > > +++ b/kernel/rcutorture.c > > @@ -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. > I suspect we can do better than that... --- a/kernel/rcutorture.c~rcutorture-remove-redundant-assignment-to-cur_ops-in +++ a/kernel/rcutorture.c @@ -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", _ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop 2007-02-08 0:22 ` Andrew Morton @ 2007-02-08 0:24 ` Andrew Morton 2007-02-08 1:42 ` Josh Triplett 0 siblings, 1 reply; 7+ messages in thread From: Andrew Morton @ 2007-02-08 0:24 UTC (permalink / raw) To: Richard Knutsson, Josh Triplett, linux-kernel, Paul E. McKenney On Wed, 7 Feb 2007 16:22:28 -0800 Andrew Morton <akpm@linux-foundation.org> wrote: > I suspect we can do better than that... err,, --- a/kernel/rcutorture.c~rcutorture-remove-redundant-assignment-to-cur_ops-in +++ a/kernel/rcutorture.c @@ -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); _ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop 2007-02-08 0:24 ` Andrew Morton @ 2007-02-08 1:42 ` Josh Triplett 0 siblings, 0 replies; 7+ messages in thread From: Josh Triplett @ 2007-02-08 1:42 UTC (permalink / raw) To: Andrew Morton; +Cc: Richard Knutsson, linux-kernel, Paul E. McKenney Andrew Morton wrote: > On Wed, 7 Feb 2007 16:22:28 -0800 > Andrew Morton <akpm@linux-foundation.org> wrote: >> I suspect we can do better than that... [...] Much better; please go ahead and replace my patch with this one. Signed-off-by: Josh Triplett <josh@kernel.org> - Josh Triplett > --- a/kernel/rcutorture.c~rcutorture-remove-redundant-assignment-to-cur_ops-in > +++ a/kernel/rcutorture.c > @@ -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); > _ > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-02-08 1:42 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-02-07 18:54 [PATCH 1/3] rcutorture: Use ARRAY_SIZE macro when appropriate Josh Triplett 2007-02-07 18:56 ` [PATCH 2/3] rcutorture: style cleanup: avoid != NULL in boolean tests Josh Triplett 2007-02-07 18:57 ` [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop Josh Triplett 2007-02-07 23:56 ` Richard Knutsson 2007-02-08 0:22 ` Andrew Morton 2007-02-08 0:24 ` Andrew Morton 2007-02-08 1:42 ` Josh Triplett
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox