[igt-dev] [PATCH i-g-t 03/23] i915/perf: Check return value from getparam

Lionel Landwerlin lionel.g.landwerlin at intel.com
Tue Sep 6 12:52:43 UTC 2022


On 23/08/2022 21:30, Umesh Nerlige Ramappa wrote:
> 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>


Something is odd with the indentation but otherwise :


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 d88835ff..7349a460 100644
> --- a/lib/i915/perf.c
> +++ b/lib/i915/perf.c
> @@ -287,19 +287,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
> @@ -415,9 +412,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;
> @@ -434,6 +431,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, &timestamp_frequency))
> +		return NULL;
> +
>   	topology = query_topology(drm_fd);
>   	if (!topology)
>   		return NULL;




More information about the igt-dev mailing list