From patchwork Mon Jul 4 23:57:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9213237 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 F287B6086B for ; Mon, 4 Jul 2016 23:57:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFC5A28790 for ; Mon, 4 Jul 2016 23:57:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D13E1287E0; Mon, 4 Jul 2016 23:57:31 +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 90BA528790 for ; Mon, 4 Jul 2016 23:57:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DB5FB6E536; Mon, 4 Jul 2016 23:57:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-f195.google.com (mail-yw0-f195.google.com [209.85.161.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 07D796E535 for ; Mon, 4 Jul 2016 23:57:29 +0000 (UTC) Received: by mail-yw0-f195.google.com with SMTP id v77so6587689ywg.2 for ; Mon, 04 Jul 2016 16:57:28 -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; bh=gB8G5XnQ2j+03Wi96yg5SjkkSv7dHR8LFjMmenl+BYw=; b=R6slO2r0M4MGBwkTL8XyWfvkwOiao2Bt20+76rFOlqUY5ecYhrhwWDgsZ1EI95PZys w11bNPIpSV7F4rFf4drW8Nfe+tWk8Cjbae5a9BBfdVdrpsllIEAnnMqzxJaYq+fx65CZ TD65f/+UY4wH/IH8Y7kruD6WgwuvGXO5d1v8K6dBzsFRxzKdSfMQOkRxfq7vZdD9bcEF 7vt4cw5QZN8ttBjLKX8+vZ90x/bXG/qTmtcrnHWNa06ganrnegl6PniIE/zS0kFdKhhY ZdbSzQrXAoWxwDcDljgG4XZa+bWEVvVXRvIF9jz/nAeLw2LR9zlv3+Cp4jaEEWNcsf3S EcUA== X-Gm-Message-State: ALyK8tKvSlflCiy1iai877Y2/ax7T8LW8GSpjWAvVQHXG9QPgKp21dgMslWAVcXVN1jh7A== X-Received: by 10.13.213.213 with SMTP id x204mr10069473ywd.226.1467676648132; Mon, 04 Jul 2016 16:57:28 -0700 (PDT) Received: from jade.localdomain ([189.61.225.79]) by smtp.gmail.com with ESMTPSA id t8sm8573299ywc.40.2016.07.04.16.57.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jul 2016 16:57:27 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 3/4] dma-buf/sync_file: add sync_file_get_fence() Date: Mon, 4 Jul 2016 20:57:07 -0300 Message-Id: <1467676628-4121-4-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1467676628-4121-1-git-send-email-gustavo@padovan.org> References: <1467676628-4121-1-git-send-email-gustavo@padovan.org> Cc: marcheu@google.com, Daniel Stone , seanpaul@google.com, 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan Creates a function that given an sync file descriptor returns a fence containing all fences in the sync_file. v2: Comments by Daniel Vetter - Adapt to new version of fence_collection_init() - Hold a reference for the fence we return v3: - Adapt to use fput() directly - rename to sync_file_get_fence() as we always return one fence v4: Adapt to use fence_array v5: set fence through fence_get() Signed-off-by: Gustavo Padovan Reviewed-by: Chris Wilson --- drivers/dma-buf/sync_file.c | 23 +++++++++++++++++++++++ include/linux/sync_file.h | 1 + 2 files changed, 24 insertions(+) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index a223f48..61a687c 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -116,6 +116,29 @@ err: return NULL; } +/** + * sync_file_get_fence - get the fence related to the sync_file fd + * @fd: sync_file fd to get the fence from + * + * Ensures @fd references a valid sync_file and returns a fence that + * represents all fence in the sync_file. On error NULL is returned. + */ +struct fence *sync_file_get_fence(int fd) +{ + struct sync_file *sync_file; + struct fence *fence; + + sync_file = sync_file_fdget(fd); + if (!sync_file) + return NULL; + + fence = fence_get(sync_file->fence); + fput(sync_file->file); + + return fence; +} +EXPORT_SYMBOL(sync_file_get_fence); + static int sync_file_set_fence(struct sync_file *sync_file, struct fence **fences, int num_fences) { diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h index 2efc5ec..f7de5a0 100644 --- a/include/linux/sync_file.h +++ b/include/linux/sync_file.h @@ -46,5 +46,6 @@ struct sync_file { }; struct sync_file *sync_file_create(struct fence *fence); +struct fence *sync_file_get_fence(int fd); #endif /* _LINUX_SYNC_H */