From f27daff0dcd945c60ffbcae7938083db23b52932 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Mon, 31 Mar 2025 12:48:54 +0100
Subject: [PATCH] check-va-api: Guard against VA_STATUS_ERROR_MAX_NUM_EXCEEDED

The documentation implies that vaQuerySurfaceAttributes could
legitimately return VA_STATUS_ERROR_MAX_NUM_EXCEEDED when we query
the number of attributes available, although it seems that in practice
it returns VA_STATUS_SUCCESS. Accept either one.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 helpers/check-va-api.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/helpers/check-va-api.c b/helpers/check-va-api.c
index db1aef16..46a4155e 100644
--- a/helpers/check-va-api.c
+++ b/helpers/check-va-api.c
@@ -212,10 +212,17 @@ create_surfaces (VADisplay va_display,
   int num_formats;
   autofree VAImageFormat *format_list = NULL;
   bool ret = false;
+  VAStatus status;
 
 #define do_vaapi_or_exit(expr) if (! _do_vaapi (#expr, expr)) goto out;
 
-  do_vaapi_or_exit (vaQuerySurfaceAttributes (va_display, config, NULL, &num_attribs));
+  status = vaQuerySurfaceAttributes (va_display, config, NULL, &num_attribs);
+
+  if (status != VA_STATUS_SUCCESS && status != VA_STATUS_ERROR_MAX_NUM_EXCEEDED)
+    {
+      _do_vaapi ("vaQuerySurfaceAttributes", status);
+      goto out;
+    }
 
   attrib_list = xcalloc (num_attribs, sizeof (*attrib_list));
   do_vaapi_or_exit (vaQuerySurfaceAttributes (va_display, config, attrib_list, &num_attribs));
-- 
GitLab