From patchwork Tue Jul 12 18:08:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9225889 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 4D0E360868 for ; Tue, 12 Jul 2016 18:09:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42530272AA for ; Tue, 12 Jul 2016 18:09:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36DA827C38; Tue, 12 Jul 2016 18:09:17 +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 B59F9272AA for ; Tue, 12 Jul 2016 18:09:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5A5006E5CB; Tue, 12 Jul 2016 18:09:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-f193.google.com (mail-yw0-f193.google.com [209.85.161.193]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6E12A6E5CF for ; Tue, 12 Jul 2016 18:09:11 +0000 (UTC) Received: by mail-yw0-f193.google.com with SMTP id c13so1508406ywh.2 for ; Tue, 12 Jul 2016 11:09:11 -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=D9EnZ36dUT0MMOHH0a1K+iUXgS4qHgxn6PcuIizmyak=; b=Hxb4TMALpvyr3mJhONZy539k/VOGgrB1m1AVXHHyxDY09TEDXMIEq9IW2cs2/yEgQ1 06+vfOntNfMyTn5S6mF7/7GuftyiUoEm7J1iu4B+0UIv/RMEsVXsQ0wJaKTV1Q98Ivc3 qfUkYM+k+TWTHPoxUCzswc0MgqR7FozJGMifMwv8BjVMLphk+r2TIoXn3HBNGHw9OR7h 1Pc7s9p2vND98Cdb7uQQFCwS6i9JIE8Z0W0O4tm0BPnXgAEVxBYm4/aL8cC9qly0iZkF 1dOkc253akeCt6MDP+QTenx8FDvqQENz7NPAsN0d1fVmOmmDtdXKFUWbr2ZuqBRimjBN jzXw== X-Gm-Message-State: ALyK8tJeVnGwmbj6FEeqBnEe0AtyR85hgAkyC7LplAa8EU4pXdtJGWI3ttnaDwYxJlxMsw== X-Received: by 10.37.85.213 with SMTP id j204mr2612166ybb.149.1468346949999; Tue, 12 Jul 2016 11:09:09 -0700 (PDT) Received: from jade.localdomain ([189.61.225.79]) by smtp.gmail.com with ESMTPSA id v68sm196062ywg.31.2016.07.12.11.09.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2016 11:09:09 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 3/5] dma-buf/sync_file: add sync_file_get_fence() Date: Tue, 12 Jul 2016 15:08:43 -0300 Message-Id: <1468346925-12774-3-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1468346925-12774-1-git-send-email-gustavo@padovan.org> References: <1468346925-12774-1-git-send-email-gustavo@padovan.org> MIME-Version: 1.0 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: , 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 Acked-by: Christian König --- 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 */