Skip to contentSkip to conversation

app: fix redundant comparison

PATCH In review Min Hu (Connor) 4 participants 5 messages Apr 19, 2021 – Jul 24, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app: fix redundant comparison

The return value of 'rte_eal_cleanup' is always zero, so comparison with zero is redundant.

This patch fixed it by deleting the redundant comparison.

Fixes 67684d1e87b6 ("app/procinfo: call EAL cleanup before exit")
Fixes b68a82425da4 ("app/compress-perf: add performance measurement")
Fixes 5e516c89830a ("app/testpmd: call cleanup on exit")
Fixes 613ce6691c0d ("examples/l3fwd-power: implement proper shutdown")
Fixes 48be180de631 ("eal: move OS common debug functions to single file")
---
 app/pdump/main.c                         | 4 +---
 app/proc-info/main.c                     | 4 +---
 app/test-compress-perf/main.c            | 7 +------
 app/test-pmd/testpmd.c                   | 5 +----
 examples/l3fwd-power/main.c              | 3 +--
 lib/librte_eal/common/eal_common_debug.c | 4 +---
 6 files changed, 6 insertions(+), 21 deletions(-)
app/pdump/main.c +1 -3
index 63bbe65..33523c5 100644
@@ -1014,9 +1014,7 @@ main(int argc, char **argv)
 	/* dump debug stats */
 	print_pdump_stats();
 
-	ret = rte_eal_cleanup();
-	if (ret)
-		printf("Error from rte_eal_cleanup(), %d\n", ret);
+	rte_eal_cleanup();
 
 	return 0;
 }
app/proc-info/main.c +1 -3
index b9587f7..9498490 100644
@@ -1458,9 +1458,7 @@ main(int argc, char **argv)
 	RTE_ETH_FOREACH_DEV(i)
 		rte_eth_dev_close(i);
 
-	ret = rte_eal_cleanup();
-	if (ret)
-		printf("Error from rte_eal_cleanup(), %d\n", ret);
+	rte_eal_cleanup();
 
 	return 0;
 }
app/test-compress-perf/main.c +1 -6
index cc9951a..03ee385 100644
@@ -474,12 +474,7 @@ main(int argc, char **argv)
 		/* fallthrough */
 	case ST_CLEAR:
 	default:
-		i = rte_eal_cleanup();
-		if (i) {
-			RTE_LOG(ERR, USER1,
-				"Error from rte_eal_cleanup(), %d\n", i);
-			ret = i;
-		}
+		rte_eal_cleanup();
 		break;
 	}
 	return ret;
app/test-pmd/testpmd.c +1 -4
index d4be23f..1f8a7b8 100644
@@ -3972,10 +3972,7 @@ main(int argc, char** argv)
 			return 1;
 	}
 
-	ret = rte_eal_cleanup();
-	if (ret != 0)
-		rte_exit(EXIT_FAILURE,
-			 "EAL cleanup failed: %s\n", strerror(-ret));
+	rte_eal_cleanup();
 
 	return EXIT_SUCCESS;
 }
examples/l3fwd-power/main.c +1 -2
index 0af8810..84464d5 100644
@@ -2914,8 +2914,7 @@ main(int argc, char **argv)
 			deinit_power_library())
 		rte_exit(EXIT_FAILURE, "deinit_power_library failed\n");
 
-	if (rte_eal_cleanup() < 0)
-		RTE_LOG(ERR, L3FWD_POWER, "EAL cleanup failed\n");
+	rte_eal_cleanup();
 
 	return 0;
 }
lib/librte_eal/common/eal_common_debug.c +1 -3
index 15418e9..04b1fed 100644
@@ -37,8 +37,6 @@ rte_exit(int exit_code, const char *format, ...)
 	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
 	va_end(ap);
 
-	if (rte_eal_cleanup() != 0)
-		RTE_LOG(CRIT, EAL,
-			"EAL could not release all resources\n");
+	rte_eal_cleanup();
 	exit(exit_code);
 }
Signature · 1 line
2.7.4
#1 lore raw

Hi Connor,

Quoted 105 lines · Min Hu (Connor)

The return value of 'rte_eal_cleanup' is always zero, so comparison with zero is redundant.

This patch fixed it by deleting the redundant comparison.

