From patchwork Mon Nov 13 10:17:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13453761 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 D22761C2BC for ; Mon, 13 Nov 2023 10:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sgvsI97f" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA305D4C for ; Mon, 13 Nov 2023 02:17:14 -0800 (PST) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8654C2C6; Mon, 13 Nov 2023 11:16:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1699870608; bh=3iURt+JSzPBRtlVuAwtf0I5lk4DAgDFb46EdfGMGCek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sgvsI97fNq0SLdfmx07WqkPG8j+zvcOGeVdm6lDhOzCJC7HUlhicCRDS3Izjr9X6v u7dt45EtkjUIPtpgRYPffWsYWyE+XOJawfeLpg2QURrdZKfZAMRM581BNrFwzNQqOf tlGYGYTnapbNlAL3WYDzO0d3X8MfO/q6lBRyg9ls= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Tomi Valkeinen , Sakari Ailus , Kieran Bingham Subject: [PATCH v1 1/2] media: v4l2-subdev: Drop unreacheable warning Date: Mon, 13 Nov 2023 12:17:17 +0200 Message-ID: <20231113101718.6098-2-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231113101718.6098-1-laurent.pinchart+renesas@ideasonboard.com> References: <20231113101718.6098-1-laurent.pinchart+renesas@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The v4l2_subdev_link_validate_get_format() function warns if the pad given as argument belongs to a non-subdev entity. This can't happen, as the function is called from v4l2_subdev_link_validate() only (indirectly through v4l2_subdev_link_validate_locked()), and that function ensures that both ends of the link are subdevs. Signed-off-by: Laurent Pinchart Reviewed-by: Tomi Valkeinen --- drivers/media/v4l2-core/v4l2-subdev.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index be86b906c985..67d43206ce32 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1184,14 +1184,6 @@ v4l2_subdev_link_validate_get_format(struct media_pad *pad, u32 stream, struct v4l2_subdev *sd; int ret; - if (!is_media_entity_v4l2_subdev(pad->entity)) { - WARN(pad->entity->function != MEDIA_ENT_F_IO_V4L, - "Driver bug! Wrong media entity type 0x%08x, entity %s\n", - pad->entity->function, pad->entity->name); - - return -EINVAL; - } - sd = media_entity_to_v4l2_subdev(pad->entity); fmt->which = V4L2_SUBDEV_FORMAT_ACTIVE; From patchwork Mon Nov 13 10:17:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13453762 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 0C82B1C699 for ; Mon, 13 Nov 2023 10:17:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WcXnk8c8" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95095D7C for ; Mon, 13 Nov 2023 02:17:16 -0800 (PST) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 303D9A68; Mon, 13 Nov 2023 11:16:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1699870610; bh=uBstu39/m6HZY+nV4D5uJFdJ0LhVZSFAKDyVMsODvQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WcXnk8c8ZKRsdgo7rDAT61cFE56z35j7nk02c+Oxeoy7RHxlQsOvPfZwBFccQL5M1 ttuJG8H14uHVVRci7udQ/PMDB5Gjv9/ad8qvmaSukafgUDB8J+aY0UjBc5XTEmikc6 BPkAtTHgC46/kZzydBneX2tSFni82BsFo14bRsP0= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Tomi Valkeinen , Sakari Ailus , Kieran Bingham Subject: [PATCH v1 2/2] media: v4l2-subdev: Relax warnings in link validation Date: Mon, 13 Nov 2023 12:17:18 +0200 Message-ID: <20231113101718.6098-3-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231113101718.6098-1-laurent.pinchart+renesas@ideasonboard.com> References: <20231113101718.6098-1-laurent.pinchart+renesas@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Before v6.3, the v4l2_subdev_link_validate() helper would ignore links whose source was a video device and sink a subdev. The helper was (and still is) used by drivers in such cases, in particular for subdevs with multiple sink pads, some connected to video devices and some to other subdevs. Then, commit a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()") assumed the entities on the two sides of a link are both subdevs, and caused crashes in drivers that use the helper with subdev sink pads connected to video devices. Commit 55f1ecb11990 ("media: v4l: subdev: Make link validation safer"), merged in v6.4, fixed the crash by adding an explicit check with a pr_warn_once(), mentioning a driver bug. Links between a subdev and a video device need to be validated, and v4l2_subdev_link_validate() can't handle that. Drivers typically handle this validation manually at stream start time (either in the .streamon() ioctl handler, or in the .start_streaming() vb2 queue operation), instead of implementing a custom .link_validate() handler. Forbidding usage of v4l2_subdev_link_validate() as the .link_validate() handler would thus force all subdev drivers that mix source links to subdev and video devices to implement a custom .link_validate() handler that returns immediately for the video device links and call v4l2_subdev_link_validate() for subdev links. This would create lots of duplicated code for no real gain. Instead, relax the check in v4l2_ctrl_modify_range() to ignore links from a video device to a subdev without printing any warning. Fixes: a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()") Signed-off-by: Laurent Pinchart --- drivers/media/v4l2-core/v4l2-subdev.c | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 67d43206ce32..b00be1d57e05 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1356,15 +1356,31 @@ int v4l2_subdev_link_validate(struct media_link *link) struct v4l2_subdev *source_sd, *sink_sd; struct v4l2_subdev_state *source_state, *sink_state; bool states_locked; + bool is_sink_subdev; + bool is_source_subdev; 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", - link->source->entity->name, link->source->index, - link->sink->entity->name, link->sink->index); + is_sink_subdev = is_media_entity_v4l2_subdev(link->sink->entity); + is_source_subdev = is_media_entity_v4l2_subdev(link->source->entity); + + if (!is_sink_subdev || !is_source_subdev) { + /* + * Do not print the warning if the source is a video device and + * the sink a subdev. This is a valid use case, to allow usage + * of this helper by subdev drivers that have multiple sink + * pads, some connected to video devices and some connected to + * other subdevs. The video device to subdev link is typically + * validated manually by the driver at stream start time in such + * cases. + */ + if (!is_sink_subdev || + !is_media_entity_v4l2_video_device(link->source->entity)) + pr_warn_once("%s of link '%s':%u->'%s':%u is not a V4L2 sub-device, driver bug!\n", + !is_sink_subdev ? "sink" : "source", + link->source->entity->name, + link->source->index, + link->sink->entity->name, + link->sink->index); return 0; }