From patchwork Sun Sep 3 17:49:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 9936473 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 5EF446037D for ; Sun, 3 Sep 2017 17:50:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51B7A28565 for ; Sun, 3 Sep 2017 17:50:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 468D928622; Sun, 3 Sep 2017 17:50:18 +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 BFF6528565 for ; Sun, 3 Sep 2017 17:50:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753205AbdICRuH (ORCPT ); Sun, 3 Sep 2017 13:50:07 -0400 Received: from nblzone-211-213.nblnetworks.fi ([83.145.211.213]:49468 "EHLO hillosipuli.retiisi.org.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753163AbdICRuE (ORCPT ); Sun, 3 Sep 2017 13:50:04 -0400 Received: from lanttu.localdomain (lanttu-e.localdomain [192.168.1.64]) by hillosipuli.retiisi.org.uk (Postfix) with ESMTP id BAD5D600F0; Sun, 3 Sep 2017 20:50:00 +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 v7 10/18] v4l: async: Introduce macros for calling async ops callbacks Date: Sun, 3 Sep 2017 20:49:50 +0300 Message-Id: <20170903174958.27058-11-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170903174958.27058-1-sakari.ailus@linux.intel.com> References: <20170903174958.27058-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 two macros 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 --- drivers/media/v4l2-core/v4l2-async.c | 19 +++++++------------ include/media/v4l2-async.h | 8 ++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 810f5e0273dc..91d04f00b4e4 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -107,16 +107,13 @@ static int v4l2_async_test_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_int_op(notifier, bound, 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_void_op(notifier, unbind, sd, asd); return ret; } @@ -129,7 +126,7 @@ static int v4l2_async_test_notify(struct v4l2_async_notifier *notifier, list_move(&sd->async_list, ¬ifier->done); if (list_empty(¬ifier->waiting) && notifier->ops->complete) - return notifier->ops->complete(notifier); + return v4l2_async_notifier_call_int_op(notifier, complete); return 0; } @@ -232,8 +229,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier) /* If we handled USB devices, we'd have to lock the parent too */ device_release_driver(d); - if (notifier->ops->unbind) - notifier->ops->unbind(notifier, sd, sd->asd); + v4l2_async_notifier_call_void_op(notifier, unbind, sd, sd->asd); /* * Store device at the device cache, in order to call @@ -344,8 +340,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_void_op(notifier, unbind, sd, sd->asd); mutex_unlock(&list_lock); } diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h index 3c48f8b66d12..c3e001e0d1f1 100644 --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h @@ -95,6 +95,14 @@ struct v4l2_async_notifier_operations { struct v4l2_async_subdev *asd); }; +#define v4l2_async_notifier_call_int_op(n, op, ...) \ + (((n)->ops && (n)->ops->op) ? (n)->ops->op(n, ## __VA_ARGS__) : 0) +#define v4l2_async_notifier_call_void_op(n, op, ...) \ + do { \ + if ((n)->ops && (n)->ops->op) \ + (n)->ops->op(n, ## __VA_ARGS__); \ + } while (false) + /** * struct v4l2_async_notifier - v4l2_device notifier data *