Fixes 67684d1e87b6 ("app/procinfo: call EAL cleanup before exit")
Fixes b68a82425da4 ("app/compress-perf: add performance measurement")
Fixes 5e516c89830a ("app/testpmd: call cleanup on exit")
Fixes 613ce6691c0d ("examples/l3fwd-power: implement proper shutdown")
Fixes 48be180de631 ("eal: move OS common debug functions to single file")
---
  app/pdump/main.c                         | 4 +---
  app/proc-info/main.c                     | 4 +---
  app/test-compress-perf/main.c            | 7 +------
  app/test-pmd/testpmd.c                   | 5 +----
  examples/l3fwd-power/main.c              | 3 +--
  lib/librte_eal/common/eal_common_debug.c | 4 +---
  6 files changed, 6 insertions(+), 21 deletions(-)
app/pdump/main.c +1 -3
index 63bbe65..33523c5 100644
@@ -1014,9 +1014,7 @@ main(int argc, char **argv)
  	/* dump debug stats */
  	print_pdump_stats();
 
-	ret = rte_eal_cleanup();
-	if (ret)
-		printf("Error from rte_eal_cleanup(), %d\n", ret);
+	rte_eal_cleanup();
 
  	return 0;
  }
app/proc-info/main.c +1 -3
index b9587f7..9498490 100644
@@ -1458,9 +1458,7 @@ main(int argc, char **argv)
  	RTE_ETH_FOREACH_DEV(i)
  		rte_eth_dev_close(i);
 
-	ret = rte_eal_cleanup();
-	if (ret)
-		printf("Error from rte_eal_cleanup(), %d\n", ret);
+	rte_eal_cleanup();
 
  	return 0;
  }
app/test-compress-perf/main.c +1 -6
index cc9951a..03ee385 100644
@@ -474,12 +474,7 @@ main(int argc, char **argv)
  		/* fallthrough */
  	case ST_CLEAR:
  	default:
-		i = rte_eal_cleanup();
-		if (i) {
-			RTE_LOG(ERR, USER1,
-				"Error from rte_eal_cleanup(), %d\n", i);
-			ret = i;
-		}
+		rte_eal_cleanup();
  		break;
  	}
  	return ret;
app/test-pmd/testpmd.c +1 -4
index d4be23f..1f8a7b8 100644
@@ -3972,10 +3972,7 @@ main(int argc, char** argv)
  			return 1;
  	}
 
-	ret = rte_eal_cleanup();
-	if (ret != 0)
-		rte_exit(EXIT_FAILURE,
-			 "EAL cleanup failed: %s\n", strerror(-ret));
+	rte_eal_cleanup();
 
  	return EXIT_SUCCESS;
  }
examples/l3fwd-power/main.c +1 -2
index 0af8810..84464d5 100644
@@ -2914,8 +2914,7 @@ main(int argc, char **argv)
  			deinit_power_library())
  		rte_exit(EXIT_FAILURE, "deinit_power_library failed\n");
 
-	if (rte_eal_cleanup() < 0)
-		RTE_LOG(ERR, L3FWD_POWER, "EAL cleanup failed\n");
+	rte_eal_cleanup();
 
  	return 0;
  }
lib/librte_eal/common/eal_common_debug.c +0 -0
index 15418e9..04b1fed 100644

lib/librte_eal/common/eal_common_debug.c rte_exit(int exit_code, const char *format, ...) · line 42

Quoted 9 lines
lib/librte_eal/common/eal_common_debug.c +1 -3
@@ -37,8 +37,6 @@ rte_exit(int exit_code, const char *format, ...)
  	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
  	va_end(ap);
 
-	if (rte_eal_cleanup() != 0)
-		RTE_LOG(CRIT, EAL,
-			"EAL could not release all resources\n");
+	rte_eal_cleanup();
  	exit(exit_code);
  }

Since the function is defined as "int rte_eal_cleanup(void)" and the documentation says:

 *  - 0 Successfully released all internal EAL resources. *  - -EFAULT There was an error in releasing all resources.

We really should check for non zero values. Just because it's currently coded to only return zero may not hold in the future. The code may change in the future to return non-zero values.

Rgds,
Dave.

#2 lore raw
Quoted 112 lines · David Hunt

Hi Connor,

Quoted 97 lines · Min Hu (Connor)

The return value of 'rte_eal_cleanup' is always zero, so comparison with zero is redundant.

This patch fixed it by deleting the redundant comparison.

Fixes 67684d1e87b6 ("app/procinfo: call EAL cleanup before exit")
Fixes b68a82425da4 ("app/compress-perf: add performance measurement")
Fixes 5e516c89830a ("app/testpmd: call cleanup on exit")
Fixes 613ce6691c0d ("examples/l3fwd-power: implement proper shutdown")
Fixes 48be180de631 ("eal: move OS common debug functions to single file")

