2007-02-07 18:54:41

by Josh Triplett

[permalink] [raw]
Subject: [PATCH 1/3] rcutorture: Use ARRAY_SIZE macro when appropriate

Replace open-coded array size calculation with standard ARRAY_SIZE macro.

Signed-off-by: Ahmed S. Darwish <[email protected]>
Signed-off-by: Josh Triplett <[email protected]>
---
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);


2007-02-07 18:56:28

by Josh Triplett

[permalink] [raw]
Subject: [PATCH 2/3] rcutorture: style cleanup: avoid != NULL in boolean tests

Signed-off-by: Josh Triplett <[email protected]>
---
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)

2007-02-07 18:58:00

by Josh Triplett

[permalink] [raw]
Subject: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop

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 <[email protected]>
---
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);

2007-02-07 23:57:26

by Richard Knutsson

[permalink] [raw]
Subject: Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop

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 <[email protected]>
> ---
> 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


2007-02-08 00:24:10

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop

On Thu, 08 Feb 2007 00:56:01 +0100
Richard Knutsson <[email protected]> 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 <[email protected]>
> > ---
> > 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",
_

2007-02-08 00:25:49

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop

On Wed, 7 Feb 2007 16:22:28 -0800
Andrew Morton <[email protected]> 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);
_

2007-02-08 01:42:43

by Josh Triplett

[permalink] [raw]
Subject: Re: [PATCH 3/3] rcutorture: Remove redundant assignment to cur_ops in for loop

Andrew Morton wrote:
> On Wed, 7 Feb 2007 16:22:28 -0800
> Andrew Morton <[email protected]> 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 <[email protected]>

- 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);
> _
>
>
>