From patchwork Wed Jun 19 01:23:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13703308 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 8575210A03; Wed, 19 Jun 2024 01:24: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=1718760264; cv=none; b=M+9XHI6YnXL0JSkwry2+rmuSM4GRsDkk+SmNciYE4dldIuNePZmQmT5VCRBSGfsAJOyRoab5FrPRGyAlD4Wm0uKxJxCArZoT55F+F66hhe9kPMi4xFNXMFTdU0o258BMaq04OOVlFXH7q4Qr4SgFPTuI2TuUku/IUNtPTgAGbMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718760264; c=relaxed/simple; bh=IauAKKLLKtIroMXis0ibbuul9unL6FHlSgiNK/zpnac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LK3HgpyS8fMSUKUjGmbOk43AERqCX+GO1Piiny1736sk8bBwSnz2vPoKa+BwgYkCSHP1Wni3gNuR1semR8gmtPOPHZyGG4VvBMhozlU52q1sQzvIxaKW9KziZ1WtKJ5uami15vAvCf8hbTnsOLQUFpBLWB2I/9sd3zkqR/qnMdk= 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=jZXrWC6x; 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="jZXrWC6x" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 77DBA1011; Wed, 19 Jun 2024 03:24:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718760242; bh=IauAKKLLKtIroMXis0ibbuul9unL6FHlSgiNK/zpnac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jZXrWC6xlSYmHQpeNhr0lQnF5Yksug633wsWdZklbWw5vl2NpH2oKenyHfo9HKL7q msWtvZQHgBcgbDHXu5E0DaHwO8WsUGYFaeLGwachuTt2JeWZYnM4NcEmUNO0u7i6YH GTgUspc0KzQuXpYi9N4BpEXV2SoUCGoy/bko9FVs= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, Eugen Hristev , Maxime Ripard , Chen-Yu Tsai , Sakari Ailus , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Hans Verkuil Subject: [PATCH 1/8] media: microchip-isc: Drop v4l2_subdev_link_validate() for video devices Date: Wed, 19 Jun 2024 04:23:49 +0300 Message-ID: <20240619012356.22685-2-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240619012356.22685-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240619012356.22685-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 Wed Jun 19 01:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13703309 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 BDBC1B658; Wed, 19 Jun 2024 01:24:24 +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=1718760266; cv=none; b=Wp8xmcykRhaOsGRS3MllKojou55aK+J6U5ni9WNKS3u0B4t2VwKO15jh37NAY/rxWhZoFOk/WH4WS0xBAWOcAVmipJNL67UlNJP4bhBSFkvvf+xwFbPfE6hj/QB6vsxzrTvca9PylK5T99JZQUxS9t9JyJT7nInyZYLy1Ltrt6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718760266; c=relaxed/simple; bh=oN4ZSHaKeO11dckj3HGXkhAzH8nO8cjjZzc17znYEYY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bK9S4m5/K4v8jcxF4dZshOifZ51ZccPusXcPwGXCbhtgTh+GU+9YODOi5x8MLHlsGTT0K4HD8RmECIKejTCnM2+RPZgxYTtJq8aKKNzYGhZDvlfkqG7QDTuZvfM29OXIi0I8m4gYjlZ3aGu8eRclqVR+2rURYfkbzqyctMRXo/E= 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=BVowi7By; 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="BVowi7By" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D46C210CA; Wed, 19 Jun 2024 03:24:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718760244; bh=oN4ZSHaKeO11dckj3HGXkhAzH8nO8cjjZzc17znYEYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BVowi7ByD49qe9x1t41LGC/4II7n0yi/YSkzr2rU3ud7ZCiUc1VUhkbqJaHf0vsbQ wa/VsH8wShf8rt3zWt4piF3UsnILtAUyqR5QDc23nmUkubGoMY0VCfswIMr4kpc20S hSUgs2Du//kt3OEClhBMjNTFBemwaxMkN77Jj91g= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, Eugen Hristev , Maxime Ripard , Chen-Yu Tsai , Sakari Ailus , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Hans Verkuil Subject: [PATCH 2/8] media: sun4i_csi: Implement link validate for sun4i_csi subdev Date: Wed, 19 Jun 2024 04:23:50 +0300 Message-ID: <20240619012356.22685-3-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240619012356.22685-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240619012356.22685-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. 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 Wed Jun 19 01:23:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13703310 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 B2AAD6AB6; Wed, 19 Jun 2024 01:24:25 +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=1718760267; cv=none; b=OHN4WQnB59Cd/rUnS29mxcyg6Xt5Iu3q22Lv5J60i/yrN4UY/TH16g0THyKZulcfLzxlMvQzxNd/Uh7/TcKLRZYwWx6hNXnUfYGplbtOJnJUaUu0muzvNTr76e36/bfXe7PYmyw0g3cRPwLUdM/cINNkSv1ekiRSItS0TyEQHzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718760267; c=relaxed/simple; bh=JM3em1hFUj4zI1/nP0bY2hrcwLa2X9MF1PvvcpPLXcc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q4tAoBnli51jRe0rBqWK/RoROyyZr9EUdKfYbNs6d5ml04OyuePs3z0JFc3II6jerNxxV0cbYZZUlb6kgmrDIJPiPmP1BpHJqEjFlIvSr7NMfemKfs3xNuFrXxhuOjFAqc6e3OF5m5+qUMFZkE8sbU2ITEZQFwGarkcwZjbXLvU= 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=g7btRBOP; 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="g7btRBOP" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 28FFA11CF; Wed, 19 Jun 2024 03:24:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718760245; bh=JM3em1hFUj4zI1/nP0bY2hrcwLa2X9MF1PvvcpPLXcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g7btRBOP7Qo7KDi5kNpeXqCceRk2C0MaN5onY5kWVkWf2P3I4Bi7wt46XPIkpLJgY O4Blty4LGdogdUMc8Co1Lh1/8YbrC5cqBQakvkr9JmKLcLMdD57i6L08cgIZeKgBo0 P11I7xMEK75zMBC0vB9sgD4XQjxWyQHjRAGBf22M= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, Eugen Hristev , Maxime Ripard , Chen-Yu Tsai , Sakari Ailus , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Hans Verkuil Subject: [PATCH 3/8] media: sun4i_csi: Don't use v4l2_subdev_link_validate() for video device Date: Wed, 19 Jun 2024 04:23:51 +0300 Message-ID: <20240619012356.22685-4-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240619012356.22685-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240619012356.22685-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 Wed Jun 19 01:23:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13703311 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 A83A5EAF9; Wed, 19 Jun 2024 01:24:27 +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=1718760269; cv=none; b=RjZqmWykEHYrutbA5c9u2vJ6tPvER1ibE3VJ/+UZwU1utbGqSPFyWHNWy0Rh1Bgk03hZDxkixHiBqVdNDr+t4MqCU5n+wN6SVdlOKno7guf6xqG1xp+6QvWhYZdVv0P0fKM2Nr20E98IgeLCwgzC4Teu//6PND4uA1QHS9OZHY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718760269; c=relaxed/simple; bh=GebboEQBPNN6stBSyIeo/u+bZsCpoRVYWm0IsmkmX2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V48IT5ecINQwUOhRJSNy1MtHtnkg5+JjGAvDD9tUD8HcWlsRgW1OShtZc7nc/+qd/w4qvdAAfkNNa7WFstirr9AhsVu5kf2kdyg/ywarTv+FeJkIzSXR7UxV/wIgCAZl9ZbQfiM1FNaqHtYVy3bHxgLLNCZLWxb8lGI2lsY8Trw= 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=SXVNE4PA; 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="SXVNE4PA" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 73294F89; Wed, 19 Jun 2024 03:24:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718760246; bh=GebboEQBPNN6stBSyIeo/u+bZsCpoRVYWm0IsmkmX2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXVNE4PALmS+2/4h2cUercuGY/blGsocT1V8aXhkFV+mZGxDrEAPDhUgN/6DwcijD v1k+BJMVXizFpH+X8p47hU3HElgcN7+pwdOor0HTTSjrdKR8BIn1PDFOtEPJUNmTUT hAilrrz7qbG1FYoi1qJIf90Y8eGeiskCLrp1D2sA= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, Eugen Hristev , Maxime Ripard , Chen-Yu Tsai , Sakari Ailus , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Hans Verkuil Subject: [PATCH 4/8] media: v4l2-subdev: Refactor warnings in v4l2_subdev_link_validate() Date: Wed, 19 Jun 2024 04:23:52 +0300 Message-ID: <20240619012356.22685-5-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240619012356.22685-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240619012356.22685-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() in this case to make sure that new offenders won't be introduced. Signed-off-by: Laurent Pinchart --- 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 4f71199bf592..2d5e39c79620 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1451,11 +1451,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(!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 Wed Jun 19 01:23:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13703312 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 939EA6FB8; Wed, 19 Jun 2024 01:24:28 +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=1718760270; cv=none; b=Fz6aLC22w1flkoha8FBcRKbqK2Za6vZ9fONKUwKxJo7jCUL/babNPYb7OHSAyaKiZVOWkw6oZeu6S7dCtLx+mUEr+wrlhumHv3OZLmieg1DxIiBkNjhBFAk1RVl7gaVXnw9IMZPwdzZmNVQ+1YLuYTOaK68pmX8foOGRf7FgBNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718760270; c=relaxed/simple; bh=YTxAEnF666VLTPV6Ru8lkNDk/zUjMbICv0YvCoEr+Z0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a+0wkF3Q8tsyTWJB8ZsnVruq5w3OnVlcKr4KFhPVcwYaz13odvGaBuTrK5mz5xSlZsRQr5CRa9d/MqPZc3U9yjoF/6+I7kcgdyp62fLlJnWn3mP0dKEMXwEwfnMPTle9hFL/G+Y9YraZo35eEKu4JWwt5GS3Wdbvh4z77LQncxM= 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=GoTfb3CK; 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="GoTfb3CK" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C0A271207; Wed, 19 Jun 2024 03:24:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718760248; bh=YTxAEnF666VLTPV6Ru8lkNDk/zUjMbICv0YvCoEr+Z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GoTfb3CKX3t+vFVKb2qRjkFRKmBxuV/LIDAFsYpXKacRWNAjna5rAYo6sZZxY5rXH uMLQaE3Yy5vGcOkS4IehVnGN5IrbhPLX5T6Mvi6783RUBTD8V+4Xe/XJVSortEOvjp HW5OAQThlFdSJmhNu9kCRNGz75a0hcG7i2xz1Z/8= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, Eugen Hristev , Maxime Ripard , Chen-Yu Tsai , Sakari Ailus , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Hans Verkuil Subject: [PATCH 5/8] media: v4l2-subdev: Support hybrid links in v4l2_subdev_link_validate() Date: Wed, 19 Jun 2024 04:23:53 +0300 Message-ID: <20240619012356.22685-6-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240619012356.22685-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240619012356.22685-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 2d5e39c79620..e1e1333cfb0a 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1458,13 +1458,43 @@ int v4l2_subdev_link_validate(struct media_link *link) if (WARN_ON(!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 1b74e037e440..731be85a7af1 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 Wed Jun 19 01:23:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13703313 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 9F151AD32; Wed, 19 Jun 2024 01:24:30 +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=1718760272; cv=none; b=jGAlI9qse5FUlDHQMKVjccmaWM+v+kJZmR898sNDCp3w7ZuIml5s1TmgIbz90naIlrG0h/IUC5UNjydigXfl26s2Bd85PfBVo2huUqfWY8pCjRMzQl0dqoWxH6121oa4+jDWoJAruIxRAopAWzKyyrz87wTHQ+iG5VOH0OPchvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718760272; c=relaxed/simple; bh=BxwFc+luxvMoNAtbVbMthJtaEL72gSDIum8h9l1swBU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dgbtvVVgeBrAOIDPtPfnzOfPXCXpcqJVbOkLsH6qfdP0B0ptXcxoEceBwdP2vdUTstG1jPeOVl+M0KqcKnrpuqfUYD9obzKaWLvkb2199R3pG0+Ci2lccA/nMldGUUfy92SIjs8in8pjeVHnj1r+oXP/+e/I+67HRdjNhmTt1RY= 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=l/AsMhOE; 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="l/AsMhOE" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1463C121A; Wed, 19 Jun 2024 03:24:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718760249; bh=BxwFc+luxvMoNAtbVbMthJtaEL72gSDIum8h9l1swBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l/AsMhOEv81G6pS2xsbdnkCId3X8AKNqWyr9q7M21fEerbEjhgcVHFYNXq0GLCARZ 2KaVQh2B68L5gg9j2otoa3iokH8jwxjFoXLer7MsUQ2mnwLD1tvnM2dhrRJD6JCi0t VDgkltX83vglus607GXzyEje1I1YnWaGMU2sftK0= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, Eugen Hristev , Maxime Ripard , Chen-Yu Tsai , Sakari Ailus , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Hans Verkuil Subject: [PATCH 6/8] media: renesas: vsp1: Print debug message to diagnose validation failure Date: Wed, 19 Jun 2024 04:23:54 +0300 Message-ID: <20240619012356.22685-7-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240619012356.22685-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240619012356.22685-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 When formats don't match between a subdev and a connected video device, starting streaming returns an error without giving the user any indication as to what went wrong. To help debugging pipeline misconfigurations, add a debug message that indicates the cause of the failure. Signed-off-by: Laurent Pinchart --- drivers/media/platform/renesas/vsp1/vsp1_video.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/renesas/vsp1/vsp1_video.c b/drivers/media/platform/renesas/vsp1/vsp1_video.c index 5a9cb0e5640e..d6f2739456bf 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c @@ -78,8 +78,14 @@ static int vsp1_video_verify_format(struct vsp1_video *video) if (video->rwpf->fmtinfo->mbus != fmt.format.code || video->rwpf->format.height != fmt.format.height || - video->rwpf->format.width != fmt.format.width) + 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 -EINVAL; + } return 0; } From patchwork Wed Jun 19 01:23:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13703314 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 6EF286FB8; Wed, 19 Jun 2024 01:24:31 +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=1718760272; cv=none; b=n+TS/ezjwvHTw75BUmnd2TvIbv3rq8R5ts9iqHi7FG8goN8YNyhaEDdhGigylVBu+6sL9mm4fFILQIfKgY9mRsmgBDDQ/NR+Tx1JWqTgFYeRj6Kxzb54bvoj+rKKQVIfALoXDOIyTFeqlnSg2imwFloLOie5lmyjfzgGQrU2vhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718760272; c=relaxed/simple; bh=urL8luN8cOSRyuyB24bVfFlprB0iZWyVX1WCfEWmGUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jf3sUZYaIwppYdU/GlWL7wiZ0WkwXwFeyZFml5tbsBdoVwp2BhO99XnwVZt6nXYs8D6dXVJzWQ53xzn5t+wFVDiTfyy1PgXccxmMWZjMDZmo1j3GCw/vJ9vDuikjZdvf+hruvqQPYdLf3F+D+dthrr7Lt1NquLKMGB27kqCwukM= 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=chLkp+bp; 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="chLkp+bp" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6276F1254; Wed, 19 Jun 2024 03:24:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718760250; bh=urL8luN8cOSRyuyB24bVfFlprB0iZWyVX1WCfEWmGUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=chLkp+bp8AegfzWymPhfy7cUXfuHGAx31Vkk/WM2RfYQ3Nfiig5j0ylDn9xbrveMq wnSJXHEfAIPfJSA32hf6oncKVkROa9Xkk9ksZPUTOEhfkRu+QJHL447xGLGJn/+pHj JZoNhCkASf6XlkEyCadVj6sFEUOr4oNkh4D6uQ+U= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, Eugen Hristev , Maxime Ripard , Chen-Yu Tsai , Sakari Ailus , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Hans Verkuil Subject: [PATCH 7/8] media: renesas: vsp1: Implement .link_validate() for video devices Date: Wed, 19 Jun 2024 04:23:55 +0300 Message-ID: <20240619012356.22685-8-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240619012356.22685-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240619012356.22685-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 d6f2739456bf..88806eddc839 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_video.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_video.c @@ -1151,6 +1151,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 */ @@ -1285,6 +1306,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 Wed Jun 19 01:23:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13703315 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 7FA71125C1; Wed, 19 Jun 2024 01:24: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=1718760275; cv=none; b=t5fgWEBAX4LCrw8evbVQF0RcRL/PX8s6dmPcpkyAi8U8yiE/PSNt1BCephBtS78/d09WZ1gtKaffqf4JvU6C2gXDckfKls1ixcV7S0vU7lYUGIUnPO002ZrlpU98PUzphMcR2Dn5QjqXYfwpy3UHTnJcd48TEisqRk5AJHGExVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718760275; c=relaxed/simple; bh=fhKbz6+wr6roy/hhRss/GWu3sliCltbVi4WtlztKcVQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JB8Cu3LJXrHrUyX0BDNaDJrGKQye1se59LMEHMusqjvEF0E6Ltmuxg2qRNSxb/944V5NLlVoOfSJXmT2g79QmoyRCT7H8C8FpzTjDQpANUoVUtBi2spkbMEsfTXpFzm8mMOiKXO4E0HCh6nsWwnLEOLWue2Q9+j1hymFgE/J9iY= 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=DTGoHKaz; 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="DTGoHKaz" Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AD154122D; Wed, 19 Jun 2024 03:24:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718760251; bh=fhKbz6+wr6roy/hhRss/GWu3sliCltbVi4WtlztKcVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DTGoHKazYQqmCsRVL4cE9FSxdDvhjpq8cnvnVDUlmPdOL7kbFX49A8mUfR4XgM65l 5j1l2E23ImfhUFXOTSkaTCm9sxnVxb0AwOM0TTrJFIB1P4bLcEX0CBpdY6Xnh2m39i Kym2edd9xjz7Us2KYjG3sbe/uhVmIOMr2O4eER64= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, Eugen Hristev , Maxime Ripard , Chen-Yu Tsai , Sakari Ailus , Kieran Bingham , Tomi Valkeinen , Jacopo Mondi , Hans Verkuil Subject: [PATCH 8/8] [DNI] media: renesas: vsp1: Validate all links through .link_validate() Date: Wed, 19 Jun 2024 04:23:56 +0300 Message-ID: <20240619012356.22685-9-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240619012356.22685-1-laurent.pinchart+renesas@ideasonboard.com> References: <20240619012356.22685-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 88806eddc839..0fd78c22b635 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 -EINVAL; - } - - return 0; -} - static int __vsp1_video_try_format(struct vsp1_video *video, struct v4l2_pix_format_mplane *pix, const struct vsp1_format_info **fmtinfo) @@ -1061,14 +1016,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) @@ -1157,14 +1104,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 -EINVAL; + } + return 0; }