Skip to contentSkip to conversation

mdadm.c: fix compile error "switch condition has boolean value"

PATCH Applied Gioh Kim 3 participants 3 messages Mar 30, 2017 MD RAID

lore
Share & tools
lore

Gioh Kim

author
#0 lore raw

PATCH v2 1/1 mdadm.c: fix compile error "switch condition has boolean value"

Remove a boolean expression in switch condition
to prevent compile error of some compilers,
for example, gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2).

---
 mdadm.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mdadm.c +6 -8
index 0f32773..d6b5437 100644
@@ -1965,14 +1965,12 @@ static int misc_list(struct mddev_dev *devlist,
 			rv |= SetAction(dv->devname, c->action);
 			continue;
 		}
-		switch(dv->devname[0] == '/') {
-			case 0:
-				mdfd = open_dev(dv->devname);
-				if (mdfd >= 0)
-					break;
-			case 1:
-				mdfd = open_mddev(dv->devname, 1);  
-		}
+
+		if (dv->devname[0] != '/')
+			mdfd = open_dev(dv->devname);
+		if (dv->devname[0] == '/' || mdfd < 0)
+			mdfd = open_mddev(dv->devname, 1);
+
 		if (mdfd >= 0) {
 			switch(dv->disposition) {
 			case 'R':
Signature · 1 line
2.5.0
#1 lore raw

You can add my acked-by (never done it before, not sure how :-)

Cheers,
Wol

Quoted 35 lines · Gioh Kim

Remove a boolean expression in switch condition
to prevent compile error of some compilers,
for example, gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2).

---
 mdadm.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mdadm.c +6 -8
index 0f32773..d6b5437 100644
@@ -1965,14 +1965,12 @@ static int misc_list(struct mddev_dev *devlist,
 			rv |= SetAction(dv->devname, c->action);
 			continue;
 		}
-		switch(dv->devname[0] == '/') {
-			case 0:
-				mdfd = open_dev(dv->devname);
-				if (mdfd >= 0)
-					break;
-			case 1:
-				mdfd = open_mddev(dv->devname, 1);  
-		}
+
+		if (dv->devname[0] != '/')
+			mdfd = open_dev(dv->devname);
+		if (dv->devname[0] == '/' || mdfd < 0)
+			mdfd = open_mddev(dv->devname, 1);
+
 		if (mdfd >= 0) {
 			switch(dv->disposition) {
 			case 'R':
Applied
#2 lore raw
In reply to Gioh Kim
Quoted 8 lines · Gioh Kim

Remove a boolean expression in switch condition
to prevent compile error of some compilers,
for example, gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2).

---
 mdadm.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Applied!

Thanks,
Jes

Quoted 26 lines
mdadm.c +6 -8
index 0f32773..d6b5437 100644
@@ -1965,14 +1965,12 @@ static int misc_list(struct mddev_dev *devlist,
 			rv |= SetAction(dv->devname, c->action);
 			continue;
 		}
-		switch(dv->devname[0] == '/') {
-			case 0:
-				mdfd = open_dev(dv->devname);
-				if (mdfd >= 0)
-					break;
-			case 1:
-				mdfd = open_mddev(dv->devname, 1);
-		}
+
+		if (dv->devname[0] != '/')
+			mdfd = open_dev(dv->devname);
+		if (dv->devname[0] == '/' || mdfd < 0)
+			mdfd = open_mddev(dv->devname, 1);
+
 		if (mdfd >= 0) {
 			switch(dv->disposition) {
 			case 'R':