From patchwork Mon Aug 26 12:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13777808 X-Patchwork-Delegate: kieran@bingham.xyz Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38C0117C9B5; Mon, 26 Aug 2024 12:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676076; cv=none; b=ubconn6npkae1y+e4cKC62TEm5Gr9q7uu0wKOUdTyToW2jPKPUD18MMeZbEHtz8rqAieptRbuwyItjl3p6thhXrLvualCMq2+d4qxEpU4FsvV+01gOkbVNA0P/L92HdIyUioZFw+3RO07mZSpoJGzAiLL/Tmsol1MgERw3smVPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676076; c=relaxed/simple; bh=0HM33IFSvPq8mPFtAxp1mMrC/z1rT8ewvo6H+mRbCt8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RSeEhnF1PizGjQ8gNWK1qdLS6TheZ1Y5FnkgHuoPPpsv72f4hO7Cubtset5gdUOJ//Z+G20w1mqWlYP8hSxmulJtwxV98kZQnMDySOPYRSoPGVOGvpG+OqcFZ+Ngu8T6QXAoG7C2UOjKo5ctcIgELVA2OYhM0z6QuAaYyjajHj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=liJjew+8; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="liJjew+8" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0B545741; Mon, 26 Aug 2024 14:40:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724676006; bh=0HM33IFSvPq8mPFtAxp1mMrC/z1rT8ewvo6H+mRbCt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=liJjew+8tmregBwKV+eHJqNTOXPICba5m6uYFxVUjHAQOYZCRzg3Ks6uq08wt/1Ka 1PwNeWCFKrqbKJC5N/sb44W8nlBAbRDDqCDa9YZLaDWj9ygyPvpIkvtnpmnQUT2ZAg uW8uERbgCgdEa/dhhV2bcDFN0fw6GUQBXZzSA4H4= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Chen-Yu Tsai , Eugen Hristev , Hans Verkuil , Jacopo Mondi , Kieran Bingham , Maxime Ripard , Sakari Ailus , Tomi Valkeinen , linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: [PATCH v3 1/7] media: microchip-isc: Drop v4l2_subdev_link_validate() for video devices Date: Mon, 26 Aug 2024 15:41:00 +0300 Message-ID: <20240826124106.3823-2-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The v4l2_subdev_link_validate() function is a helper designed to validate links whose sink is a subdev. When called on a link whose sink is a video device, it only prints a warning and returns. As the microchip-isc driver implements manual validate of the subdev to video device link, we can just dropp the v4l2_subdev_link_validate() to avoid the warning. Signed-off-by: Laurent Pinchart Reviewed-by: Tomi Valkeinen --- .../platform/microchip/microchip-isc-base.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/drivers/media/platform/microchip/microchip-isc-base.c index f3a5cbacadbe..28e56f6a695d 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -902,8 +902,11 @@ static int isc_set_fmt(struct isc_device *isc, struct v4l2_format *f) return 0; } -static int isc_validate(struct isc_device *isc) +static int isc_link_validate(struct media_link *link) { + struct video_device *vdev = + media_entity_to_video_device(link->sink->entity); + struct isc_device *isc = video_get_drvdata(vdev); int ret; int i; struct isc_format *sd_fmt = NULL; @@ -1906,20 +1909,6 @@ int microchip_isc_pipeline_init(struct isc_device *isc) } EXPORT_SYMBOL_GPL(microchip_isc_pipeline_init); -static int isc_link_validate(struct media_link *link) -{ - struct video_device *vdev = - media_entity_to_video_device(link->sink->entity); - struct isc_device *isc = video_get_drvdata(vdev); - int ret; - - ret = v4l2_subdev_link_validate(link); - if (ret) - return ret; - - return isc_validate(isc); -} - static const struct media_entity_operations isc_entity_operations = { .link_validate = isc_link_validate, }; From patchwork Mon Aug 26 12:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13777809 X-Patchwork-Delegate: kieran@bingham.xyz Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C7411865F8; Mon, 26 Aug 2024 12:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676077; cv=none; b=d4vWcJLz/2gxdi72n795Unj3W5E0nEhXF9V1JhpQWt+mGkwWCO7gEqJXwvmlJVzXifFV3cU913ngw6CHAMl561jAATRShk0CBYU1KqqCqO/UAD0R9fs/bNzKcnlGCYFNPSGs46qW+c9e8mD5QChEuDQrdudyq1zhCgNM4ER4+rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676077; c=relaxed/simple; bh=wvXabLBSZFqAaH8FqO8ftWR8xep2ysj04F8PIH1ewp4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+AOxWsNzI1MniNXE00oP0jyigOMTbdiTSgWtXBoEag9t8BLYaGvQhPFfOSqoJmeeJ7UaQCTz4SmIQJnIDXB1ghnUahDyYXkaeAUGbKWoUBV5kcGTTg1h/v36ZrXyp3R+CWxsmdxeu/hcC8N0I9fKoY83va9GUU0cjviYn7640I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=Bt8sQHjb; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Bt8sQHjb" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 846388D4; Mon, 26 Aug 2024 14:40:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724676007; bh=wvXabLBSZFqAaH8FqO8ftWR8xep2ysj04F8PIH1ewp4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bt8sQHjboIvHmTCZGYU+julNs483g0ojpqldPhn6LkLjyjdICif0rnnEqde3V7EJH ShiC8VIZPTWje/9PvNvQFsMVoqIvOqaUg4tv+wwZZRvnbAQnjnzJB4j4nlgxDkdrhX gCkllaaicRAg7bHNzqMz03fZzokA42KU//n2QSz4= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Chen-Yu Tsai , Eugen Hristev , Hans Verkuil , Jacopo Mondi , Kieran Bingham , Maxime Ripard , Sakari Ailus , Tomi Valkeinen , linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, stable@vger.kernel.org Subject: [PATCH v3 2/7] media: sun4i_csi: Implement link validate for sun4i_csi subdev Date: Mon, 26 Aug 2024 15:41:01 +0300 Message-ID: <20240826124106.3823-3-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The sun4i_csi driver doesn't implement link validation for the subdev it registers, leaving the link between the subdev and its source unvalidated. Fix it, using the v4l2_subdev_link_validate() helper. Fixes: 577bbf23b758 ("media: sunxi: Add A10 CSI driver") Cc: stable@vger.kernel.org Signed-off-by: Laurent Pinchart Acked-by: Chen-Yu Tsai Reviewed-by: Tomi Valkeinen --- drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c index 097a3a08ef7d..dbb26c7b2f8d 100644 --- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c +++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c @@ -39,6 +39,10 @@ static const struct media_entity_operations sun4i_csi_video_entity_ops = { .link_validate = v4l2_subdev_link_validate, }; +static const struct media_entity_operations sun4i_csi_subdev_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; + static int sun4i_csi_notify_bound(struct v4l2_async_notifier *notifier, struct v4l2_subdev *subdev, struct v4l2_async_connection *asd) @@ -214,6 +218,7 @@ static int sun4i_csi_probe(struct platform_device *pdev) subdev->internal_ops = &sun4i_csi_subdev_internal_ops; subdev->flags = V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; subdev->entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; + subdev->entity.ops = &sun4i_csi_subdev_entity_ops; subdev->owner = THIS_MODULE; snprintf(subdev->name, sizeof(subdev->name), "sun4i-csi-0"); v4l2_set_subdevdata(subdev, csi); From patchwork Mon Aug 26 12:41:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13777810 X-Patchwork-Delegate: kieran@bingham.xyz Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A79C18755F; Mon, 26 Aug 2024 12:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676079; cv=none; b=ie7ib09QmfxWWk8BnzriaUEk2C3aZO2yG0YPdWkihDJPG3ICtHiwDXJgJOHF1DDS4qwRS1p/DM7SU5fceU4SkE5Cc3use7MT2a8ncqMisw5X1Xm0phao1xUql4VrxiZU18u+qTPGyienWCv/PldIOqzAgbVtbCEe5Wydn4ToOaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676079; c=relaxed/simple; bh=scQkDIL05VQp5Mauo9cfSnC/NPA9wVIB97pdzpBE5UY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LPcwGO/uZrwE/uH4SbWCGy4pUxnq0nTeMSmhhOtS7XITVFDNVbEVztWAKzblkKCnp41KLCO+pBxA+DJ37r+rvH+Q9vv5WHPwhCC+Ehk4qIVexV5qeqs/mJqR1g7vZhXMkU9NziomUWU4HhjvHlKrsxO+//XJvpmc5+07RTGsAgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=cc2JKB5K; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cc2JKB5K" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E8F349FF; Mon, 26 Aug 2024 14:40:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724676009; bh=scQkDIL05VQp5Mauo9cfSnC/NPA9wVIB97pdzpBE5UY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cc2JKB5K3mjkVUZvlSi/gydBbFcICpqPcFF7RuaRUnil/8XUXaZqlAkBUIkG4hTFs 6Ze0+mf6ro02CJ/4RP40rgpnfFCdZTtWJqB6HGwe9kpeBk5KnZ2aRCSPjwp7u5AXE7 msIJDAQujLqRiRGr+lyWPXzLv7hSmpSgqnkxxaEo= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Chen-Yu Tsai , Eugen Hristev , Hans Verkuil , Jacopo Mondi , Kieran Bingham , Maxime Ripard , Sakari Ailus , Tomi Valkeinen , linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: [PATCH v3 3/7] media: sun4i_csi: Don't use v4l2_subdev_link_validate() for video device Date: Mon, 26 Aug 2024 15:41:02 +0300 Message-ID: <20240826124106.3823-4-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The v4l2_subdev_link_validate() function is a helper designed to validate links whose sink is a subdev. When called on a link whose sink is a video device, it only prints a warning and returns. Its usage in the sun4i_csi driver is wrong, leaving the link from the sub4i_csi subdev to the capture video device unvalidated. Planned improvements to the v4l2_subdev_link_validate() function will turn the warning into an error, breaking the sun4i_csi driver. As an interim measure, move the warning to the sun4i_csi driver in a custom validation handler, and drop the call to the helper. Signed-off-by: Laurent Pinchart Acked-by: Chen-Yu Tsai Reviewed-by: Tomi Valkeinen --- drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c index dbb26c7b2f8d..d07e980aba61 100644 --- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c +++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c @@ -35,8 +35,15 @@ struct sun4i_csi_traits { bool has_isp; }; +static int sun4i_csi_video_link_validate(struct media_link *link) +{ + dev_warn_once(link->graph_obj.mdev->dev, + "Driver bug: link validation not implemented\n"); + return 0; +} + static const struct media_entity_operations sun4i_csi_video_entity_ops = { - .link_validate = v4l2_subdev_link_validate, + .link_validate = sun4i_csi_video_link_validate, }; static const struct media_entity_operations sun4i_csi_subdev_entity_ops = { From patchwork Mon Aug 26 12:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13777811 X-Patchwork-Delegate: kieran@bingham.xyz Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7915518785F; Mon, 26 Aug 2024 12:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676080; cv=none; b=ZU7nwMuze8V5AsxyWFzwWDm5XbqrBeCowvd/U9Um2r/sAHt8pj3VixKku7+9RS1tdsgmh9BgANVteFlJnJGzbrGEnjjAoJQKDoDlmlEKm6AFbN9A5QkFB1opiKbS9ijz8TA+ysS2Sg5cOOCjW5qIQFtYHW2uK8/llpnQJJAqW/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676080; c=relaxed/simple; bh=tf0gc+Fe9/W9nbNtwdjzHM9gsYlIcyofSdubnqTEUoI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PMQKk+Q5wcF3ZvmsdcwSB4e5EPodXL/E5sAC9y3D54A/T2bfGbAImToRnNWF7w2pFK2imBQrF9OH4ZE2y+OfU9gKv8NGlwUP6Kgt9guZGyk7xwYd+WSbGu4WDe39GP7YlcnogRA6X8Q1+vMVo64DJNuyy+U45Nl/cGMB65EHqZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=Cb2PW3I4; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Cb2PW3I4" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E058A8F; Mon, 26 Aug 2024 14:40:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724676010; bh=tf0gc+Fe9/W9nbNtwdjzHM9gsYlIcyofSdubnqTEUoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cb2PW3I4Hy4uVS5oXuJOP4NG0db2CPbZKoXMXxjLLPLD0Yehvn+YpFHkRG/j9YUr8 TywusXbvI0FS/ed1upfdHbKZ9BbH0vesI+nVO4KssWuYD4cIeAe5KkguG0TCE58bWL SCoTBxV3CjwZUHYhPeUPMUNSeG6i4CqIOycQqE+g= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Chen-Yu Tsai , Eugen Hristev , Hans Verkuil , Jacopo Mondi , Kieran Bingham , Maxime Ripard , Sakari Ailus , Tomi Valkeinen , linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: [PATCH v3 4/7] media: v4l2-subdev: Refactor warnings in v4l2_subdev_link_validate() Date: Mon, 26 Aug 2024 15:41:03 +0300 Message-ID: <20240826124106.3823-5-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The v4l2_subdev_link_validate() function prints a one-time warning if it gets called on a link whose source or sink is not a subdev. As links get validated in the context of their sink, a call to the helper when the link's sink is not a subdev indicates that the driver has set its .link_validate() handler to v4l2_subdev_link_validate() on a non-subdev entity, which is a clear driver bug. On the other hand, the link's source not being a subdev indicates that the helper is used for a subdev connected to a video output device, which is a lesser issue, if only because this is currently common practice. There are no drivers left in the kernel that use v4l2_subdev_link_validate() in a context where it may get called on a non-subdev sink. Replace the pr_warn_once() with a WARN_ON_ONCE() in this case to make sure that new offenders won't be introduced. A subsequent change will improve the v4l2_subdev_link_validate() helper to properly support validating video device to subdev links. Signed-off-by: Laurent Pinchart --- Changes since v2: - Extend commit message with third paragraph Changes since v1: - Switch from WARN_ON() to WARN_ON_ONCE() --- drivers/media/v4l2-core/v4l2-subdev.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 7c5812d55315..d3196042d5c5 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1443,11 +1443,15 @@ int v4l2_subdev_link_validate(struct media_link *link) bool states_locked; int ret; - if (!is_media_entity_v4l2_subdev(link->sink->entity) || - !is_media_entity_v4l2_subdev(link->source->entity)) { - pr_warn_once("%s of link '%s':%u->'%s':%u is not a V4L2 sub-device, driver bug!\n", - !is_media_entity_v4l2_subdev(link->sink->entity) ? - "sink" : "source", + /* + * Links are validated in the context of the sink entity. Usage of this + * helper on a sink that is not a subdev is a clear driver bug. + */ + if (WARN_ON_ONCE(!is_media_entity_v4l2_subdev(link->sink->entity))) + return -EINVAL; + + if (!is_media_entity_v4l2_subdev(link->source->entity)) { + pr_warn_once("source of link '%s':%u->'%s':%u is not a V4L2 sub-device, driver bug!\n", link->source->entity->name, link->source->index, link->sink->entity->name, link->sink->index); return 0; From patchwork Mon Aug 26 12:41:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13777812 X-Patchwork-Delegate: kieran@bingham.xyz Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A9AD188584; Mon, 26 Aug 2024 12:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676082; cv=none; b=iwMKDjFQf808W29Jr8l95ypH68d9uJ9XGTFLG/5L7ATQ1Kphe0fMWcsYyPQ19jRzCHcK4Tgk06925qY90gpspSO71oGtxL90FtoHSOEdGP7KzviHa2HTNc2W3yuus46UOvikbqtgzkjzcL4X51/zgc6kyTu7+pr+SRLLS6ljW2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676082; c=relaxed/simple; bh=SxMIqFS6SWymda0VHG0xFKm6S+RPDfcEs0E4NjlsKD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C5Y4y7pFTYF1PljR/NHZUxIuZpdSlu0jzACgnxt+Q0Evy/mXLUhTp2uZsLF4Zm1NRAD+9oycGr69ffZXpzgOlM7No4fTnsOnfCmM+t7e+0o0OT8Vnyb7fXj8zzjfUWVePCpjHn7NKwc2zBz5QoClURAN9RcINSm/AIDZvh0hMm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=RlRqrv7n; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RlRqrv7n" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4BC2F6CA; Mon, 26 Aug 2024 14:40:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724676012; bh=SxMIqFS6SWymda0VHG0xFKm6S+RPDfcEs0E4NjlsKD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RlRqrv7nlQaxNIJUjtfhEXyYX30OsyqP8/MHyN0aBwMymy/7hJqki2+NrZ/LPKOfv eWVd+DcOb6w+ie+qhyOuJ5xblIohyVNj+8HngHv+Lrz0xUA/J8Sbbz18cl5OcZaPXj bzyZ5r8uBpLCT5eNJLxQN8NN18F4kwtuWOkTJK+E= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Chen-Yu Tsai , Eugen Hristev , Hans Verkuil , Jacopo Mondi , Kieran Bingham , Maxime Ripard , Sakari Ailus , Tomi Valkeinen , linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: [PATCH v3 5/7] media: v4l2-subdev: Support hybrid links in v4l2_subdev_link_validate() Date: Mon, 26 Aug 2024 15:41:04 +0300 Message-ID: <20240826124106.3823-6-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The v4l2_subdev_link_validate() helper function is meant to be used as a drop-in implementation of a V4L2 subdev entity .link_validate() handler. It supports subdev-to-subdev links only, and complains if one end of the link is not a subdev. This forces drivers that have video output devices connected to subdevs to implement a custom .link_validate() handler, calling v4l2_subdev_link_validate() for the subdev-to-subdev links, and performing manual link validation for the video-to-subdev links. Video devices embed a media entity, and therefore also have a .link_validate() operation. For video capture devices, the operation should be manually implemented by drivers for validate the subdev-to-video links. For video output devices, on the other hand, that operation is never called, as link validation is performed in the context of the sink entity. As a result, we end up forcing drivers to implement a custom .link_validate() handler for subdevs connected to video output devices, when the video devices provide an operation that could be used for that purpose. To improve that situation, make v4l2_subdev_link_validate() delegate link validation to the source's .link_validate() operation when the link source is a video device and the link sink is a subdev. This allows broader usage of v4l2_subdev_link_validate(), and simplifies drivers by making video device link validation easy to implement in the video device .link_validate(), regardless of whether the video device is an output device or a capture device. Signed-off-by: Laurent Pinchart --- Changes since v2: - Expand comment about infinite loops --- drivers/media/v4l2-core/v4l2-subdev.c | 43 +++++++++++++++++++++++---- include/media/v4l2-subdev.h | 6 ++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index d3196042d5c5..3a4ba08810d2 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1450,13 +1450,46 @@ int v4l2_subdev_link_validate(struct media_link *link) if (WARN_ON_ONCE(!is_media_entity_v4l2_subdev(link->sink->entity))) return -EINVAL; - if (!is_media_entity_v4l2_subdev(link->source->entity)) { - pr_warn_once("source of link '%s':%u->'%s':%u is not a V4L2 sub-device, driver bug!\n", - link->source->entity->name, link->source->index, - link->sink->entity->name, link->sink->index); - return 0; + /* + * If the source is a video device, delegate link validation to it. This + * allows usage of this helper for subdev connected to a video output + * device, provided that the driver implement the video output device's + * .link_validate() operation. + */ + if (is_media_entity_v4l2_video_device(link->source->entity)) { + struct media_entity *source = link->source->entity; + + if (!source->ops || !source->ops->link_validate) { + /* + * Many existing drivers do not implement the required + * .link_validate() operation for their video devices. + * Print a warning to get the drivers fixed, and return + * 0 to avoid breaking userspace. This should + * eventually be turned into a WARN_ON() when all + * drivers will have been fixed. + */ + pr_warn_once("video device '%s' does not implement .link_validate(), driver bug!\n", + source->name); + return 0; + } + + /* + * Avoid infinite loops in case a video device incorrectly uses + * this helper function as its .link_validate() handler. + */ + if (WARN_ON(source->ops->link_validate == v4l2_subdev_link_validate)) + return -EINVAL; + + return source->ops->link_validate(link); } + /* + * If the source is still not a subdev, usage of this helper is a clear + * driver bug. + */ + if (WARN_ON(!is_media_entity_v4l2_subdev(link->source->entity))) + return -EINVAL; + sink_sd = media_entity_to_v4l2_subdev(link->sink->entity); source_sd = media_entity_to_v4l2_subdev(link->source->entity); diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index bd235d325ff9..8daa0929865c 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1250,6 +1250,12 @@ int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd, * calls v4l2_subdev_link_validate_default() to ensure that * width, height and the media bus pixel code are equal on both * source and sink of the link. + * + * The function can be used as a drop-in &media_entity_ops.link_validate + * implementation for v4l2_subdev instances. It supports all links between + * subdevs, as well as links between subdevs and video devices, provided that + * the video devices also implement their &media_entity_ops.link_validate + * operation. */ int v4l2_subdev_link_validate(struct media_link *link); From patchwork Mon Aug 26 12:41:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13777813 X-Patchwork-Delegate: kieran@bingham.xyz Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8099C1898F2; Mon, 26 Aug 2024 12:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676084; cv=none; b=Vlmx+HBZOod0rLCIGh6fpQYoBCwcNCQNld2lHUModXk8UAXv4p72wQQghX/v660FX4x7dKDje+Q5k0UJK+i1h3fttA7JyO6B5itugAEy9prnYDNmBJrV2nVHGSwLgaCJ7G67M+q/BqkNzNzxfunpMH9I+U1gF1ik0xDxJWV/UCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676084; c=relaxed/simple; bh=xnXHdOWz1ePOrNRwz+1c9IdDf589HBsYqT6MdqLoPoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NPHtd3tpCHh+Xbwkv3L9ytScEZ/sDBOJfDrkzHyaruhJLxotIvZDMK/FLep83KIAGp6lXdvuZUEhDfvoxxnY/FPjuoc9rA9JqexYfFiFK3sldXp+eghymdmFqUBdAuKvzo7EMA78VDJdtbjsEzmczI8ak+z+LdARD6sc0d9Umes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=RWPLUEgm; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RWPLUEgm" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B1D90D4A; Mon, 26 Aug 2024 14:40:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724676013; bh=xnXHdOWz1ePOrNRwz+1c9IdDf589HBsYqT6MdqLoPoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RWPLUEgmyl4uc7cXRG6mq0sb2plLDGNiLLjeHdlSKqsueCQMKM6fpCPzkazNblsau NYM/hX4hEoYOvgR7AhWS/qQoEdK30UEg6H0Xixd3zaE5Bh7UN/dVEuf+Ru3PEFcnuo I354xqSxR4/B3liTLly/GokwmQ7VbIGLqVfHy2Mg= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Chen-Yu Tsai , Eugen Hristev , Hans Verkuil , Jacopo Mondi , Kieran Bingham , Maxime Ripard , Sakari Ailus , Tomi Valkeinen , linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: [PATCH v3 6/7] media: renesas: vsp1: Implement .link_validate() for video devices Date: Mon, 26 Aug 2024 15:41:05 +0300 Message-ID: <20240826124106.3823-7-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The v4l2_subdev_link_validate() helper prints a warning if the .link_validate() operation is not implemented for video devices connected to the subdevs. Implement the operation to silence the warning. Ideally validation of the link between the video device and the subdev should be implemented in that operation. That would however break userspace that does not configure formats on all video devices before starting streaming. While this mode of operation may not be considered valid by the V4L2 API specification (interpretation differ), it is nonetheless supported by the vsp1 driver at the moment and used by at least the vsp1 unit test suite, and possibly other userspace applications. Removing it would be a regression. Signed-off-by: Laurent Pinchart --- Changes since v2: - Fix typo in commit message --- .../media/platform/renesas/vsp1/vsp1_video.c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c index fdb46ec0c872..e728f9f5160e 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c @@ -1081,6 +1081,27 @@ static const struct v4l2_file_operations vsp1_video_fops = { .mmap = vb2_fop_mmap, }; +/* ----------------------------------------------------------------------------- + * Media entity operations + */ + +static int vsp1_video_link_validate(struct media_link *link) +{ + /* + * Ideally, link validation should be implemented here instead of + * calling vsp1_video_verify_format() in vsp1_video_streamon() + * manually. That would however break userspace that start one video + * device before configures formats on other video devices in the + * pipeline. This operation is just a no-op to silence the warnings + * from v4l2_subdev_link_validate(). + */ + return 0; +} + +static const struct media_entity_operations vsp1_video_media_ops = { + .link_validate = vsp1_video_link_validate, +}; + /* ----------------------------------------------------------------------------- * Suspend and Resume */ @@ -1215,6 +1236,7 @@ struct vsp1_video *vsp1_video_create(struct vsp1_device *vsp1, /* ... and the video node... */ video->video.v4l2_dev = &video->vsp1->v4l2_dev; + video->video.entity.ops = &vsp1_video_media_ops; video->video.fops = &vsp1_video_fops; snprintf(video->video.name, sizeof(video->video.name), "%s %s", rwpf->entity.subdev.name, direction); From patchwork Mon Aug 26 12:41:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13777814 X-Patchwork-Delegate: kieran@bingham.xyz Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFA2B18D63F; Mon, 26 Aug 2024 12:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676085; cv=none; b=ViHf/DAq2Q9aU6LpCBSQDVbwVVrh6lZ8FPC+QaPvnkaD3bKcN5xl0C+mHTADLL5QyQSq2OwjMxDqhLdmdO7AB7VBxw3QQ9VYqe2y1NJLKX+a6fOOX9zG81JA6ttyenZwK3pVoaG3wnXv0E01SHhnu/MRDDuv4/nv2LA5x/C4Qc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724676085; c=relaxed/simple; bh=pC31TMBm1LuxpurY7zo/QNQuPEpRlxOKUDSCCF/EcTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ckkMYr9YzrDrf0WdRUFb3jtTGbhcgJ/kAhonCCt56EF7tg67G1REzUWpcmE6/3pj6x0ZtKHCGeiP5RRaAVs9rUIk122rsGSM+I6u4G7hCLKXVXZQTxkUKqkz8qKsTvAJ7s7IcIdHIg7jVsKuveBBn6aTSH8IFGaT3TLr8XC7/fQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=PolcWDec; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="PolcWDec" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2312B741; Mon, 26 Aug 2024 14:40:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724676015; bh=pC31TMBm1LuxpurY7zo/QNQuPEpRlxOKUDSCCF/EcTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PolcWDecwpJ7RLmXdYEUtUYefnM2ZnokhL76Z5KatwZQy9HVXnqqVGY7fjW3stgJo RZ65ob3+0gXPv0H7lhVdbT+XZxaAR1cGh7Y/utqGx8Hk+8Ou7qjDd0BLM5aJlmlWwd PsBCLl0qhJ4ysnirDigO415IzHErXbuJzVvMlhfQ= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Chen-Yu Tsai , Eugen Hristev , Hans Verkuil , Jacopo Mondi , Kieran Bingham , Maxime Ripard , Sakari Ailus , Tomi Valkeinen , linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: [PATCH v3 7/7] [DNI] media: renesas: vsp1: Validate all links through .link_validate() Date: Mon, 26 Aug 2024 15:41:06 +0300 Message-ID: <20240826124106.3823-8-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240826124106.3823-1-laurent.pinchart+renesas@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move validation of the links between video devices and subdevs, performed manually in vsp1_video_streamon(), to the video device .link_validate() handler. This is how drivers should be implemented, but sadly, doing so for the vsp1 driver could break userspace, introducing a regression. This patch serves as an example to showcase usage of the .link_validate() operation, but should not be merged. Signed-off-by: Laurent Pinchart Reviewed-by: Tomi Valkeinen --- .../media/platform/renesas/vsp1/vsp1_video.c | 98 +++++++------------ 1 file changed, 37 insertions(+), 61 deletions(-) diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c index e728f9f5160e..14575698bbe7 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c @@ -45,51 +45,6 @@ * Helper functions */ -static struct v4l2_subdev * -vsp1_video_remote_subdev(struct media_pad *local, u32 *pad) -{ - struct media_pad *remote; - - remote = media_pad_remote_pad_first(local); - if (!remote || !is_media_entity_v4l2_subdev(remote->entity)) - return NULL; - - if (pad) - *pad = remote->index; - - return media_entity_to_v4l2_subdev(remote->entity); -} - -static int vsp1_video_verify_format(struct vsp1_video *video) -{ - struct v4l2_subdev_format fmt = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - }; - struct v4l2_subdev *subdev; - int ret; - - subdev = vsp1_video_remote_subdev(&video->pad, &fmt.pad); - if (subdev == NULL) - return -EINVAL; - - ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt); - if (ret < 0) - return ret == -ENOIOCTLCMD ? -EINVAL : ret; - - if (video->rwpf->fmtinfo->mbus != fmt.format.code || - video->rwpf->format.height != fmt.format.height || - video->rwpf->format.width != fmt.format.width) { - dev_dbg(video->vsp1->dev, - "Format mismatch: 0x%04x/%ux%u != 0x%04x/%ux%u\n", - video->rwpf->fmtinfo->mbus, video->rwpf->format.width, - video->rwpf->format.height, fmt.format.code, - fmt.format.width, fmt.format.height); - return -EPIPE; - } - - return 0; -} - static int __vsp1_video_try_format(struct vsp1_video *video, struct v4l2_pix_format_mplane *pix, const struct vsp1_format_info **fmtinfo) @@ -991,14 +946,6 @@ vsp1_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) mutex_unlock(&mdev->graph_mutex); - /* - * Verify that the configured format matches the output of the connected - * subdev. - */ - ret = vsp1_video_verify_format(video); - if (ret < 0) - goto err_stop; - /* Start the queue. */ ret = vb2_streamon(&video->queue, type); if (ret < 0) @@ -1087,14 +1034,43 @@ static const struct v4l2_file_operations vsp1_video_fops = { static int vsp1_video_link_validate(struct media_link *link) { - /* - * Ideally, link validation should be implemented here instead of - * calling vsp1_video_verify_format() in vsp1_video_streamon() - * manually. That would however break userspace that start one video - * device before configures formats on other video devices in the - * pipeline. This operation is just a no-op to silence the warnings - * from v4l2_subdev_link_validate(). - */ + struct v4l2_subdev_format fmt = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + struct v4l2_subdev *subdev; + struct media_entity *entity; + struct media_pad *remote; + struct vsp1_video *video; + int ret; + + if (is_media_entity_v4l2_video_device(link->source->entity)) { + entity = link->source->entity; + remote = link->sink; + } else { + entity = link->sink->entity; + remote = link->source; + } + + fmt.pad = remote->index; + + subdev = media_entity_to_v4l2_subdev(remote->entity); + ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt); + if (ret < 0) + return ret == -ENOIOCTLCMD ? -EINVAL : ret; + + video = to_vsp1_video(media_entity_to_video_device(entity)); + + if (video->rwpf->fmtinfo->mbus != fmt.format.code || + video->rwpf->format.height != fmt.format.height || + video->rwpf->format.width != fmt.format.width) { + dev_dbg(video->vsp1->dev, + "Format mismatch: 0x%04x/%ux%u != 0x%04x/%ux%u\n", + video->rwpf->fmtinfo->mbus, video->rwpf->format.width, + video->rwpf->format.height, fmt.format.code, + fmt.format.width, fmt.format.height); + return -EPIPE; + } + return 0; }