From 3260cc87998708a0a8bf952291cb3f2790144e4f Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 12 Jul 2021 13:21:15 +0100 Subject: [PATCH] Use cached context version if available If the backend initialized the private iio_context fields .major, .minor and .git_tag, use them instead of issuing a call to the backend's .get_version() callback. Signed-off-by: Paul Cercueil --- context.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/context.c b/context.c index cbd5c665e..fc91d494e 100644 --- a/context.c +++ b/context.c @@ -355,6 +355,17 @@ int iio_context_init(struct iio_context *ctx) int iio_context_get_version(const struct iio_context *ctx, unsigned int *major, unsigned int *minor, char git_tag[8]) { + if (ctx->git_tag) { + if (major) + *major = ctx->major; + if (minor) + *minor = ctx->minor; + if (git_tag) + iio_strlcpy(git_tag, ctx->git_tag, 8); + + return 0; + } + if (ctx->ops->get_version) return ctx->ops->get_version(ctx, major, minor, git_tag);