From: Iago Toral Quiroga Date: Fri, 3 Mar 2017 09:57:17 +0000 (+0100) Subject: anv: do not try to ref/unref NULL shaders X-Git-Tag: upstream/17.1.0~1331 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=88b539c4a03e3d680c297b60cc7a58a9e05fa0d6;p=platform%2Fupstream%2Fmesa.git anv: do not try to ref/unref NULL shaders This situation can happen if we failed to allocate memory for the shader. v2: - We shouldn't see NULL shaders in anv_shader_bin_ref so we should not check for that (Jason). Make sure that callers don't attempt to call this function with a NULL shader and assert that this never happens (Iago). v3: - All callers to anv_shader_bin_unref seem to check for NULL before calling, so just assert that it is not NULL (Topi) Reviewed-by: Topi Pohjolainen --- diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c index 0b677a4..cdd8215 100644 --- a/src/intel/vulkan/anv_pipeline_cache.c +++ b/src/intel/vulkan/anv_pipeline_cache.c @@ -308,7 +308,8 @@ anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache, pthread_mutex_unlock(&cache->mutex); /* We increment refcount before handing it to the caller */ - anv_shader_bin_ref(bin); + if (bin) + anv_shader_bin_ref(bin); return bin; } else { @@ -546,6 +547,8 @@ VkResult anv_MergePipelineCaches( struct hash_entry *entry; hash_table_foreach(src->cache, entry) { struct anv_shader_bin *bin = entry->data; + assert(bin); + if (_mesa_hash_table_search(dst->cache, bin->key)) continue; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 7682bfc..eec1cd6 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1556,14 +1556,14 @@ anv_shader_bin_destroy(struct anv_device *device, struct anv_shader_bin *shader) static inline void anv_shader_bin_ref(struct anv_shader_bin *shader) { - assert(shader->ref_cnt >= 1); + assert(shader && shader->ref_cnt >= 1); __sync_fetch_and_add(&shader->ref_cnt, 1); } static inline void anv_shader_bin_unref(struct anv_device *device, struct anv_shader_bin *shader) { - assert(shader->ref_cnt >= 1); + assert(shader && shader->ref_cnt >= 1); if (__sync_fetch_and_add(&shader->ref_cnt, -1) == 1) anv_shader_bin_destroy(device, shader); }