From patchwork Mon Jun 27 19:29:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9201299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B426D6075F for ; Mon, 27 Jun 2016 19:30:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1A7E285BA for ; Mon, 27 Jun 2016 19:30:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9647F285BD; Mon, 27 Jun 2016 19:30:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D53B285BA for ; Mon, 27 Jun 2016 19:30:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A87066E36A; Mon, 27 Jun 2016 19:30:02 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-f195.google.com (mail-qk0-f195.google.com [209.85.220.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id D87896E36A for ; Mon, 27 Jun 2016 19:29:51 +0000 (UTC) Received: by mail-qk0-f195.google.com with SMTP id n132so3089001qka.0 for ; Mon, 27 Jun 2016 12:29:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mrGZyydKCy8fwNRveX+RnvnV/AMZWE5LZYCE/omhMHQ=; b=GQzueZ6pBl2tEMUj9Xe5SITkokhaspOsAhNxokqShM4f5Ij/HrdZJuk0szbDlaKE0n 6SL1pXz28W3j/j0f7N9sMaqma7wS3OxDHGm5E1drNPMFFZNujR62MSHHYJMJiPXxikhM z4r1kCNI00DQ1vmkKwLJA5EgOu1Q/1QimvUhE7DjXwamYG7MQ7Oj+X334V+QOsjhAjum C9amJoUizV6Auodr6dC4xKCBKFn04D0+2b+7akwk37+1OMui9SQXlrtlHTUZoypJJRYu 38Daw4GsMbdWXYpPiSehNLKjAp9f2eJwSoyeJX0gXeJNauZ/yYzlksB1ZrjQ3voHXJPV 9HJw== X-Gm-Message-State: ALyK8tJ5ZEl24kwP8To198CWI4WrBPQF3l10JDIRq2l+r9bBCey33od+TVtuTrnu+LkmGA== X-Received: by 10.129.74.86 with SMTP id x83mr12167260ywa.38.1467055790509; Mon, 27 Jun 2016 12:29:50 -0700 (PDT) Received: from jade.localdomain ([189.61.225.79]) by smtp.gmail.com with ESMTPSA id u82sm5838687ywa.44.2016.06.27.12.29.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jun 2016 12:29:49 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org 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> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1467055762-25881-1-git-send-email-gustavo@padovan.org> References: <1467055762-25881-1-git-send-email-gustavo@padovan.org> MIME-Version: 1.0 Cc: marcheu@google.com, Daniel Stone , seanpaul@google.com, =?UTF-8?q?Christian=20K=C3=B6nig?= , Daniel Vetter , linux-kernel@vger.kernel.org, laurent.pinchart@ideasonboard.com, Gustavo Padovan , John Harrison , m.chehab@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: 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önig 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-array.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_fences, 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 fence 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 holded by the + * the fences that still have signalling enabled. + */ +void fence_array_teardown(struct fence_array *array) +{ + struct fence_array_cb *cb = (void *)(&array[1]); + int i; + + for (i = 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(struct 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); #endif /* __LINUX_FENCE_ARRAY_H */