diff --git a/src/gallium/auxiliary/pipebuffer/pb_cache.c b/src/gallium/auxiliary/pipebuffer/pb_cache.c index ec878202f0825b266e1d862819404a1e31439c80..48ed89a7473edf07423ceb852ec55623d2af0689 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_cache.c +++ b/src/gallium/auxiliary/pipebuffer/pb_cache.c @@ -41,7 +41,7 @@ destroy_buffer_locked(struct pb_cache_entry *entry) struct pb_buffer *buf = entry->buffer; assert(!pipe_is_referenced(&buf->reference)); - if (entry->head.next) { + if (list_is_linked(&entry->head)) { list_del(&entry->head); assert(mgr->num_buffers); --mgr->num_buffers; diff --git a/src/gallium/auxiliary/pipebuffer/pb_slab.c b/src/gallium/auxiliary/pipebuffer/pb_slab.c index d84686961515ff84552868b26c64eab9d4bee871..37f2400dd9b4a8d79d68b5e5d6a9786a53d145be 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_slab.c +++ b/src/gallium/auxiliary/pipebuffer/pb_slab.c @@ -60,7 +60,7 @@ pb_slab_reclaim(struct pb_slabs *slabs, struct pb_slab_entry *entry) slab->num_free++; /* Add slab to the group's list if it isn't already linked. */ - if (!slab->head.next) { + if (!list_is_linked(&slab->head)) { struct pb_slab_group *group = &slabs->groups[entry->group_index]; list_addtail(&slab->head, &group->slabs); } diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c index 249bf82ad35ccb69f86b375d6cd28cac23fc9a23..f2fa323299312d75f6de622826a1f44f1f050d31 100644 --- a/src/gallium/auxiliary/util/u_threaded_context.c +++ b/src/gallium/auxiliary/util/u_threaded_context.c @@ -469,7 +469,7 @@ tc_call_destroy_query(struct pipe_context *pipe, union tc_payload *payload) { struct threaded_query *tq = threaded_query(payload->query); - if (tq->head_unflushed.next) + if (list_is_linked(&tq->head_unflushed)) list_del(&tq->head_unflushed); pipe->destroy_query(pipe, payload->query); @@ -510,7 +510,7 @@ tc_call_end_query(struct pipe_context *pipe, union tc_payload *payload) struct tc_end_query_payload *p = (struct tc_end_query_payload *)payload; struct threaded_query *tq = threaded_query(p->query); - if (!tq->head_unflushed.next) + if (!list_is_linked(&tq->head_unflushed)) list_add(&tq->head_unflushed, &p->tc->unflushed_queries); pipe->end_query(pipe, p->query); @@ -548,7 +548,7 @@ tc_get_query_result(struct pipe_context *_pipe, if (success) { tq->flushed = true; - if (tq->head_unflushed.next) { + if (list_is_linked(&tq->head_unflushed)) { /* This is safe because it can only happen after we sync'd. */ list_del(&tq->head_unflushed); } diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 12c13f43733038fc3f99b3d04748106eed529547..9a67602ac020908b6880ec12de16babcdb877bad 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -206,7 +206,7 @@ find_and_ref_external_bo(struct hash_table *ht, unsigned int key) * we hadn't yet closed it...and then reimported the same BO. If it * is, then remove it since it's now been resurrected. */ - if (bo->head.prev || bo->head.next) + if (list_is_linked(&bo->head)) list_del(&bo->head); iris_bo_reference(bo); diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index df27f05c964758be5f2fdb0206b3ae90d4f0b839..8d12c66227e1b7b5192d7f1ccd33d38e394a879e 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -377,7 +377,7 @@ error: void r600_pipe_shader_destroy(struct pipe_context *ctx UNUSED, struct r600_pipe_shader *shader) { r600_resource_reference(&shader->bo, NULL); - if (shader->shader.bc.cf.next) + if (list_is_linked(&shader->shader.bc.cf)) r600_bytecode_clear(&shader->shader.bc); r600_release_command_buffer(&shader->command_buffer); } diff --git a/src/gallium/drivers/svga/svga_resource_buffer_upload.c b/src/gallium/drivers/svga/svga_resource_buffer_upload.c index 1b1a8077e20c15f030deb75bf4df91681d3f8585..cf85228425e8f95cefb43e4852c43b4da965f341 100644 --- a/src/gallium/drivers/svga/svga_resource_buffer_upload.c +++ b/src/gallium/drivers/svga/svga_resource_buffer_upload.c @@ -730,9 +730,6 @@ svga_buffer_upload_flush(struct svga_context *svga, struct svga_buffer *sbuf) assert(sbuf->head.prev && sbuf->head.next); list_del(&sbuf->head); /* remove from svga->dirty_buffers list */ -#ifdef DEBUG - sbuf->head.next = sbuf->head.prev = NULL; -#endif sbuf->dma.pending = FALSE; sbuf->dma.flags.discard = FALSE; sbuf->dma.flags.unsynchronized = FALSE; diff --git a/src/gallium/frontends/nine/basetexture9.c b/src/gallium/frontends/nine/basetexture9.c index c9ef17c6c6e0cfc44834150f07d680f1cbdb46da..c509a1f46210a1c19f1ca3392fb36e37a2e379ad 100644 --- a/src/gallium/frontends/nine/basetexture9.c +++ b/src/gallium/frontends/nine/basetexture9.c @@ -99,9 +99,9 @@ NineBaseTexture9_dtor( struct NineBaseTexture9 *This ) pipe_sampler_view_reference(&This->view[0], NULL); pipe_sampler_view_reference(&This->view[1], NULL); - if (This->list.prev != NULL && This->list.next != NULL) + if (list_is_linked(&This->list)) list_del(&This->list); - if (This->list2.prev != NULL && This->list2.next != NULL) + if (list_is_linked(&This->list2)) list_del(&This->list2); NineResource9_dtor(&This->base); diff --git a/src/gallium/frontends/nine/buffer9.c b/src/gallium/frontends/nine/buffer9.c index 6c2bc8895da003812b0d5562fea11cce60339f06..ad4e9020f5829555f0d3b049a3d3a8747d59ce2c 100644 --- a/src/gallium/frontends/nine/buffer9.c +++ b/src/gallium/frontends/nine/buffer9.c @@ -161,9 +161,9 @@ NineBuffer9_dtor( struct NineBuffer9 *This ) if (This->base.pool == D3DPOOL_MANAGED) { if (This->managed.data) align_free(This->managed.data); - if (This->managed.list.prev != NULL && This->managed.list.next != NULL) + if (list_is_linked(&This->managed.list)) list_del(&This->managed.list); - if (This->managed.list2.prev != NULL && This->managed.list2.next != NULL) + if (list_is_linked(&This->managed.list2)) list_del(&This->managed.list2); } diff --git a/src/gallium/frontends/omx/vid_enc_common.c b/src/gallium/frontends/omx/vid_enc_common.c index a3b274606cf235991d995aa1e3eabd21c4de39ae..9d64f4358cdf8a47c9a2e6e1909bf38da8a9db8d 100644 --- a/src/gallium/frontends/omx/vid_enc_common.c +++ b/src/gallium/frontends/omx/vid_enc_common.c @@ -34,7 +34,7 @@ void enc_ReleaseTasks(struct list_head *head) { struct encode_task *i, *next; - if (!head || !head->next) + if (!head || !list_is_linked(head)) return; LIST_FOR_EACH_ENTRY_SAFE(i, next, head, list) { diff --git a/src/util/list.h b/src/util/list.h index fdc6fafb1a193532e40b644140be482bd4e4970b..0e71a66a7d544c197ee8145b462005f6af9daa36 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -111,12 +111,20 @@ static inline bool list_is_empty(const struct list_head *list) return list->next == list; } +static inline bool list_is_linked(const struct list_head *list) +{ + /* both must be NULL or both must be not NULL */ + assert((list->prev != NULL) == (list->next != NULL)); + + return list->next != NULL; +} + /** * Returns whether the list has exactly one element. */ static inline bool list_is_singular(const struct list_head *list) { - return list->next != NULL && list->next != list && list->next->next == list; + return list_is_linked(list) && !list_is_empty(list) && list->next->next == list; } static inline unsigned list_length(const struct list_head *list) @@ -153,6 +161,7 @@ static inline void list_splicetail(struct list_head *src, struct list_head *dst) static inline void list_validate(const struct list_head *list) { struct list_head *node; + assert(list_is_linked(list)); assert(list->next->prev == list && list->prev->next == list); for (node = list->next; node != list; node = node->next) assert(node->next->prev == node && node->prev->next == node);