---
  app/pdump/main.c                         | 4 +--- app/proc-info/main.c                     | 4 +--- app/test-compress-perf/main.c            | 7 +------ app/test-pmd/testpmd.c                   | 5 +---- examples/l3fwd-power/main.c              | 3 +-- lib/librte_eal/common/eal_common_debug.c | 4 +---

  6 files changed, 6 insertions(+), 21 deletions(-)
app/pdump/main.c +1 -3
index 63bbe65..33523c5 100644
@@ -1014,9 +1014,7 @@ main(int argc, char **argv)
       /* dump debug stats */
       print_pdump_stats();
-    ret = rte_eal_cleanup();
-    if (ret)
-        printf("Error from rte_eal_cleanup(), %d\n", ret);
+    rte_eal_cleanup();
       return 0;
   }
app/proc-info/main.c +1 -3
index b9587f7..9498490 100644
@@ -1458,9 +1458,7 @@ main(int argc, char **argv)
       RTE_ETH_FOREACH_DEV(i)
           rte_eth_dev_close(i);
-    ret = rte_eal_cleanup();
-    if (ret)
-        printf("Error from rte_eal_cleanup(), %d\n", ret);
+    rte_eal_cleanup();
       return 0;
   }
app/test-compress-perf/main.c +0 -0
index cc9951a..03ee385 100644
@@ -474,12 +474,7 @@ main(int argc, char **argv)
           /* fallthrough */

      case ST_CLEAR:
      default:
-        i = rte_eal_cleanup();
-        if (i) {
-            RTE_LOG(ERR, USER1,
-                "Error from rte_eal_cleanup(), %d\n", i); -            ret = i;
-        }
+        rte_eal_cleanup();
          break;
      }
      return ret;

app/test-pmd/testpmd.c +1 -4
index d4be23f..1f8a7b8 100644
@@ -3972,10 +3972,7 @@ main(int argc, char** argv)
               return 1;
       }
-    ret = rte_eal_cleanup();
-    if (ret != 0)
-        rte_exit(EXIT_FAILURE,
-             "EAL cleanup failed: %s\n", strerror(-ret));
+    rte_eal_cleanup();
       return EXIT_SUCCESS;
   }
examples/l3fwd-power/main.c +1 -2
index 0af8810..84464d5 100644
@@ -2914,8 +2914,7 @@ main(int argc, char **argv)
               deinit_power_library())
           rte_exit(EXIT_FAILURE, "deinit_power_library failed\n");
-    if (rte_eal_cleanup() < 0)
-        RTE_LOG(ERR, L3FWD_POWER, "EAL cleanup failed\n");
+    rte_eal_cleanup();
       return 0;
   }
lib/librte_eal/common/eal_common_debug.c +0 -0
index 15418e9..04b1fed 100644

lib/librte_eal/common/eal_common_debug.c rte_exit(int exit_code, const char *format, ...) · line 41

Quoted 8 lines
lib/librte_eal/common/eal_common_debug.c +1 -3
@@ -37,8 +37,6 @@ rte_exit(int exit_code, const char *format, ...)
       rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
       va_end(ap);
-    if (rte_eal_cleanup() != 0)
-        RTE_LOG(CRIT, EAL,
-            "EAL could not release all resources\n");
+    rte_eal_cleanup();
       exit(exit_code);
   }

Since the function is defined as "int rte_eal_cleanup(void)" and the documentation says:

Quoted 4 lines

 *  - 0 Successfully released all internal EAL resources. *  - -EFAULT There was an error in releasing all resources.

We really should check for non zero values. Just because it's currently coded to only return zero may not hold in the future. The code may change in the future to return non-zero values.

+1

I think the patch should be rejected.

#3 lore raw

Agreed, This patch can be rejected, thanks.

Quoted 122 lines · Andrew Rybchenko
Quoted 112 lines · David Hunt

Hi Connor,

Quoted 97 lines · Min Hu (Connor)

The return value of 'rte_eal_cleanup' is always zero, so comparison with zero is redundant.

This patch fixed it by deleting the redundant comparison.

Fixes 67684d1e87b6 ("app/procinfo: call EAL cleanup before exit")
Fixes b68a82425da4 ("app/compress-perf: add performance measurement")
Fixes 5e516c89830a ("app/testpmd: call cleanup on exit")
Fixes 613ce6691c0d ("examples/l3fwd-power: implement proper shutdown")
Fixes 48be180de631 ("eal: move OS common debug functions to single file")

