diff --git a/src/gallium/drivers/v3d/v3d_screen.c b/src/gallium/drivers/v3d/v3d_screen.c index 5c415eb6b0e..2c491e85467 100644 --- a/src/gallium/drivers/v3d/v3d_screen.c +++ b/src/gallium/drivers/v3d/v3d_screen.c @@ -942,10 +942,13 @@ v3d_screen_create(int fd, const struct pipe_screen_config *config, if (!v3d_get_device_info(screen->fd, &screen->devinfo, &v3d_ioctl)) goto fail; - screen->perfcnt_names = rzalloc_array(screen, char*, screen->devinfo.max_perfcnt); - if (!screen->perfcnt_names) { - fprintf(stderr, "Error allocating performance counters names"); - goto fail; + const uint8_t max_perfcnt = screen->devinfo.max_perfcnt; + if (max_perfcnt) { + screen->perfcnt_names = rzalloc_array(screen, char*, max_perfcnt); + if (!screen->perfcnt_names) { + fprintf(stderr, "Error allocating performance counters names"); + goto fail; + } } driParseConfigFiles(config->options, config->options_info, 0, "v3d", diff --git a/src/gallium/drivers/v3d/v3dx_query_perfcnt.c b/src/gallium/drivers/v3d/v3dx_query_perfcnt.c index 84acbb769da..d627b54d8ce 100644 --- a/src/gallium/drivers/v3d/v3dx_query_perfcnt.c +++ b/src/gallium/drivers/v3d/v3dx_query_perfcnt.c @@ -91,22 +91,24 @@ v3dX(get_driver_query_info_perfcnt)(struct v3d_screen *screen, unsigned index, if (index >= max_perfcnt) return 0; - if (screen->perfcnt_names[index]) { - info->name = screen->perfcnt_names[index]; - } else if (devinfo->max_perfcnt) { - struct drm_v3d_perfmon_get_counter counter = { - .counter = index, - }; - int ret = v3d_ioctl(screen->fd, DRM_IOCTL_V3D_PERFMON_GET_COUNTER, &counter); - if (ret != 0) { - fprintf(stderr, "Failed to get performance counter %d: %s\n", - index, strerror(errno)); - return 0; - } + if (screen->perfcnt_names) { + if (screen->perfcnt_names[index]) { + info->name = screen->perfcnt_names[index]; + } else { + struct drm_v3d_perfmon_get_counter counter = { + .counter = index, + }; + int ret = v3d_ioctl(screen->fd, DRM_IOCTL_V3D_PERFMON_GET_COUNTER, &counter); + if (ret != 0) { + fprintf(stderr, "Failed to get performance counter %d: %s\n", + index, strerror(errno)); + return 0; + } - screen->perfcnt_names[index] = ralloc_strdup(screen->perfcnt_names, - (const char *) counter.name); - info->name = screen->perfcnt_names[index]; + screen->perfcnt_names[index] = ralloc_strdup(screen->perfcnt_names, + (const char *) counter.name); + info->name = screen->perfcnt_names[index]; + } } else { info->name = v3d_performance_counters[index][V3D_PERFCNT_NAME]; }