[PATCH v5 1/7] tst_kvercmp: Factor out error handling

Petr Vorel <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
Error check was already on 2 places (and possibly more will be added in
the future).

Signed-off-by: Petr Vorel <[email protected]>
---
Changes v1->v2:
* Use proper name for function (underscore at the end)

 lib/tst_kvercmp.c | 23 +++++++++++++++++------
 lib/tst_test.c    |  6 +-----
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
index 9e1a511aff..27b156c8bc 100644
--- a/lib/tst_kvercmp.c
+++ b/lib/tst_kvercmp.c
@@ -45,7 +45,7 @@ static char *parse_digit(const char *str, int *d)
 	return end;
 }
 
-int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3)
+static int tst_parse_kver_(const char *str_kver, int *v1, int *v2, int *v3)
 {
 	const char *str = str_kver;
 
@@ -81,17 +81,28 @@ int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3)
 	return 0;
 }
 
-int tst_kvcmp(const char *cur_kver, int r1, int r2, int r3)
+int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3)
 {
-	int a1, a2, a3;
-	int testver, currver;
+	int rc;
+
+	rc = tst_parse_kver_(str_kver, v1, v2, v3);
 
-	if (tst_parse_kver(cur_kver, &a1, &a2, &a3)) {
+	if (rc) {
 		tst_resm(TWARN,
 			 "Invalid kernel version %s, expected %%d.%%d.%%d",
-		         cur_kver);
+		         str_kver);
 	}
 
+	return rc;
+}
+
+int tst_kvcmp(const char *cur_kver, int r1, int r2, int r3)
+{
+	int a1, a2, a3;
+	int testver, currver;
+
+	tst_parse_kver(cur_kver, &a1, &a2, &a3);
+
 	testver = (r1 << 20) + (r2 << 10) + r3;
 	currver = (a1 << 20) + (a2 << 10) + a3;
 
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 9c5f2617fe..a147521e9d 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1067,11 +1067,7 @@ static bool check_kver(const char *min_kver, const int brk_nosupp)
 	char *msg;
 	int v1, v2, v3;
 
-	if (tst_parse_kver(min_kver, &v1, &v2, &v3)) {
-		tst_res(TWARN,
-			"Invalid kernel version %s, expected %%d.%%d.%%d",
-			min_kver);
-	}
+	tst_parse_kver(min_kver, &v1, &v2, &v3);
 
 	if (tst_kvercmp(v1, v2, v3) < 0) {
 		msg = "The test requires kernel %s or newer";
-- 
2.55.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.