Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp567823ybt; Wed, 17 Jun 2020 08:18:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7JSxY0F9pK5YQkotC2soVwpEKPlQGiT1VWJWHV9a5jZHR1754vXOgPW/hgkaPZcqI5kiv X-Received: by 2002:a17:906:c952:: with SMTP id fw18mr7830997ejb.505.1592407081740; Wed, 17 Jun 2020 08:18:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592407081; cv=none; d=google.com; s=arc-20160816; b=VI2gY5Ij/XpAfGYMi1xi0ZNW9n2kVFMyie9xx5X6ebhgDHOzX1AKR0Cc4eB4pvi0TH sOdC6x8mO3hkWoCb/CvXyJ9/Pd5mBlSCc0CerqZ6zJzT0j0hUjRHZ+ehR0CqShuOVzhu 68puQbToUgUKt2lnFuBNt5a9bq7oCcd1oMT51b+gvg6tVTHNiQCn/LzxelBFJ30qVNzm kka12Z8vrVoU93NJZUiMgI5uY9O3mBS+DhuUYyFrYbRS6fbfdJt7mm3e2NVNMvX/uDnJ SQWch4yfFYJ+Hy2EF73Lt5ynM/Gs0D9PnZG6pyHqe//NY0zjG1ojxJZtbo5I90304EL5 kfsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=/DPli70/+EQYYSrWVkuXokTfke76QDGGUjzBoki62rs=; b=WNPBYGfEVhZMzboSiMHVr9K7o80aqWk9qtF3ds4Kp2fYvgJBucO+tIKPMgBSc3O7TA gDCmDWIo6585kuS+K9OqxFCNpSm7OdnoV+isgW3Xs+dOwC3AGaMWB2hTcHqbSCzBCpkB DkAL+IUZHcoaIDdGRszHQdFBFMVLhnECnX++jMvO1fY/9KPIwqjZZAqVj1zVygBW9/9F 3MqGUlLwssqRfHzhl4LvU6eU0vsxLjg4SfKIEIlQ4v8068pRA91MetDcxdmyFyzfiaRO gQiM9SXigkipWiNW8ctOEsYt78EDdiazT1c3tvnCh1qP5RDPRTe3dCjazaOZyuFwo+NU yMIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w6si77825eja.471.2020.06.17.08.17.36; Wed, 17 Jun 2020 08:18:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726758AbgFQPPq (ORCPT + 99 others); Wed, 17 Jun 2020 11:15:46 -0400 Received: from smtp1.de.adit-jv.com ([93.241.18.167]:50328 "EHLO smtp1.de.adit-jv.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726494AbgFQPPq (ORCPT ); Wed, 17 Jun 2020 11:15:46 -0400 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id E9EC03C057F; Wed, 17 Jun 2020 17:15:43 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8p7emesp5isC; Wed, 17 Jun 2020 17:15:37 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id CA0AD3C00BA; Wed, 17 Jun 2020 17:15:37 +0200 (CEST) Received: from vmlxhi-121.adit-jv.com (10.72.92.132) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.487.0; Wed, 17 Jun 2020 17:15:37 +0200 Date: Wed, 17 Jun 2020 17:15:37 +0200 From: Michael Rodin To: Niklas =?utf-8?Q?S=C3=B6derlund?= CC: Michael Rodin , Mauro Carvalho Chehab , , , , , , , Steve Longerbeam Subject: Re: [PATCH] media: rcar-vin: Move media_device_register to async completion Message-ID: <20200617151537.GB88066@vmlxhi-121.adit-jv.com> References: <1592328696-84533-1-git-send-email-mrodin@de.adit-jv.com> <20200617105646.GB2850317@oden.dyn.berto.se> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200617105646.GB2850317@oden.dyn.berto.se> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [10.72.92.132] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Niklas and Steve, On Wed, Jun 17, 2020 at 12:56:46PM +0200, Niklas Söderlund wrote: > Hi Michael and Steve, > > On 2020-06-16 19:31:36 +0200, Michael Rodin wrote: > > From: Steve Longerbeam > > > > The media_device is registered during driver probe, before async > > completion, so it is possible for .link_notify to be called before > > all devices are bound. > > > > Fix this by moving media_device_register() to rvin_group_notify_complete(). > > This ensures that all devices are now bound (the rcar-csi2 subdevices and > > and video capture devices) before .link_notify can be called. > > I'm curious to what situation created the need for this change. I'm > currently trying to take the VIN driver in the opposite direction [1] > with the end goal of registering video devices at probe time and then > allow the media graph to populate as devices becomes available. It looks like almost all platform drivers call media_device_register() in the completion callback. From my understaning it is necessary to ensure that all subdevices are bound and all links are created before the user can enable any link (which would trigger link_notify callback execution) and set formats. If I am not mistaken, Steve could observe an "OOPS" or at least it is theoretically possible. Actually I found that this patch alone is not enough even if it is correct, because we also have to register the media device in rvin_parallel_notify_complete() in case if there is only a parallel video input device attached. > My reason for this is that we could have a functional pipeline inside > the graph even if it's not complete. This came out of the GMSL work done > a while pack where I had a faulty camera that would prevent the other 7 > in the system to function. I agree that if a probe of a faulty subdevice fails, this should not affect functionality of the other attached subdevices. The "complete" callback of the async notifier is probably not executed in this case, so I guess, we would have to register the media device in the "bound" callback after the first subdevice has been probed? Otherwise there is not much sense to have video capture devices, which are not connected to any source. (Delayed) population of the media graph after media device registration sounds also like a requirement for device tree overlay support, which would also be a nice feature. > 1. [PATCH 0/5] media-device: Report if graph is complete > > > > > Signed-off-by: Steve Longerbeam > > Signed-off-by: Michael Rodin > > --- > > drivers/media/platform/rcar-vin/rcar-core.c | 14 ++++++-------- > > 1 file changed, 6 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c > > index 7440c89..e70f83b 100644 > > --- a/drivers/media/platform/rcar-vin/rcar-core.c > > +++ b/drivers/media/platform/rcar-vin/rcar-core.c > > @@ -253,7 +253,6 @@ static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin) > > struct media_device *mdev = &group->mdev; > > const struct of_device_id *match; > > struct device_node *np; > > - int ret; > > > > mutex_init(&group->lock); > > > > @@ -266,7 +265,6 @@ static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin) > > vin_dbg(vin, "found %u enabled VIN's in DT", group->count); > > > > mdev->dev = vin->dev; > > - mdev->ops = &rvin_media_ops; > > > > match = of_match_node(vin->dev->driver->of_match_table, > > vin->dev->of_node); > > @@ -278,11 +276,7 @@ static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin) > > > > media_device_init(mdev); > > > > - ret = media_device_register(&group->mdev); > > - if (ret) > > - rvin_group_cleanup(group); > > - > > - return ret; > > + return 0; > > } > > > > static void rvin_group_release(struct kref *kref) > > @@ -688,6 +682,8 @@ static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier) > > return ret; > > } > > > > + vin->group->mdev.ops = &rvin_media_ops; > > + > > /* Register all video nodes for the group. */ > > for (i = 0; i < RCAR_VIN_NUM; i++) { > > if (vin->group->vin[i] && > > @@ -736,8 +732,10 @@ static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier) > > } > > } > > mutex_unlock(&vin->group->lock); > > + if (ret) > > + return ret; > > > > - return ret; > > + return media_device_register(&vin->group->mdev); > > } > > > > static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier, > > -- > > 2.7.4 > > > > -- > Regards, > Niklas Söderlund -- Best Regards, Michael