---
  app/pdump/main.c                         | 4 +--- app/proc-info/main.c                     | 4 +--- app/test-compress-perf/main.c            | 7 +------ app/test-pmd/testpmd.c                   | 5 +---- examples/l3fwd-power/main.c              | 3 +-- lib/librte_eal/common/eal_common_debug.c | 4 +---

  6 files changed, 6 insertions(+), 21 deletions(-)
app/pdump/main.c +1 -3
index 63bbe65..33523c5 100644
@@ -1014,9 +1014,7 @@ main(int argc, char **argv)
       /* dump debug stats */
       print_pdump_stats();
-    ret = rte_eal_cleanup();
-    if (ret)
-        printf("Error from rte_eal_cleanup(), %d\n", ret);
+    rte_eal_cleanup();
       return 0;
   }
app/proc-info/main.c +1 -3
index b9587f7..9498490 100644
@@ -1458,9 +1458,7 @@ main(int argc, char **argv)
       RTE_ETH_FOREACH_DEV(i)
           rte_eth_dev_close(i);
-    ret = rte_eal_cleanup();
-    if (ret)
-        printf("Error from rte_eal_cleanup(), %d\n", ret);
+    rte_eal_cleanup();
       return 0;
   }
app/test-compress-perf/main.c +0 -0
index cc9951a..03ee385 100644
@@ -474,12 +474,7 @@ main(int argc, char **argv)
           /* fallthrough */

      case ST_CLEAR:
      default:
-        i = rte_eal_cleanup();
-        if (i) {
-            RTE_LOG(ERR, USER1,
-                "Error from rte_eal_cleanup(), %d\n", i); -            ret = i;
-        }
+        rte_eal_cleanup();
          break;
      }
      return ret;

app/test-pmd/testpmd.c +1 -4
index d4be23f..1f8a7b8 100644
@@ -3972,10 +3972,7 @@ main(int argc, char** argv)
               return 1;
       }
-    ret = rte_eal_cleanup();
-    if (ret != 0)
-        rte_exit(EXIT_FAILURE,
-             "EAL cleanup failed: %s\n", strerror(-ret));
+    rte_eal_cleanup();
       return EXIT_SUCCESS;
   }
examples/l3fwd-power/main.c +1 -2
index 0af8810..84464d5 100644
@@ -2914,8 +2914,7 @@ main(int argc, char **argv)
               deinit_power_library())
           rte_exit(EXIT_FAILURE, "deinit_power_library failed\n");
-    if (rte_eal_cleanup() < 0)
-        RTE_LOG(ERR, L3FWD_POWER, "EAL cleanup failed\n");
+    rte_eal_cleanup();
       return 0;
   }
lib/librte_eal/common/eal_common_debug.c +0 -0
index 15418e9..04b1fed 100644

lib/librte_eal/common/eal_common_debug.c rte_exit(int exit_code, const char *format, ...) · line 41

Quoted 8 lines
lib/librte_eal/common/eal_common_debug.c +1 -3
@@ -37,8 +37,6 @@ rte_exit(int exit_code, const char *format, ...)
       rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
       va_end(ap);
-    if (rte_eal_cleanup() != 0)
-        RTE_LOG(CRIT, EAL,
-            "EAL could not release all resources\n");
+    rte_eal_cleanup();
       exit(exit_code);
   }

Since the function is defined as "int rte_eal_cleanup(void)" and the documentation says:

Quoted 4 lines

  *  - 0 Successfully released all internal EAL resources. *  - -EFAULT There was an error in releasing all resources.

We really should check for non zero values. Just because it's currently coded to only return zero may not hold in the future. The code may change in the future to return non-zero values.

+1

I think the patch should be rejected.
.

#4 lore raw
In reply to Min Hu (Connor)
Quoted 5 lines · On Mon, 19 Apr 2021 20:29:51 +0800 "Min Hu (Connor)" <[email protected]> wrote:

The return value of 'rte_eal_cleanup' is always zero, so comparison with zero is redundant.

This patch fixed it by deleting the redundant comparison.

Quoted 8 lines
Fixes 67684d1e87b6 ("app/procinfo: call EAL cleanup before exit")
Fixes b68a82425da4 ("app/compress-perf: add performance measurement")
Fixes 5e516c89830a ("app/testpmd: call cleanup on exit")
Fixes 613ce6691c0d ("examples/l3fwd-power: implement proper shutdown")
Fixes 48be180de631 ("eal: move OS common debug functions to single file")

Please keep it in testpmd, which should be checking everything.
For the others, the message doesn't add any value to the user and can be removed.