anv: Handle errors properly in anv_i915_query

DRM_IOCTL_I915_QUERY is a multi-query.  The most egregious errors are
returned via the usual ioctl error mechanism but there are also
per-query errors that are indicated by item.length < 0.  We need to
handle those as well.  While we're at it, scrape errno so we can return
a proper integer error.

Fixes: c0d07c838a "anv: Support i915 query (DRM_IOCTL_I915_QUERY)..."
Reviewed-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11770>
(cherry picked from commit b664481ba9)
This commit is contained in:
Jason Ekstrand 2021-07-07 14:21:58 -05:00 committed by Dylan Baker
parent a63d23c4c2
commit bbeb420157
2 changed files with 9 additions and 4 deletions

View file

@ -184,7 +184,7 @@
"description": "anv: Handle errors properly in anv_i915_query",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "c0d07c838a9fcd67e4ae8cf948ced2daa3edf8c6"
},

View file

@ -787,8 +787,13 @@ anv_i915_query(int fd, uint64_t query_id, void *buffer,
};
int ret = intel_ioctl(fd, DRM_IOCTL_I915_QUERY, &args);
if (ret != 0)
return -errno;
else if (item.length < 0)
return item.length;
*buffer_len = item.length;
return ret;
return 0;
}
struct drm_i915_query_engine_info *
@ -796,14 +801,14 @@ anv_gem_get_engine_info(int fd)
{
int32_t length = 0;
int ret = anv_i915_query(fd, DRM_I915_QUERY_ENGINE_INFO, NULL, &length);
if (ret == -1)
if (ret < 0)
return NULL;
struct drm_i915_query_engine_info *info = calloc(1, length);
ret = anv_i915_query(fd, DRM_I915_QUERY_ENGINE_INFO, info, &length);
assert(ret == 0);
if (ret != 0) {
if (ret < 0) {
free(info);
return NULL;
}