Skip to contentSkip to conversation

md: fix a build warning

PATCH Superseded Firo Yang 5 participants 8 messages Jun 10, 2015 – Jun 11, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Firo Yang

author
#0 lore raw

PATCH 1/1 md: fix a build warning

Warning like this:

drivers/md/md.c: In function ‘update_array_info’:
drivers/md/md.c:6394:26: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]

      !mddev->persistent  != info->not_persistent||

I fix it by enclosing !mddev->persistent with parentheses

By the way, I also fixed a line over 80 characters warning outputed by ./scripts/checkpatch.pl

---
 drivers/md/md.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/md/md.c +3 -2
index dd85be9..b420d82 100644
@@ -6391,9 +6391,10 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
 	    mddev->ctime         != info->ctime         ||
 	    mddev->level         != info->level         ||
 /*	    mddev->layout        != info->layout        || */
-	    !mddev->persistent	 != info->not_persistent||
+	    (!mddev->persistent) != info->not_persistent ||
 	    mddev->chunk_sectors != info->chunk_size >> 9 ||
-	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */
+	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT
+		to change */
 	    ((state^info->state) & 0xfffffe00)
 		)
 		return -EINVAL;
Signature · 1 line
2.4.2
#1 lore raw
Quoted 2 lines · Firo Yang

By the way, I also fixed a line over 80 characters warning outputed by ./scripts/checkpatch.pl

Don't do this. It's not on the same line, it's not really related at all.

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6397

Quoted 4 lines
drivers/md/md.c +2 -1
 	    mddev->chunk_sectors != info->chunk_size >> 9 ||
-	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */
+	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT
+		to change */

The new comment style isn't correct.

regards,
dan carpenter

#2 lore raw
In reply to Firo Yang

Am 10.06.2015 17:20, schrieb Firo Yang:

Quoted 22 lines

Warning like this:

drivers/md/md.c: In function ‘update_array_info’:
drivers/md/md.c:6394:26: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]

      !mddev->persistent  != info->not_persistent||

I fix it by enclosing !mddev->persistent with parentheses

By the way, I also fixed a line over 80 characters warning outputed by ./scripts/checkpatch.pl

---
 drivers/md/md.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/md/md.c +0 -0
index dd85be9..b420d82 100644

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6394

Quoted 5 lines
drivers/md/md.c +1 -1
@@ -6391,9 +6391,10 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
 	    mddev->ctime         != info->ctime         ||
 	    mddev->level         != info->level         ||
 /*	    mddev->layout        != info->layout        || */
-	    !mddev->persistent	 != info->not_persistent||
+	    (!mddev->persistent) != info->not_persistent ||

this looks odd,
would it be possible the check for = instead (and drop the !) ? and it someone care for readability: It would be helpful to make some more ifs here.

re,
wh

Quoted 7 lines
drivers/md/md.c +2 -1
 	    mddev->chunk_sectors != info->chunk_size >> 9 ||
-	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */
+	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT
+		to change */
 	    ((state^info->state) & 0xfffffe00)
 		)
 		return -EINVAL;
#3 lore raw
Quoted 20 lines · walter harms

Am 10.06.2015 17:20, schrieb Firo Yang:

Quoted 17 lines

Warning like this:

drivers/md/md.c: In function ‘update_array_info’:
drivers/md/md.c:6394:26: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]

      !mddev->persistent  != info->not_persistent||

I fix it by enclosing !mddev->persistent with parentheses

By the way, I also fixed a line over 80 characters warning outputed by ./scripts/checkpatch.pl

---
 drivers/md/md.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 16 lines

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6394

Quoted 10 lines
drivers/md/md.c +1 -1
index dd85be9..b420d82 100644
@@ -6391,9 +6391,10 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
 	    mddev->ctime         != info->ctime         ||
 	    mddev->level         != info->level         ||
 /*	    mddev->layout        != info->layout        || */
-	    !mddev->persistent	 != info->not_persistent||
+	    (!mddev->persistent) != info->not_persistent ||

