diff mbox series

[1/2] lib: Cache kernel_bits value

Message ID 20211115152029.22552-1-rpalethorpe@suse.com
State Accepted
Headers show
Series [1/2] lib: Cache kernel_bits value | expand

Commit Message

Richard Palethorpe Nov. 15, 2021, 3:20 p.m. UTC
This is primarily to avoid printing the uname info two or more
times. Which is increasingly likely with using tst_kernel_bits in
other library functions. Also with features like test variants where
setup may be run multiple times.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 lib/tst_kernel.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Cyril Hrubis Nov. 15, 2021, 4:01 p.m. UTC | #1
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
diff mbox series

Patch

diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
index c908bb04c..6db85bff0 100644
--- a/lib/tst_kernel.c
+++ b/lib/tst_kernel.c
@@ -37,7 +37,12 @@  static int get_kernel_bits_from_uname(struct utsname *buf)
 int tst_kernel_bits(void)
 {
 	struct utsname buf;
-	int kernel_bits = get_kernel_bits_from_uname(&buf);
+	static int kernel_bits;
+
+	if (kernel_bits)
+		return kernel_bits;
+
+	kernel_bits = get_kernel_bits_from_uname(&buf);
 
 	if (kernel_bits == -1)
 		return -1;