From patchwork Fri Jul 21 09:55:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 9856415 X-Patchwork-Delegate: geert@linux-m68k.org 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 A04F560392 for ; Fri, 21 Jul 2017 09:56:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DAA62872B for ; Fri, 21 Jul 2017 09:56:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7247B2877C; Fri, 21 Jul 2017 09:56:05 +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=unavailable 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 820F828767 for ; Fri, 21 Jul 2017 09:56:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753388AbdGUJ4B (ORCPT ); Fri, 21 Jul 2017 05:56:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:51942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752198AbdGUJz4 (ORCPT ); Fri, 21 Jul 2017 05:55:56 -0400 Received: from CookieMonster.cookiemonster.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 030BC22B4E; Fri, 21 Jul 2017 09:55:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 030BC22B4E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=kieran.bingham+renesas@ideasonboard.com From: Kieran Bingham To: niklas.soderlund@ragnatech.se Cc: laurent.pinchart@ideasonboard.com, linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, kieran.bingham@ideasonboard.com, Kieran Bingham Subject: [PATCH] v4l: rcar-vin: Simplify rvin_group_notify_{bound,unbind} Date: Fri, 21 Jul 2017 10:55:50 +0100 Message-Id: <1500630950-29870-1-git-send-email-kieran.bingham+renesas@ideasonboard.com> X-Mailer: git-send-email 2.7.4 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use a container_of macro to obtain the graph entity object from the ASD This removes the error conditions, and reduces the lock contention. (The locking may even be potentially removed) Signed-off-by: Kieran Bingham --- Hi Niklas, While working through the Multi camera setup, we came across this improvement. If this code isn't yet upstream, feel free to squash this change into your existing branch if you wish. Regards Kieran drivers/media/platform/rcar-vin/rcar-core.c | 28 ++++++---------------------- drivers/media/platform/rcar-vin/rcar-vin.h | 3 +++ 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 8393a1598660..b4fc7b56c8a1 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -688,20 +688,11 @@ static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier, struct v4l2_async_subdev *asd) { struct rvin_dev *vin = notifier_to_vin(notifier); - unsigned int i; + struct rvin_graph_entity *csi = to_rvin_graph_entity(asd); mutex_lock(&vin->group->lock); - for (i = 0; i < RVIN_CSI_MAX; i++) { - if (&vin->group->csi[i].asd == asd) { - vin_dbg(vin, "Unbind CSI-2 %s\n", subdev->name); - vin->group->csi[i].subdev = NULL; - mutex_unlock(&vin->group->lock); - return; - } - } + csi->subdev = NULL; mutex_unlock(&vin->group->lock); - - vin_err(vin, "No entity for subdev %s to unbind\n", subdev->name); } static int rvin_group_notify_bound(struct v4l2_async_notifier *notifier, @@ -709,23 +700,16 @@ static int rvin_group_notify_bound(struct v4l2_async_notifier *notifier, struct v4l2_async_subdev *asd) { struct rvin_dev *vin = notifier_to_vin(notifier); - unsigned int i; + struct rvin_graph_entity *csi = to_rvin_graph_entity(asd); v4l2_set_subdev_hostdata(subdev, vin); mutex_lock(&vin->group->lock); - for (i = 0; i < RVIN_CSI_MAX; i++) { - if (&vin->group->csi[i].asd == asd) { - vin_dbg(vin, "Bound CSI-2 %s\n", subdev->name); - vin->group->csi[i].subdev = subdev; - mutex_unlock(&vin->group->lock); - return 0; - } - } + vin_dbg(vin, "Bound CSI-2 %s\n", subdev->name); + csi->subdev = subdev; mutex_unlock(&vin->group->lock); - vin_err(vin, "No entity for subdev %s to bind\n", subdev->name); - return -EINVAL; + return 0; } static struct device_node *rvin_group_get_csi(struct rvin_dev *vin, diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index e7e600fdf566..900c473c3d15 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -92,6 +92,9 @@ struct rvin_graph_entity { unsigned int sink_pad; }; +#define to_rvin_graph_entity(asd) \ + container_of(asd, struct rvin_graph_entity, asd) + struct rvin_group;