this looks odd,
would it be possible the check for == instead (and drop the !) ? and it someone care for readability: It would be helpful to make some more ifs here.

The original issue looks like a false positive. If all of the other cases have no parentheses on the left and use !=, isn't it better to leave the code as is?

julia

Quoted 16 lines

re,
wh

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6400

Quoted 7 lines
drivers/md/md.c +2 -1
 	    mddev->chunk_sectors != info->chunk_size >> 9 ||
-	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */
+	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT
+		to change */
 	    ((state^info->state) & 0xfffffe00)
 		)
 		return -EINVAL;

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Am 10.06.2015 19:36, schrieb Julia Lawall:

Quoted 41 lines · walter harms
Quoted 21 lines

Am 10.06.2015 17:20, schrieb Firo Yang:

Quoted 17 lines

Warning like this:

drivers/md/md.c: In function ‘update_array_info’:
drivers/md/md.c:6394:26: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]

      !mddev->persistent  != info->not_persistent||

I fix it by enclosing !mddev->persistent with parentheses

By the way, I also fixed a line over 80 characters warning outputed by ./scripts/checkpatch.pl

---
 drivers/md/md.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 16 lines

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6394

Quoted 10 lines
drivers/md/md.c +1 -1
index dd85be9..b420d82 100644
@@ -6391,9 +6391,10 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
 	    mddev->ctime         != info->ctime         ||
 	    mddev->level         != info->level         ||
 /*	    mddev->layout        != info->layout        || */
-	    !mddev->persistent	 != info->not_persistent||
+	    (!mddev->persistent) != info->not_persistent ||

this looks odd,
would it be possible the check for = instead (and drop the !) ? and it someone care for readability: It would be helpful to make some more ifs here.

Quoted 4 lines

The original issue looks like a false positive. If all of the other cases have no parentheses on the left and use !=, isn't it better to leave the code as is?

i do not think so, the name indicate persistent/not_persistent devices. Maybe both parties can agree what should be stored, ppl are bad at those not_not things and that is an unnecessary trouble spot.

re,
wh

Quoted 18 lines

julia

Quoted 16 lines

re,
wh

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6400

Quoted 7 lines
drivers/md/md.c +2 -1
 	    mddev->chunk_sectors != info->chunk_size >> 9 ||
-	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */
+	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT
+		to change */
 	    ((state^info->state) & 0xfffffe00)
 		)
 		return -EINVAL;

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to walter harms
Quoted 20 lines · On Wed, 10 Jun 2015 19:32:41 +0200 walter harms <[email protected]> wrote:

Am 10.06.2015 17:20, schrieb Firo Yang:

Quoted 17 lines

Warning like this:

drivers/md/md.c: In function ‘update_array_info’:
drivers/md/md.c:6394:26: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]

      !mddev->persistent  != info->not_persistent||

I fix it by enclosing !mddev->persistent with parentheses

By the way, I also fixed a line over 80 characters warning outputed by ./scripts/checkpatch.pl

---
 drivers/md/md.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 16 lines

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6394

Quoted 10 lines
drivers/md/md.c +1 -1
index dd85be9..b420d82 100644
@@ -6391,9 +6391,10 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
 	    mddev->ctime         != info->ctime         ||
 	    mddev->level         != info->level         ||
 /*	    mddev->layout        != info->layout        || */
-	    !mddev->persistent	 != info->not_persistent||
+	    (!mddev->persistent) != info->not_persistent ||

this looks odd,
would it be possible the check for = instead (and drop the !) ? and it someone care for readability: It would be helpful to make some more ifs here.

The first attempt Firo summited did exactly that. I said no. I like the visual consistency of LHS != RHS.

More 'if's would just waste more vertical space.

Thanks,
NeilBrown

Quoted 11 lines

re,
wh

Quoted 7 lines
drivers/md/md.c +2 -1
 	    mddev->chunk_sectors != info->chunk_size >> 9 ||
-	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */
+	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT
+		to change */
 	    ((state^info->state) & 0xfffffe00)
 		)
 		return -EINVAL;
