From patchwork Thu Aug 22 15:35:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13773783 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 AFDB01CBEBA for ; Thu, 22 Aug 2024 15:35:33 +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=1724340935; cv=none; b=PEueG4PBy6GfUIlYqph4/HL3stiaL8fPLZu/0omcJZmnYw7uzPqjxRWzx+eOri5zitOlcDBC94xH5Y4wI4nPfxUABwdkuHaxTSjBTisQSNo2Qrn1+zpPywwgoQ7H9AE51lnsj808VMFgYyabV6P77+T8yDNBwHyh79hokGEGipU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724340935; c=relaxed/simple; bh=IauAKKLLKtIroMXis0ibbuul9unL6FHlSgiNK/zpnac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DzRR/hbelusbfBs7y0pu0iY37gRUhtG7fGaRwpY9SxYVheRK9FJ/myorwy3/u/56shxdpN4WceLGEkS4NCf5HAIlhBR87I3Jb2DhXV7YYp5SRCMoEAYEtRNAQmbeBjk6GIbeUWUBzHY007sJDf9GaUg8j4TQMDjwLuB2k+Uortk= 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=ljINV/A+; 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="ljINV/A+" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0D3948D0; Thu, 22 Aug 2024 17:34:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724340868; bh=IauAKKLLKtIroMXis0ibbuul9unL6FHlSgiNK/zpnac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ljINV/A+wacBAFJaqIif+y5mZY5DRl9s+ghzAWOrzcteFJiRPktPRMOCXlMtPrPZ3 sOqy5QmOcJZ7jQeVsSnRXUFIE7RgyMGAG+tYOdv+INHDAaOXthNAEL1V/Of0grV+qO IDlHExE9DrcmloCdG/C6Y+z0BZbmMlv2So3Wb1HE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.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 v2 1/7] media: microchip-isc: Drop v4l2_subdev_link_validate() for video devices Date: Thu, 22 Aug 2024 18:35:21 +0300 Message-ID: <20240822153527.25320-2-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240822153527.25320-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240822153527.25320-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 --- .../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 Thu Aug 22 15:35:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13773785 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 8F9BF1CC88A; Thu, 22 Aug 2024 15:35:36 +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=1724340938; cv=none; b=hukNRBr9cFNvgICTmK8i3ZyARFK3WoRhElxobcn++zhyyhn6MNXEbtDeejkm41g00Sj+XVOlkJwGV5JRFTTMhGHgV4VjcdZLac2Zxh7plCSF52h+xOF8zv7zqWw91BsiPa1pKIZwy5krUD945X4D4GYbsuKM4fGDocQwnEjfXDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724340938; c=relaxed/simple; bh=g4UzTpjAkmH1/8Mi3biEb/L7TovlNwHywY7DzG7f2wA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tm3oUBA/kQItiCUwIfhgbSnVhY/LN04b6bxSL9XTkDxZMYX1HvMdvWuGUZ+hKHEqJpCOdabZq+c63Q6nZG+hM7gSZEuRqDwaO1+5brYQgUs0eG+AgBiKOhJ4/jcleD+Z7GsPardGZKMGImq7LEnFesB+7M9BL2Ci+0W6i4WzQRM= 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=CMu3/vJC; 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="CMu3/vJC" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E79FBB2A; Thu, 22 Aug 2024 17:34:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724340870; bh=g4UzTpjAkmH1/8Mi3biEb/L7TovlNwHywY7DzG7f2wA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CMu3/vJCap9NxISUHX76T7sb86mhw9cppcfHGK4Kfq3oCcT0Fs5ZKqxmg+xNrlYNp 7h3kpp95yRA6UbDdsKkLakgRMU+jp7xtXuHZ787PFTq3nACMjIznAWabsQRJxwYntl 5WrufxQtDSIySkDEmv1+0/1x6XCbe3fA938Z75N4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.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 v2 2/7] media: sun4i_csi: Implement link validate for sun4i_csi subdev Date: Thu, 22 Aug 2024 18:35:22 +0300 Message-ID: <20240822153527.25320-3-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240822153527.25320-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240822153527.25320-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 --- 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 Thu Aug 22 15:35:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13773786 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 0144A1CC8A3 for ; Thu, 22 Aug 2024 15:35:36 +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=1724340938; cv=none; b=fhXzF2DS3zWRdR5vnEos4+FD/SXCcQNbwhEltefFlhQufd6oH+oT9M0w+1KHYsyClJPF4TMQA9reU1cEkrSPFqKgZY25fkCDAKdSvkZ47M3m215hOy5PqLPEuRT3bGVgd1Dom5vl05GNH897Z+Ck3WZuU8olC2yLWcMqcqRuBqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724340938; c=relaxed/simple; bh=vWnDrPPWzy4Zl3mZqqk63elPGbjLXf+2JHhw+izsKsI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sICV0VzxLbEUCbuk5vVs1pVfJNBUeBK3P6gnPhJMdbK0xLGbb8uJzv1cQElQO/T1i76OVu62Q9W2etAVqAP7FxREIxYTiEGZ0gqPMxeD2aWSAUUKAmB9WFfwXqZCJcjg6hb7yCMISQjPPLGh/V1IDqD/8qk0rmOp6dRlp1xRs6A= 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=IRdqJ3hW; 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="IRdqJ3hW" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5C64F1225; Thu, 22 Aug 2024 17:34:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724340871; bh=vWnDrPPWzy4Zl3mZqqk63elPGbjLXf+2JHhw+izsKsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IRdqJ3hWMtrdatgdFksti2LbIJHasADUvVF4+ej6uijwiNdTxHWWb0wsTHhbcS9VB P+j7Wr7/BFq5K44yzuhqpuUd44IfaS//Y5TprBIT/cvah97+yFpnYo/2Jx+/10K87/ jR2bCOYsCjDviUFj269KB6hKZENGO/l4xy/7zg2M= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.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 v2 3/7] media: sun4i_csi: Don't use v4l2_subdev_link_validate() for video device Date: Thu, 22 Aug 2024 18:35:23 +0300 Message-ID: <20240822153527.25320-4-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240822153527.25320-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240822153527.25320-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 --- 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 Thu Aug 22 15:35:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13773787 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 8D5541CC88F for ; Thu, 22 Aug 2024 15:35:39 +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=1724340941; cv=none; b=ELLzP1BmIiQecrhYSAe+UJy6lkG6SyOX2sxnYaXCRfnzlOwiMOt4lJK2ReMI1BXXE62G/JMIRo2vxcvF+IbGRyE1+LjgAPL4vdOizDjNYJz1oxLD3Egus/WpzRZNJTATgz7/7GCiCVrjFyYxZmq+1eS/eCVjQl1qw6bxyWZUsus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724340941; c=relaxed/simple; bh=L6PW/jnfXa4+nyLEP2SbfgQft2F4O8LsNw4OqltCe/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XcWK+p1KYRu2UQd3FXoz6/b/rhwu3/3hNYP+DxTGn2yxm93i6rZICrll1ToeYEMtwKahuwhp/3ShQvRh9+nd9G7lhGhTTVJyZzFZ9MokxT5JKHasSN2MpQ8ICEEjBRhnfA+4xgB1mpjgx5PmFNYvopS/WCHwyPnYvMitKreqT1g= 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=ZO+znxHn; 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="ZO+znxHn" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BD3B51083; Thu, 22 Aug 2024 17:34:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724340872; bh=L6PW/jnfXa4+nyLEP2SbfgQft2F4O8LsNw4OqltCe/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZO+znxHn3QUDNjcqbTqpq5ynt1/dPTE2hJtRe/CxAqN3qTvmEwQOdWsZBUcucydF2 zwQ90wAJuGORKewyOgycAP7hT2SqYnLS6qLd08JcWiMHip3QwfkO30trLNUHD7FUgC KOC5ntjV3Uq7n6yQcih78sejBZ7AzISFoIdO0lEA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.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 v2 4/7] media: v4l2-subdev: Refactor warnings in v4l2_subdev_link_validate() Date: Thu, 22 Aug 2024 18:35:24 +0300 Message-ID: <20240822153527.25320-5-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240822153527.25320-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240822153527.25320-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. Signed-off-by: Laurent Pinchart --- 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 Thu Aug 22 15:35:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13773788 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 ED3E71CCB26 for ; Thu, 22 Aug 2024 15:35:39 +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=1724340941; cv=none; b=rGvfI8jX7CEs4HDDUhbz8drJYyj937oBh8FNrp2ushkN1bBgxzQZYQy6lnbUss0B+m5HBRl8KybcFw8rarkqIwOE7PUewKQ91xSewRXIpwQdG1M5+doc23jCkPV0bpAp7Q2unXddyMUYATLx3WnX/Z6Vkm9lQFnFz3PJal/c29U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724340941; c=relaxed/simple; bh=O2P51g86g0NtAz1plqGfT/xpwKLKBHpq60R2JY4duvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b/Sid4+TJRgYhYWIUsH1o0+uHv9zuzQsCZVjZzy/8AAk1Hvo4BJliSuNZr747QHiCPqod65NvwRhr4vayIOSewId0P+qRUmn81x1E/r3g9iLpBxSpYDA5EQccFfe5GJD536KUpPRBfi15mF/IPKgWF2zToCXf1E3L/PYY0Jb6/Q= 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=jzG+W6xr; 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="jzG+W6xr" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 246DF13D7; Thu, 22 Aug 2024 17:34:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724340874; bh=O2P51g86g0NtAz1plqGfT/xpwKLKBHpq60R2JY4duvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jzG+W6xrStY1HhevseHoQbexUec/kofzdU8jVTzf7M71mGvAjucImrDja0U7QUqob lqXwZCbTymk+LMw7xgvw1C91t4pIowiMnkxQk1KH6s1Jf6fqnBr70p/IerDx+g1Llp owhvWB8Kij81sORIuMlf5+MX5qxAcVsv4GkIIKXI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.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 v2 5/7] media: v4l2-subdev: Support hybrid links in v4l2_subdev_link_validate() Date: Thu, 22 Aug 2024 18:35:25 +0300 Message-ID: <20240822153527.25320-6-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240822153527.25320-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240822153527.25320-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 --- drivers/media/v4l2-core/v4l2-subdev.c | 40 +++++++++++++++++++++++---- include/media/v4l2-subdev.h | 6 ++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index d3196042d5c5..32ffebae4d17 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1450,13 +1450,43 @@ 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. */ + 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 Thu Aug 22 15:35:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13773789 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 623602C87A for ; Thu, 22 Aug 2024 15:35:42 +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=1724340943; cv=none; b=BslmVTJB9ogL2Xi2p8CKEm4gWLyBcCutclCW1AVkZz1aAFmqLQycgLNeylorPJdnMKKo8aT4Z3dIeL/eJhR+aHkVvnwp67l325WqNpl65tyHAyESFOrTVRKblqFttkTZtw54FRZji9nfQbJqWln4W0OU0gLL9R6PSfQrMyf9AuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724340943; c=relaxed/simple; bh=p/Vm87vlP9XYuQzQ5C0tpdtZ2+oVHTKxRgJwzH0dUr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L4OAZ2ybmlqz59pyiFY7f+UT9YaQFX4y0xja8Hkryl+4Uk4yVjgMXzTvPv5rxZGuH1E/2vUnbaf+DS19e5f6kfO8EAEGGovghJYef5eDSTrI9bOdXOZD/u8IuKw3/Iar6LLf0633pYEa8/PeEcg7yrhjBlK6bIRmJSIOsWv1zUI= 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=C5Y6LwFU; 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="C5Y6LwFU" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9AAA6124E; Thu, 22 Aug 2024 17:34:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724340875; bh=p/Vm87vlP9XYuQzQ5C0tpdtZ2+oVHTKxRgJwzH0dUr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C5Y6LwFU1u1StjdmNVaZltQmP14CgULLXc74z7wuLGgn/aV4yp5+cLLQSO3uImXuJ gu47UuKs40s/z7OuHVsjJCzFAKTls1Fyr4/XS4keOIMqUNMsOGZ0P1wMyUM1D7aWDc B29+Gm/+b+ZBGkHnv/eKLi4Avu/OUKBgVAWjE9rw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.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 v2 6/7] media: renesas: vsp1: Implement .link_validate() for video devices Date: Thu, 22 Aug 2024 18:35:26 +0300 Message-ID: <20240822153527.25320-7-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240822153527.25320-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240822153527.25320-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 applciations. Removing it would be a regression. Signed-off-by: Laurent Pinchart --- .../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 Thu Aug 22 15:35:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13773790 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 D214D1CC88F for ; Thu, 22 Aug 2024 15:35:42 +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=1724340944; cv=none; b=SY8SLb4YZjECDBpWznnC0E+86VMeO/bkHUipXgFeYvlhy25C+X6t2QulnPfuHYX6l0X4kAc+BeELKgp8Ey6xC0Du7U6jcekz4R3K79l/JVgrHyD8+doFJ7myckUWhoy5Ptp8GJLD6DmFR2pZfq7f6AdXIC58HOlyKJF9jbEJh+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724340944; c=relaxed/simple; bh=DkRVYKPomm0xFTm0bbXZFEt4UkD+SR8c0EiOkFYeAxo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nfee5Hv4petvl3LwMSb+zFcNdN5WEJjtVHbQ7D+OILmBOt9tCB3moYb2sxT2K0Zw4FcE6VG14bDPXvDIqBKwZRaNsb/6UKFQO2Nv+lkcJigp3JBao4cj74EqfMwfpdAjB6KRJQ0GY2szkyojQT4RouIEMrFJL0rG6TkOz2Um+QI= 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=Xdu4AsXQ; 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="Xdu4AsXQ" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 249F516CD; Thu, 22 Aug 2024 17:34:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724340877; bh=DkRVYKPomm0xFTm0bbXZFEt4UkD+SR8c0EiOkFYeAxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xdu4AsXQiLtxZCYKB/M+Pm5YQkWaj3ZIrWmm8JtnFE0czPx+8hLq5+kT/SuvrY+aL b03hpaRSPxIunZ5c4/Kry04xRXPuEbU0B7mjpA6s97JgTf1B5su4gKLD2LaTY689E6 r59upnPyirZrS/usL6Z8LtVqvvI5Q3f7YGxouH48= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.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 v2 7/7] [DNI] media: renesas: vsp1: Validate all links through .link_validate() Date: Thu, 22 Aug 2024 18:35:27 +0300 Message-ID: <20240822153527.25320-8-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240822153527.25320-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240822153527.25320-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 --- .../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; }