[igt-dev] [PATCH i-g-t v3 04/28] i915/perf: Check return value from getparam
Umesh Nerlige Ramappa
umesh.nerlige.ramappa at intel.com
Fri Oct 28 19:52:34 UTC 2022
In some cases getparam could fail. Check return from getparam and fail
early on.
Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa at intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
lib/i915/perf.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/lib/i915/perf.c b/lib/i915/perf.c
index 840d77f6..95e33b3c 100644
--- a/lib/i915/perf.c
+++ b/lib/i915/perf.c
@@ -389,19 +389,16 @@ intel_perf_for_devinfo(uint32_t device_id,
return perf;
}
-static uint32_t
-getparam(int drm_fd, uint32_t param)
+static int
+getparam(int drm_fd, uint32_t param, uint32_t *val)
{
- struct drm_i915_getparam gp;
- int val = -1;
-
- memset(&gp, 0, sizeof(gp));
- gp.param = param;
- gp.value = &val;
+ struct drm_i915_getparam gp;
- perf_ioctl(drm_fd, DRM_IOCTL_I915_GETPARAM, &gp);
+ memset(&gp, 0, sizeof(gp));
+ gp.param = param;
+ gp.value = (int *)val;
- return val;
+ return perf_ioctl(drm_fd, DRM_IOCTL_I915_GETPARAM, &gp);
}
static bool
@@ -517,9 +514,9 @@ open_master_sysfs_dir(int drm_fd)
struct intel_perf *
intel_perf_for_fd(int drm_fd)
{
- uint32_t device_id = getparam(drm_fd, I915_PARAM_CHIPSET_ID);
- uint32_t device_revision = getparam(drm_fd, I915_PARAM_REVISION);
- uint32_t timestamp_frequency = getparam(drm_fd, I915_PARAM_CS_TIMESTAMP_FREQUENCY);
+ uint32_t device_id;
+ uint32_t device_revision;
+ uint32_t timestamp_frequency;
uint64_t gt_min_freq;
uint64_t gt_max_freq;
struct drm_i915_query_topology_info *topology;
@@ -536,6 +533,11 @@ intel_perf_for_fd(int drm_fd)
}
close(sysfs_dir_fd);
+ if (getparam(drm_fd, I915_PARAM_CHIPSET_ID, &device_id) ||
+ getparam(drm_fd, I915_PARAM_REVISION, &device_revision) ||
+ getparam(drm_fd, I915_PARAM_CS_TIMESTAMP_FREQUENCY, ×tamp_frequency))
+ return NULL;
+
topology = query_topology(drm_fd);
if (!topology)
return NULL;
--
2.25.1
More information about the igt-dev
mailing list