Message ID | 20211115152029.22552-1-rpalethorpe@suse.com |
---|---|
State | Accepted |
Headers | show |
Series | [1/2] lib: Cache kernel_bits value | expand |
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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;
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(-)