Skip to contentSkip to conversation

test: fix up dead code bugs

PATCH Superseded Jeff Moyer 2 participants 6 messages Nov 12, 2019 – Nov 13, 2019 io_uring

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 test: fix up dead code bugs

Coverity pointed out some dead code. Fix it.

test/fsync.c +4 -4
index e6e0898..3c67190 100644
@@ -96,14 +96,14 @@ static int test_barrier_fsync(struct io_uring *ring)
 	io_uring_sqe_set_flags(sqe, IOSQE_IO_DRAIN);
 
 	ret = io_uring_submit(ring);
-	if (ret < 5) {
-		printf("Submitted only %d\n", ret);
-		goto err;
-	} else if (ret < 0) {
+	if (ret < 0) {
 		printf("sqe submit failed\n");
 		if (ret == EINVAL)
 			printf("kernel may not support barrier fsync yet\n");
 		goto err;
+	} else if (ret < 0) {
+		printf("Submitted only %d\n", ret);
+		goto err;
 	}
 
 	for (i = 0; i < 5; i++) {
test/nop.c +4 -4
index 1373695..4b072fc 100644
@@ -62,12 +62,12 @@ static int test_barrier_nop(struct io_uring *ring)
 	}
 
 	ret = io_uring_submit(ring);
-	if (ret < 8) {
-		printf("Submitted only %d\n", ret);
-		goto err;
-	} else if (ret < 0) {
+	if (ret < 0) {
 		printf("sqe submit failed: %d\n", ret);
 		goto err;
+	} else if (ret < 8) {
+		printf("Submitted only %d\n", ret);
+		goto err;
 	}
 
 	for (i = 0; i < 8; i++) {
test/stdout.c +4 -4
index 7b64c8c..b12d75c 100644
@@ -28,12 +28,12 @@ static int test_pipe_io(struct io_uring *ring)
 	io_uring_prep_writev(sqe, STDOUT_FILENO, &vecs, 1, 0);
 
 	ret = io_uring_submit(ring);
-	if (ret < 1) {
-		printf("Submitted only %d\n", ret);
-		goto err;
-	} else if (ret < 0) {
+	if (ret < 0) {
 		printf("sqe submit failed: %d\n", ret);
 		goto err;
+	} else if (ret < 1) {
+		printf("Submitted only %d\n", ret);
+		goto err;
 	}
 
 	ret = io_uring_wait_cqe(ring, &cqe);
maintainer
#1 lore raw
Quoted 15 lines · Jeff Moyer

Coverity pointed out some dead code. Fix it.

test/fsync.c +0 -3
index e6e0898..3c67190 100644
@@ -96,14 +96,14 @@ static int test_barrier_fsync(struct io_uring *ring)
  	io_uring_sqe_set_flags(sqe, IOSQE_IO_DRAIN);
 
  	ret = io_uring_submit(ring);
-	if (ret < 5) {
-		printf("Submitted only %d\n", ret);
-		goto err;

test/fsync.c static int test_barrier_fsync(struct io_uring *ring) · line 107

Quoted 10 lines
test/fsync.c +4 -1
-	} else if (ret < 0) {
+	if (ret < 0) {
  		printf("sqe submit failed\n");
  		if (ret == EINVAL)
  			printf("kernel may not support barrier fsync yet\n");
  		goto err;
+	} else if (ret < 0) {
+		printf("Submitted only %d\n", ret);
+		goto err;
  	}

Looks like you're adding new dead code :-)

Signature · 1 line
Jens Axboe
author
#2 lore raw
Quoted 12 lines · Jens Axboe
Quoted 11 lines · Jeff Moyer

Coverity pointed out some dead code. Fix it.

test/fsync.c +0 -0
index e6e0898..3c67190 100644
@@ -96,14 +96,14 @@ static int test_barrier_fsync(struct io_uring *ring)
  	io_uring_sqe_set_flags(sqe, IOSQE_IO_DRAIN);
 
Quoted 16 lines
Quoted 4 lines
test/fsync.c +0 -3
  	ret = io_uring_submit(ring);
-	if (ret < 5) {
-		printf("Submitted only %d\n", ret);
-		goto err;

test/fsync.c static int test_barrier_fsync(struct io_uring *ring) · line 107

Quoted 10 lines
test/fsync.c +4 -1
-	} else if (ret < 0) {
+	if (ret < 0) {
  		printf("sqe submit failed\n");
  		if (ret == EINVAL)
  			printf("kernel may not support barrier fsync yet\n");
  		goto err;
+	} else if (ret < 0) {
+		printf("Submitted only %d\n", ret);
+		goto err;
  	}

Looks like you're adding new dead code :-)

Oops! I'll fix that up.

-Jeff

author
#3 lore raw

PATCH v2 1/1 test: fix up dead code bugs

In reply to Jeff Moyer

Coverity pointed out some dead code. Fix it.

---
v2: Don't re-introduce dead-code! (Jens Axboe)

test/fsync.c +4 -4
index e6e0898..1a1890e 100644
@@ -96,14 +96,14 @@ static int test_barrier_fsync(struct io_uring *ring)
 	io_uring_sqe_set_flags(sqe, IOSQE_IO_DRAIN);
 
 	ret = io_uring_submit(ring);
-	if (ret < 5) {
-		printf("Submitted only %d\n", ret);
-		goto err;
-	} else if (ret < 0) {
+	if (ret < 0) {
 		printf("sqe submit failed\n");
 		if (ret == EINVAL)
 			printf("kernel may not support barrier fsync yet\n");
 		goto err;
+	} else if (ret < 5) {
+		printf("Submitted only %d\n", ret);
+		goto err;
 	}
 
 	for (i = 0; i < 5; i++) {
test/nop.c +4 -4
index 1373695..4b072fc 100644
@@ -62,12 +62,12 @@ static int test_barrier_nop(struct io_uring *ring)
 	}
 
 	ret = io_uring_submit(ring);
-	if (ret < 8) {
-		printf("Submitted only %d\n", ret);
-		goto err;
-	} else if (ret < 0) {
+	if (ret < 0) {
 		printf("sqe submit failed: %d\n", ret);
 		goto err;
+	} else if (ret < 8) {
+		printf("Submitted only %d\n", ret);
+		goto err;
 	}
 
 	for (i = 0; i < 8; i++) {
test/stdout.c +4 -4
index 7b64c8c..b12d75c 100644
@@ -28,12 +28,12 @@ static int test_pipe_io(struct io_uring *ring)
 	io_uring_prep_writev(sqe, STDOUT_FILENO, &vecs, 1, 0);
 
 	ret = io_uring_submit(ring);
-	if (ret < 1) {
-		printf("Submitted only %d\n", ret);
-		goto err;
-	} else if (ret < 0) {
+	if (ret < 0) {
 		printf("sqe submit failed: %d\n", ret);
 		goto err;
+	} else if (ret < 1) {
+		printf("Submitted only %d\n", ret);
+		goto err;
 	}
 
 	ret = io_uring_wait_cqe(ring, &cqe);
maintainer
#4 lore raw
Quoted 6 lines · Jeff Moyer

Coverity pointed out some dead code. Fix it.

---
v2: Don't re-introduce dead-code! (Jens Axboe)

That looks better - thanks, applied. BTW, totally gave away that you didn't run the tests after writing the patch, that's a black mark.

Signature · 1 line
Jens Axboe
author
#5 lore raw
Quoted 10 lines · Jens Axboe
Quoted 6 lines · Jeff Moyer

Coverity pointed out some dead code. Fix it.

---
v2: Don't re-introduce dead-code! (Jens Axboe)

That looks better - thanks, applied. BTW, totally gave away that you didn't run the tests after writing the patch, that's a black mark.

Yeah, sorry. I usually am more disciplined. I'll do better.

-Jeff