Mesa (main): intel/perf: Use a char array for OA perf query data

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 12 00:22:57 UTC 2021


Module: Mesa
Branch: main
Commit: 279fe1ae6db724ac500a49da532dce56d4b8baf2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=279fe1ae6db724ac500a49da532dce56d4b8baf2

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Tue Aug 10 15:09:51 2021 -0500

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 at intel.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12308>

---

 src/intel/perf/intel_perf.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/intel/perf/intel_perf.c b/src/intel/perf/intel_perf.c
index 7c5175ddcba..a4d801bbdf8 100644
--- a/src/intel/perf/intel_perf.c
+++ b/src/intel/perf/intel_perf.c
@@ -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;
 }



More information about the mesa-commit mailing list