[LTP] [PATCH v4 7/9] tst_kvercmp: Factor out 2 kernels integer comparison

Petr Vorel <[email protected]>
Newsgroups it.linux.lists.ltp
Message-ID <[email protected]>
Factor out 2 kernels integer comparison into tst_kver_cmp().

This will be heavily used in metaparse.c (speedup of metadata
generation) in the next commit.

Signed-off-by: Petr Vorel <[email protected]>
---
New in v4.

 include/tst_kvercmp.h | 12 ++++++++++++
 lib/tst_kvercmp.c     | 16 +++++++++++-----
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/include/tst_kvercmp.h b/include/tst_kvercmp.h
index 26e8f8e3c1..73353e82a5 100644
--- a/include/tst_kvercmp.h
+++ b/include/tst_kvercmp.h
@@ -7,6 +7,18 @@
 #ifndef TST_KVERCMP_H__
 #define TST_KVERCMP_H__
 
+/**
+ * tst_kver_cmp() - Compare two kernel versions, versions passed by 3 integers.
+ *
+ * @a1: First kernel major version.
+ * @a2: First kernel minor version.
+ * @a3: First kernel patch level.
+ * @b1: Second kernel major version.
+ * @b2: Second kernel minor  version.
+ * @b3: Second kernel patch level.
+ */
+int tst_kver_cmp(int a1, int a2, int a3, int b1, int b2, int b3);
+
 /**
  * tst_kvcmp() - Compare given kernel version with kernel in string.
  *
diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
index c0714073d4..11b06189a9 100644
--- a/lib/tst_kvercmp.c
+++ b/lib/tst_kvercmp.c
@@ -96,17 +96,23 @@ int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3)
 	return rc;
 }
 
+int tst_kver_cmp(int a1, int a2, int a3, int b1, int b2, int b3)
+{
+	int aver, bver;
+
+	aver = (a1 << 20) + (a2 << 10) + a3;
+	bver = (b1 << 20) + (b2 << 10) + b3;
+
+	return aver - bver;
+}
+
 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;
-
-	return currver - testver;
+	return tst_kver_cmp(a1, a2, a3, r1, r2, r3);
 }
 
 int tst_kvercmp(int r1, int r2, int r3)
-- 
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.