intel/perf: Use a char array for OA perf query data

drm_i915_query_perf_config::data is an unsized array and declaring a
struct containing an unsized array that isn't at the end is a GNU
extension which trips up Android builds.  Instead, stuff both into a
char array of the appropriate size.  This emulates what you'd normally
do to allocate one of these with malloc only on the stack.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12308>
This commit is contained in:
Jason Ekstrand 2021-08-10 15:09:51 -05:00 committed by Marge Bot
parent c858d30833
commit 279fe1ae6d
1 changed files with 8 additions and 10 deletions

View File

@ -266,22 +266,20 @@ i915_query_perf_config_data(struct intel_perf_config *perf,
int fd, const char *guid,
struct drm_i915_perf_oa_config *config)
{
struct {
struct drm_i915_query_perf_config query;
struct drm_i915_perf_oa_config config;
} item_data;
char data[sizeof(struct drm_i915_query_perf_config) +
sizeof(struct drm_i915_perf_oa_config)] = {};
struct drm_i915_query_perf_config *query = (void *)data;
memset(&item_data, 0, sizeof(item_data));
memcpy(item_data.query.uuid, guid, sizeof(item_data.query.uuid));
memcpy(&item_data.config, config, sizeof(item_data.config));
memcpy(query->uuid, guid, sizeof(query->uuid));
memcpy(query->data, config, sizeof(*config));
int32_t item_length = sizeof(item_data);
int32_t item_length = sizeof(data);
if (intel_i915_query_flags(fd, DRM_I915_QUERY_PERF_CONFIG,
DRM_I915_QUERY_PERF_CONFIG_DATA_FOR_UUID,
&item_data, &item_length))
query, &item_length))
return false;
memcpy(config, &item_data.config, sizeof(item_data.config));
memcpy(config, query->data, sizeof(*config));
return true;
}