[Mesa-dev] [PATCH 03/11] i965: Check calloc return value in gather_statistics_results()

Ian Romanick idr at freedesktop.org
Fri Jun 20 16:49:43 PDT 2014


On 06/19/2014 05:24 AM, Juha-Pekka Heikkila wrote:
> Check calloc return value and report on error, also later skip
> results handling if there was no memory to store results to.
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  src/mesa/drivers/dri/i965/brw_performance_monitor.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_performance_monitor.c b/src/mesa/drivers/dri/i965/brw_performance_monitor.c
> index 3f64eae..aeef5b9 100644
> --- a/src/mesa/drivers/dri/i965/brw_performance_monitor.c
> +++ b/src/mesa/drivers/dri/i965/brw_performance_monitor.c
> @@ -610,6 +610,10 @@ gather_statistics_results(struct brw_context *brw,
>        ctx->PerfMonitor.Groups[PIPELINE_STATS_COUNTERS].NumCounters;
>  
>     monitor->pipeline_stats_results = calloc(num_counters, sizeof(uint64_t));
> +   if (monitor->pipeline_stats_results == NULL) {
> +      _mesa_error_no_memory(__func__);
> +      return;
> +   }
>  
>     drm_intel_bo_map(monitor->pipeline_stats_bo, false);
>     uint64_t *start = monitor->pipeline_stats_bo->virtual;
> @@ -1321,7 +1325,8 @@ brw_get_perf_monitor_result(struct gl_context *ctx,
>        if (!monitor->pipeline_stats_results)
>           gather_statistics_results(brw, monitor);
>  

I think I'd rather have

      if (!monitor->pipeline_stats_results)
         return;

here than the check in the loop.

With that change, this patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> -      for (int i = 0; i < num_counters; i++) {
> +      for (int i = 0; i < num_counters
> +           && monitor->pipeline_stats_results != NULL; i++) {
>           if (BITSET_TEST(m->ActiveCounters[PIPELINE_STATS_COUNTERS], i)) {
>              data[offset++] = PIPELINE_STATS_COUNTERS;
>              data[offset++] = i;



More information about the mesa-dev mailing list