#5 lore raw
In reply to Julia Lawall
Quoted 41 lines · On Wed, 10 Jun 2015 19:36:43 +0200 (CEST) Julia Lawall <[email protected]>…
Quoted 20 lines · walter harms

Am 10.06.2015 17:20, schrieb Firo Yang:

Quoted 17 lines

Warning like this:

drivers/md/md.c: In function ‘update_array_info’:
drivers/md/md.c:6394:26: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]

      !mddev->persistent  != info->not_persistent||

I fix it by enclosing !mddev->persistent with parentheses

By the way, I also fixed a line over 80 characters warning outputed by ./scripts/checkpatch.pl

---
 drivers/md/md.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 16 lines

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6394

Quoted 10 lines
drivers/md/md.c +1 -1
index dd85be9..b420d82 100644
@@ -6391,9 +6391,10 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
 	    mddev->ctime         != info->ctime         ||
 	    mddev->level         != info->level         ||
 /*	    mddev->layout        != info->layout        || */
-	    !mddev->persistent	 != info->not_persistent||
+	    (!mddev->persistent) != info->not_persistent ||

this looks odd,
would it be possible the check for = instead (and drop the !) ? and it someone care for readability: It would be helpful to make some more ifs here.

Quoted 4 lines

The original issue looks like a false positive. If all of the other cases have no parentheses on the left and use !=, isn't it better to leave the code as is?

Leaving the code as it is would leave at least one compiler generating warnings. I don't like warnings.
So if the compiler can be "fixed" that would be good. But it seems unlikely.

May we could do:

Quoted 1 line
Quoted 1 line

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6395

Quoted 1 line
drivers/md/md.c +1 -0
+	    mddev->persistent != !info->not_persistent ||

That would keep the two "not"s together, avoid the need for parentheses, and probably avoid the compiler warning.
(I think I had it the way it is because it almost reads
" not ...peristent != ... not_persistent"
but that isn't a strong reason)

Firo: Can you confirm that this version doesn't upset the compiler? If if doesn't I'd definitely prefer this one. (and definitely leave out the comment change - just change the code)

Thanks,
NeilBrown

Quoted 18 lines

julia

Quoted 16 lines

re,
wh

drivers/md/md.c static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · line 6400

Quoted 7 lines
drivers/md/md.c +2 -1
 	    mddev->chunk_sectors != info->chunk_size >> 9 ||
-	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */
+	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT
+		to change */
 	    ((state^info->state) & 0xfffffe00)
 		)
 		return -EINVAL;

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
In reply to Firo Yang

Hey Joe,

checkpatch.pl in linux-next is now encouraging people to make unrelated long line fixes like the below patch. Reverting 0b4193c79c83 ('checkpatch: categorize some long line length checks') makes the new checkpatch.pl warning go away.

regards,
dan carpenter

Quoted 41 lines · Firo Yang

Warning like this:

drivers/md/md.c: In function ‘update_array_info’:
drivers/md/md.c:6394:26: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]

      !mddev->persistent  != info->not_persistent||

I fix it by enclosing !mddev->persistent with parentheses

By the way, I also fixed a line over 80 characters warning outputed by ./scripts/checkpatch.pl

---
 drivers/md/md.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/md/md.c +3 -2
index dd85be9..b420d82 100644
@@ -6391,9 +6391,10 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
 	    mddev->ctime         != info->ctime         ||
 	    mddev->level         != info->level         ||
 /*	    mddev->layout        != info->layout        || */
-	    !mddev->persistent	 != info->not_persistent||
+	    (!mddev->persistent) != info->not_persistent ||
 	    mddev->chunk_sectors != info->chunk_size >> 9 ||
-	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT to change */
+	    /* ignore bottom 8 bits of state, and allow SB_BITMAP_PRESENT
+		to change */
 	    ((state^info->state) & 0xfffffe00)
 		)
 		return -EINVAL;
Signature · 6 lines
2.4.2

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html