From patchwork Sat Aug 4 12:44:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10555747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1C8013AC for ; Sat, 4 Aug 2018 12:45:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3A742A13A for ; Sat, 4 Aug 2018 12:45:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7C7F2A146; Sat, 4 Aug 2018 12:45:56 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 682122A13A for ; Sat, 4 Aug 2018 12:45:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729687AbeHDOqc (ORCPT ); Sat, 4 Aug 2018 10:46:32 -0400 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:55025 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727832AbeHDOqJ (ORCPT ); Sat, 4 Aug 2018 10:46:09 -0400 Received: from tschai.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id lvvyfCzUl6brUlvw3fFM4N; Sat, 04 Aug 2018 14:45:31 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Hans Verkuil Subject: [PATCHv17 06/34] media-request: add media_request_object_find Date: Sat, 4 Aug 2018 14:44:58 +0200 Message-Id: <20180804124526.46206-7-hverkuil@xs4all.nl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180804124526.46206-1-hverkuil@xs4all.nl> References: <20180804124526.46206-1-hverkuil@xs4all.nl> X-CMAE-Envelope: MS4wfGvL6nGROrBfAI6uzSUG74PO1F28yBICiIKix5kL/k1KsW3y82qtpgIJNvqH6JlXWHSa8XtBWuiHUBQSAxqv1uvdeQXyOqnbtPhzH12lklUmUBU71v7u hpGinD4j06koiQwoBqPnUd1EqjyH7wpJUlZcHbXYAzlobJP7Z4/232i1bYIDfRAQ4pxw7lWoQRPRzNn+lQq6o0Z+V12MxO9hdqM= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil Add media_request_object_find to find a request object inside a request based on ops and priv values. Objects of the same type (vb2 buffer, control handler) will have the same ops value. And objects that refer to the same 'parent' object (e.g. the v4l2_ctrl_handler that has the current driver state) will have the same priv value. The caller has to call media_request_object_put() for the returned object since this function increments the refcount. Signed-off-by: Hans Verkuil Acked-by: Sakari Ailus Reviewed-by: Mauro Carvalho Chehab --- drivers/media/media-request.c | 25 +++++++++++++++++++++++++ include/media/media-request.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c index 4b523f3a03a3..a5b70a4e613b 100644 --- a/drivers/media/media-request.c +++ b/drivers/media/media-request.c @@ -344,6 +344,31 @@ static void media_request_object_release(struct kref *kref) obj->ops->release(obj); } +struct media_request_object * +media_request_object_find(struct media_request *req, + const struct media_request_object_ops *ops, + void *priv) +{ + struct media_request_object *obj; + struct media_request_object *found = NULL; + unsigned long flags; + + if (WARN_ON(!ops || !priv)) + return NULL; + + spin_lock_irqsave(&req->lock, flags); + list_for_each_entry(obj, &req->objects, list) { + if (obj->ops == ops && obj->priv == priv) { + media_request_object_get(obj); + found = obj; + break; + } + } + spin_unlock_irqrestore(&req->lock, flags); + return found; +} +EXPORT_SYMBOL_GPL(media_request_object_find); + void media_request_object_put(struct media_request_object *obj) { kref_put(&obj->kref, media_request_object_release); diff --git a/include/media/media-request.h b/include/media/media-request.h index 66ec9d09fcd8..fd08d7a431a1 100644 --- a/include/media/media-request.h +++ b/include/media/media-request.h @@ -253,6 +253,26 @@ static inline void media_request_object_get(struct media_request_object *obj) */ void media_request_object_put(struct media_request_object *obj); +/** + * media_request_object_find - Find an object in a request + * + * @req: The media request + * @ops: Find an object with this ops value + * @priv: Find an object with this priv value + * + * Both @ops and @priv must be non-NULL. + * + * Returns the object pointer or NULL if not found. The caller must + * call media_request_object_put() once it finished using the object. + * + * Since this function needs to walk the list of objects it takes + * the @req->lock spin lock to make this safe. + */ +struct media_request_object * +media_request_object_find(struct media_request *req, + const struct media_request_object_ops *ops, + void *priv); + /** * media_request_object_init - Initialise a media request object * @@ -324,6 +344,14 @@ static inline void media_request_object_put(struct media_request_object *obj) { } +static inline struct media_request_object * +media_request_object_find(struct media_request *req, + const struct media_request_object_ops *ops, + void *priv) +{ + return NULL; +} + static inline void media_request_object_init(struct media_request_object *obj) { obj->ops = NULL;