From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gustavo Padovan Subject: [RFC v2 2/3] dma-buf/fence-array: add fence_array_teardown() Date: Mon, 27 Jun 2016 16:29:21 -0300 Message-ID: <1467055762-25881-3-git-send-email-gustavo@padovan.org> References: <1467055762-25881-1-git-send-email-gustavo@padovan.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <1467055762-25881-1-git-send-email-gustavo@padovan.org> Sender: linux-kernel-owner@vger.kernel.org To: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, Daniel Stone , Daniel Vetter , Rob Clark , Greg Hackmann , John Harrison , laurent.pinchart@ideasonboard.com, seanpaul@google.com, marcheu@google.com, m.chehab@samsung.com, Sumit Semwal , Maarten Lankhorst , Gustavo Padovan , Chris Wilson , =?UTF-8?q?Christian=20K=C3=B6nig?= List-Id: dri-devel@lists.freedesktop.org =46rom: Gustavo Padovan As the array of fence callbacks held by an active struct fence_array each has a reference to the struct fence_array, when the owner of the fence_array is freed it must dispose of the callback references before it can free the fence_array. This can not happen simply during fence_release() because of the extra references and so we need a new function to run before the final fence_put(). Cc: Chris Wilson Cc: Christian K=C3=B6nig Signed-off-by: Gustavo Padovan --- drivers/dma-buf/fence-array.c | 25 +++++++++++++++++++++++++ include/linux/fence-array.h | 1 + 2 files changed, 26 insertions(+) diff --git a/drivers/dma-buf/fence-array.c b/drivers/dma-buf/fence-arra= y.c index a8731c8..8891357 100644 --- a/drivers/dma-buf/fence-array.c +++ b/drivers/dma-buf/fence-array.c @@ -142,3 +142,28 @@ struct fence_array *fence_array_create(int num_fen= ces, struct fence **fences, return array; } EXPORT_SYMBOL(fence_array_create); + +/** + * fence_array_teardown - Teardown and clean up a fence array + * @array: [in] the fence array to teardown + * + * This function removes callbacks and extra references to the base fe= nce on + * the fence_array for each unsignalled fence in the array. It should = be called + * before calling fence_put() to remove the last reference on a fence_= array, + * otherwise the fence won't be released due to extra references holde= d by the + * the fences that still have signalling enabled. + */ +void fence_array_teardown(struct fence_array *array) +{ + struct fence_array_cb *cb =3D (void *)(&array[1]); + int i; + + for (i =3D 0; i < array->num_fences; i++) { + if (fence_is_signaled(array->fences[i])) + continue; + + fence_remove_callback(array->fences[i], &cb[i].cb); + fence_put(&array->base); + } +} +EXPORT_SYMBOL(fence_array_teardown); diff --git a/include/linux/fence-array.h b/include/linux/fence-array.h index d2e9f40..9f1b923 100644 --- a/include/linux/fence-array.h +++ b/include/linux/fence-array.h @@ -79,5 +79,6 @@ static inline struct fence_array *to_fence_array(stru= ct fence *fence) struct fence_array *fence_array_create(int num_fences, struct fence **= fences, u64 context, unsigned seqno, bool signal_on_any); +void fence_array_teardown(struct fence_array *array); =20 #endif /* __LINUX_FENCE_ARRAY_H */ --=20 2.5.5