From patchwork Tue Sep 5 13:05:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 9938981 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 4DE086038C for ; Tue, 5 Sep 2017 13:06:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4056C28981 for ; Tue, 5 Sep 2017 13:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3530228986; Tue, 5 Sep 2017 13:06:29 +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=-6.9 required=2.0 tests=BAYES_00,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 CD36328981 for ; Tue, 5 Sep 2017 13:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751821AbdIENG0 (ORCPT ); Tue, 5 Sep 2017 09:06:26 -0400 Received: from nblzone-211-213.nblnetworks.fi ([83.145.211.213]:40780 "EHLO hillosipuli.retiisi.org.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751671AbdIENF7 (ORCPT ); Tue, 5 Sep 2017 09:05:59 -0400 Received: from lanttu.localdomain (unknown [IPv6:2001:1bc8:1a6:d3d5::e1:1002]) by hillosipuli.retiisi.org.uk (Postfix) with ESMTP id C16F1600F7; Tue, 5 Sep 2017 16:05:57 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: niklas.soderlund@ragnatech.se, robh@kernel.org, hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, devicetree@vger.kernel.org, pavel@ucw.cz, sre@kernel.org Subject: [PATCH v8 12/21] v4l: async: Introduce helpers for calling async ops callbacks Date: Tue, 5 Sep 2017 16:05:44 +0300 Message-Id: <20170905130553.1332-13-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170905130553.1332-1-sakari.ailus@linux.intel.com> References: <20170905130553.1332-1-sakari.ailus@linux.intel.com> 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 Add three helper functions to call async operations callbacks. Besides simplifying callbacks, this allows async notifiers to have no ops set, i.e. it can be left NULL. Signed-off-by: Sakari Ailus Acked-by: Hans Verkuil --- drivers/media/v4l2-core/v4l2-async.c | 49 ++++++++++++++++++++++++++---------- include/media/v4l2-async.h | 1 + 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index f7eb3713207a..baee95eacbba 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -25,6 +25,34 @@ #include #include +static int v4l2_async_notifier_call_bound(struct v4l2_async_notifier *n, + struct v4l2_subdev *subdev, + struct v4l2_async_subdev *asd) +{ + if (!n->ops || !n->ops->bound) + return 0; + + return n->ops->bound(n, subdev, asd); +} + +static void v4l2_async_notifier_call_unbind(struct v4l2_async_notifier *n, + struct v4l2_subdev *subdev, + struct v4l2_async_subdev *asd) +{ + if (!n->ops || !n->ops->unbind) + return; + + n->ops->unbind(n, subdev, asd); +} + +static int v4l2_async_notifier_call_complete(struct v4l2_async_notifier *n) +{ + if (!n->ops || !n->ops->complete) + return 0; + + return n->ops->complete(n); +} + static bool match_i2c(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd) { #if IS_ENABLED(CONFIG_I2C) @@ -107,16 +135,13 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier, { int ret; - if (notifier->ops->bound) { - ret = notifier->ops->bound(notifier, sd, asd); - if (ret < 0) - return ret; - } + ret = v4l2_async_notifier_call_bound(notifier, sd, asd); + if (ret < 0) + return ret; ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd); if (ret < 0) { - if (notifier->ops->unbind) - notifier->ops->unbind(notifier, sd, asd); + v4l2_async_notifier_call_unbind(notifier, sd, asd); return ret; } @@ -128,8 +153,8 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier, /* Move from the global subdevice list to notifier's done */ list_move(&sd->async_list, ¬ifier->done); - if (list_empty(¬ifier->waiting) && notifier->ops->complete) - return notifier->ops->complete(notifier); + if (list_empty(¬ifier->waiting)) + return v4l2_async_notifier_call_complete(notifier); return 0; } @@ -215,8 +240,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier) list_for_each_entry_safe(sd, tmp, ¬ifier->done, async_list) { v4l2_async_cleanup(sd); - if (notifier->ops->unbind) - notifier->ops->unbind(notifier, sd, sd->asd); + v4l2_async_notifier_call_unbind(notifier, sd, sd->asd); } mutex_unlock(&list_lock); @@ -294,8 +318,7 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd) v4l2_async_cleanup(sd); - if (notifier->ops->unbind) - notifier->ops->unbind(notifier, sd, sd->asd); + v4l2_async_notifier_call_unbind(notifier, sd, sd->asd); mutex_unlock(&list_lock); } diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h index 3c48f8b66d12..3bc8a7c0d83f 100644 --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h @@ -164,4 +164,5 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd); * @sd: pointer to &struct v4l2_subdev */ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd); + #endif