Re: [PATCH] md: make the code more readable in the for-loop

2016-05-08 Thread Shaohua Li
On Sun, May 08, 2016 at 08:56:55PM +0800, Tiezhu Yang wrote:
> This patch modifies raid1.c, raid10.c and raid5.c
> to make the code more readable in the for-loop
> and also fixes the scripts/checkpatch.pl error:
> ERROR: trailing statements should be on next line.
> 
> Signed-off-by: Tiezhu Yang 
> @@ -3573,7 +3573,8 @@ static void handle_stripe_dirtying(struct r5conf *conf,
>   pr_debug("force RCW rmw_level=%u, recovery_cp=%llu 
> sh->sector=%llu\n",
>conf->rmw_level, (unsigned long long)recovery_cp,
>(unsigned long long)sh->sector);
> - } else for (i = disks; i--; ) {
> + } else
> + for (i = disks - 1; i >= 0; i--) {
>   /* would I have to read this buffer for read_modify_write */
>   struct r5dev *dev = >dev[i];
>   if ((dev->towrite || i == sh->pd_idx || i == sh->qd_idx) &&

Applied. I move the for statement to be in a {} of else statement.


[PATCH] md: make the code more readable in the for-loop

2016-05-08 Thread Tiezhu Yang
This patch modifies raid1.c, raid10.c and raid5.c
to make the code more readable in the for-loop
and also fixes the scripts/checkpatch.pl error:
ERROR: trailing statements should be on next line.

Signed-off-by: Tiezhu Yang 
---
 drivers/md/raid1.c  |  6 +++---
 drivers/md/raid10.c |  2 +-
 drivers/md/raid5.c  | 59 +++--
 3 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index a7f2b9c..760de56 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -109,7 +109,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
/*
 * Allocate bios : 1 for reading, n-1 for writing
 */
-   for (j = pi->raid_disks ; j-- ; ) {
+   for (j = pi->raid_disks - 1; j >= 0; j--) {
bio = bio_kmalloc(gfp_flags, RESYNC_PAGES);
if (!bio)
goto out_free_bio;
@@ -166,7 +166,7 @@ static void r1buf_pool_free(void *__r1_bio, void *data)
struct r1bio *r1bio = __r1_bio;
 
for (i = 0; i < RESYNC_PAGES; i++)
-   for (j = pi->raid_disks; j-- ;) {
+   for (j = pi->raid_disks - 1; j >= 0; j--) {
if (j == 0 ||
r1bio->bios[j]->bi_io_vec[i].bv_page !=
r1bio->bios[0]->bi_io_vec[i].bv_page)
@@ -1976,7 +1976,7 @@ static void process_checks(struct r1bio *r1_bio)
sbio->bi_error = 0;
 
if (!error) {
-   for (j = vcnt; j-- ; ) {
+   for (j = vcnt - 1; j >= 0; j--) {
struct page *p, *s;
p = pbio->bi_io_vec[j].bv_page;
s = sbio->bi_io_vec[j].bv_page;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 84e24e6..52f1e07 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -157,7 +157,7 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
/*
 * Allocate bios.
 */
-   for (j = nalloc ; j-- ; ) {
+   for (j = nalloc - 1; j >= 0; j--) {
bio = bio_kmalloc(gfp_flags, RESYNC_PAGES);
if (!bio)
goto out_free_bio;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 4d31b23..db978ab 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -536,7 +536,7 @@ retry:
stripe_set_idx(sector, conf, previous, sh);
sh->state = 0;
 
-   for (i = sh->disks; i--; ) {
+   for (i = sh->disks - 1; i >= 0; i--) {
struct r5dev *dev = >dev[i];
 
if (dev->toread || dev->read || dev->towrite || dev->written ||
@@ -890,7 +890,7 @@ static void ops_run_io(struct stripe_head *sh, struct 
stripe_head_state *s)
 
if (r5l_write_stripe(conf->log, sh) == 0)
return;
-   for (i = disks; i--; ) {
+   for (i = disks - 1; i >= 0; i--) {
int rw;
int replace_only = 0;
struct bio *bi, *rbi;
@@ -1175,7 +1175,7 @@ static void ops_complete_biofill(void *stripe_head_ref)
(unsigned long long)sh->sector);
 
/* clear completed biofills */
-   for (i = sh->disks; i--; ) {
+   for (i = sh->disks - 1; i >= 0; i--) {
struct r5dev *dev = >dev[i];
 
/* acknowledge completion of a biofill operation */
@@ -1216,7 +1216,7 @@ static void ops_run_biofill(struct stripe_head *sh)
pr_debug("%s: stripe %llu\n", __func__,
(unsigned long long)sh->sector);
 
-   for (i = sh->disks; i--; ) {
+   for (i = sh->disks - 1; i >= 0; i--) {
struct r5dev *dev = >dev[i];
if (test_bit(R5_Wantfill, >flags)) {
struct bio *rbi;
@@ -1307,7 +1307,7 @@ ops_run_compute5(struct stripe_head *sh, struct 
raid5_percpu *percpu)
__func__, (unsigned long long)sh->sector, target);
BUG_ON(!test_bit(R5_Wantcompute, >flags));
 
-   for (i = disks; i--; )
+   for (i = disks - 1; i >= 0; i--)
if (i != target)
xor_srcs[count++] = sh->dev[i].page;
 
@@ -1407,7 +1407,7 @@ ops_run_compute6_1(struct stripe_head *sh, struct 
raid5_percpu *percpu)
} else {
/* Compute any data- or p-drive using XOR */
count = 0;
-   for (i = disks; i-- ; ) {
+   for (i = disks - 1; i >= 0; i--) {
if (i == target || i == qd_idx)
continue;
blocks[count++] = sh->dev[i].page;
@@ -1492,7 +1492,7 @@ ops_run_compute6_2(struct stripe_head *sh, struct 
raid5_percpu *percpu)
data_target = target;
 
count = 0;
-   for (i = disks; i-- ; ) {
+   for (i = disks - 1; i >= 0; i--) {