Show a patch.

GET /api/1.1/patches/20994/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 20994,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20994/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20994/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240822153527.25320-6-laurent.pinchart+renesas@ideasonboard.com>",
    "date": "2024-08-22T15:35:25",
    "name": "[v2,5/7] media: v4l2-subdev: Support hybrid links in v4l2_subdev_link_validate()",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": false,
    "hash": "9791e4f65376d19a049cb4738c0d6d638eaac578",
    "submitter": {
        "id": 204,
        "url": "https://patchwork.libcamera.org/api/1.1/people/204/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart+renesas@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20994/mbox/",
    "series": [
        {
            "id": 4533,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4533/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4533",
            "date": "2024-08-22T15:35:20",
            "name": "media: v4l2: Improve media link validation",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4533/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20994/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20994/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9695AC32C2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 22 Aug 2024 15:35:45 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 17705633DC;\n\tThu, 22 Aug 2024 17:35:45 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BC363633D5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 22 Aug 2024 17:35:37 +0200 (CEST)",
            "from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 246DF13D7;\n\tThu, 22 Aug 2024 17:34:34 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"jzG+W6xr\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1724340874;\n\tbh=O2P51g86g0NtAz1plqGfT/xpwKLKBHpq60R2JY4duvo=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=jzG+W6xrStY1HhevseHoQbexUec/kofzdU8jVTzf7M71mGvAjucImrDja0U7QUqob\n\tlqXwZCbTymk+LMw7xgvw1C91t4pIowiMnkxQk1KH6s1Jf6fqnBr70p/IerDx+g1Llp\n\towhvWB8Kij81sORIuMlf5+MX5qxAcVsv4GkIIKXI=",
        "From": "Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Chen-Yu Tsai <wens@csie.org>, Eugen Hristev <eugen.hristev@collabora.com>,\n\tHans Verkuil <hverkuil-cisco@xs4all.nl>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tMaxime Ripard <mripard@kernel.org>, Sakari Ailus <sakari.ailus@iki.fi>,\n\tTomi Valkeinen <tomi.valkeinen@ideasonboard.com>,\n\tlinux-renesas-soc@vger.kernel.org, linux-sunxi@lists.linux.dev",
        "Subject": "[PATCH v2 5/7] media: v4l2-subdev: Support hybrid links in\n\tv4l2_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>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The v4l2_subdev_link_validate() helper function is meant to be used as a\ndrop-in implementation of a V4L2 subdev entity .link_validate() handler.\nIt supports subdev-to-subdev links only, and complains if one end of the\nlink is not a subdev. This forces drivers that have video output devices\nconnected to subdevs to implement a custom .link_validate() handler,\ncalling v4l2_subdev_link_validate() for the subdev-to-subdev links, and\nperforming manual link validation for the video-to-subdev links.\n\nVideo devices embed a media entity, and therefore also have a\n.link_validate() operation. For video capture devices, the operation\nshould be manually implemented by drivers for validate the\nsubdev-to-video links. For video output devices, on the other hand, that\noperation is never called, as link validation is performed in the\ncontext of the sink entity.\n\nAs a result, we end up forcing drivers to implement a custom\n.link_validate() handler for subdevs connected to video output devices,\nwhen the video devices provide an operation that could be used for that\npurpose.\n\nTo improve that situation, make v4l2_subdev_link_validate() delegate\nlink validation to the source's .link_validate() operation when the link\nsource is a video device and the link sink is a subdev. This allows\nbroader usage of v4l2_subdev_link_validate(), and simplifies drivers by\nmaking video device link validation easy to implement in the video\ndevice .link_validate(), regardless of whether the video device is an\noutput device or a capture device.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>\n---\n drivers/media/v4l2-core/v4l2-subdev.c | 40 +++++++++++++++++++++++----\n include/media/v4l2-subdev.h           |  6 ++++\n 2 files changed, 41 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c\nindex d3196042d5c5..32ffebae4d17 100644\n--- a/drivers/media/v4l2-core/v4l2-subdev.c\n+++ b/drivers/media/v4l2-core/v4l2-subdev.c\n@@ -1450,13 +1450,43 @@ int v4l2_subdev_link_validate(struct media_link *link)\n \tif (WARN_ON_ONCE(!is_media_entity_v4l2_subdev(link->sink->entity)))\n \t\treturn -EINVAL;\n \n-\tif (!is_media_entity_v4l2_subdev(link->source->entity)) {\n-\t\tpr_warn_once(\"source of link '%s':%u->'%s':%u is not a V4L2 sub-device, driver bug!\\n\",\n-\t\t\t     link->source->entity->name, link->source->index,\n-\t\t\t     link->sink->entity->name, link->sink->index);\n-\t\treturn 0;\n+\t/*\n+\t * If the source is a video device, delegate link validation to it. This\n+\t * allows usage of this helper for subdev connected to a video output\n+\t * device, provided that the driver implement the video output device's\n+\t * .link_validate() operation.\n+\t */\n+\tif (is_media_entity_v4l2_video_device(link->source->entity)) {\n+\t\tstruct media_entity *source = link->source->entity;\n+\n+\t\tif (!source->ops || !source->ops->link_validate) {\n+\t\t\t/*\n+\t\t\t * Many existing drivers do not implement the required\n+\t\t\t * .link_validate() operation for their video devices.\n+\t\t\t * Print a warning to get the drivers fixed, and return\n+\t\t\t * 0 to avoid breaking userspace. This should\n+\t\t\t * eventually be turned into a WARN_ON() when all\n+\t\t\t * drivers will have been fixed.\n+\t\t\t */\n+\t\t\tpr_warn_once(\"video device '%s' does not implement .link_validate(), driver bug!\\n\",\n+\t\t\t\t     source->name);\n+\t\t\treturn 0;\n+\t\t}\n+\n+\t\t/* Avoid infinite loops. */\n+\t\tif (WARN_ON(source->ops->link_validate == v4l2_subdev_link_validate))\n+\t\t\treturn -EINVAL;\n+\n+\t\treturn source->ops->link_validate(link);\n \t}\n \n+\t/*\n+\t * If the source is still not a subdev, usage of this helper is a clear\n+\t * driver bug.\n+\t */\n+\tif (WARN_ON(!is_media_entity_v4l2_subdev(link->source->entity)))\n+\t\treturn -EINVAL;\n+\n \tsink_sd = media_entity_to_v4l2_subdev(link->sink->entity);\n \tsource_sd = media_entity_to_v4l2_subdev(link->source->entity);\n \ndiff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h\nindex bd235d325ff9..8daa0929865c 100644\n--- a/include/media/v4l2-subdev.h\n+++ b/include/media/v4l2-subdev.h\n@@ -1250,6 +1250,12 @@ int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,\n  * calls v4l2_subdev_link_validate_default() to ensure that\n  * width, height and the media bus pixel code are equal on both\n  * source and sink of the link.\n+ *\n+ * The function can be used as a drop-in &media_entity_ops.link_validate\n+ * implementation for v4l2_subdev instances. It supports all links between\n+ * subdevs, as well as links between subdevs and video devices, provided that\n+ * the video devices also implement their &media_entity_ops.link_validate\n+ * operation.\n  */\n int v4l2_subdev_link_validate(struct media_link *link);\n \n",
    "prefixes": [
        "v2",
        "5/7"
    ]
}