Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795975680; b=VwLdm9DGkTETYN/DqMb3KO/cgFfQ+dvEFQFKKCG2PAbsnhCECZh1vKEjwQaUAzE2Estq NNUva3NuLMQcrZDpuvfuUgbYaZPbCeIAHYS30CrwrEeWv5bCMB3rj+fVVnpydFf38I33t 34xwn7G0dhhU4oYChBliT/npGufWYPzxBl3SSXGGR6EDMoiUqKQxCjSJPMQVgh7JGfjqe Vf8cIwUJ6mePNt2KDzNePd/llSDEffsw/LXThzBesit7bRAtjFpMUJPbh96cyth1vP28e 8ShIA0ywrWm6oDv+KgeO67c34JA6ihhI9RoY9m3pkrG5zgFr2Iz2jabLp2Ddcd2AFLQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795975680; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=+rUQlrJM6V1zh1SgadBAYvYIUz0WD+g8jepXHHq1/VM=; b=0KF+88hsiPfoO0M8dAiHWjXvoigBHIknQQcV5OQF2nQAjamcPlItVedS2SVXBKeXVC2e EbUvER7c2Ef5zmmbPJ5NkTsMI2yIuNAOY29jSvWBelu3ogZralKW5CV2Fo8nys6a142j9 t861yLGGg2sjs70SQHvoo707aSGkiYbXpDenfsr6r6o5udSErAzmiJLesIfdpSQ44NMbu QsuNCRaVdKJenqIRPCRAyta72GSRxtsmXHpcmr9eT8eb13YmPqjQ59tFdqFhwAJaVXlkm PHO/x2mJ3Cupg17APy1TJmLWJcQZ3y46aHvZCx6UlOKPZ5lii3eIUStQJpMqTTiMpUA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zCxABgbW; arc=none smtp.remote-ip=209.85.218.52 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 862CE606A682 for ; Sun, 29 Nov 2026 18:08:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 862CE606A682 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=zCxABgbW Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-c50e26763a4so645416266b.1 for ; Sun, 29 Nov 2026 10:08:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795975679; x=1796580479; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+rUQlrJM6V1zh1SgadBAYvYIUz0WD+g8jepXHHq1/VM=; b=zCxABgbWf3DAb9t94YXyadnpG4O5hpacZIN1Py5k2hUesGMiZ4uLIxhYYimex/8Dvp cYbclwWbfCUqi+QFbJfUnW/d2l+4IM/0hQNQS2+mwVNE6sIj1MXjF8WwJmQEigciUtsm TZ/Po9SCiGbqOrVxl2kHm1YCOCy/JzbwJGiUKnicKY3ljJSVoLgeReFzmMPlU0VMhagL +XY4xfUvAzUhps9iG8tX0O1F6HR6zPJK2BYxZYb8WVzaM9xaR41sAHFnLMlP1WfyWZpa QOSoogPlDDtULknNV/z97gDOaXPYCzg5ukuRzeCNi+qq/CowLNq/ctsFbdv9Iongy809 bTjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795975679; x=1796580479; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+rUQlrJM6V1zh1SgadBAYvYIUz0WD+g8jepXHHq1/VM=; b=EL5q1ThzggnUWsbPnFsQ9ml7fU6JDhj+DzJzJ9joFfnrYkQvpGCIrPpSFudpIX+IMl l1zXCKkMz9N0BRU0ABUXmCMGTKsaMJfek0osgbiiu2SCXaAzn7Nf/q65XazeIAp76B15 GoG8itqbuGwKkWDSCEfQ8uc1Dhb4kksut+sP3dLxdd5x9MYph0x65P52zivlb56XJbYc x5ogKJpMA3GSjbEd0C0izidQ4TfJnC5evCvFZohRsFWZWQrk86oylvmSKoIB06xdvi4B edpBsV0Gmse6dWBDinBlnlHQwJJOr/WIjbLRpBtPMFxQAjLzDfY0vuQV4v9NzpYGmjxp +DGw== X-Forwarded-Encrypted: i=1; AL+hErHtXTECAapHRq29XCUwIT0GcUDl6CHpPlnohnnkR+unOAI6PPwiMuf0VKtbpUXhWgq37ngNge5jycZb+g==@vger.kernel.org X-Gm-Message-State: APuU4Z8WleMTs0QdinRH65AnqLaY9Hrcf5fwcPwl+WDL6YFHcRSD64o+ SLm5RlJ3qVbKMyhCjrFTQJ3dZ39vIRt6Howm3tK4lj4Kg3GzExYOnEPs X-Gm-Gg: AZFdTZdrIJx7TU6mwRRkLG8l+VL7DlT4G/jTlAutC698X0kWq0wVhLZemfCgrsLD16G iQVzE+5hjn6+jFwa2XXGRfc5I7HPcFXBFc8bmv3yLLOhRkg12++GPQTgcX0nAz0A5U8EqcCK6jy FeJS9sygNamM9xio7CdTSNGP8P+qjn6RRD/ZLZlODRLgVpH6qFIW8fHV08iGOF7ONkHZ6XBarnG 3WQaOsljOkNdNrewZUOE0+oe/FaZDb9uaiVul6dnKETyZcVlP0jled+h918lh7Uimv0XrS2jl3m sA84amSoXuuW0YvDov4o/rNYeVOZVZ5fgg12+dmVzbD4xJzok0Lizbgw4rU9bIrLNWlXU8EecMs acJCDwd29KmYmiWoZH5BiNK9lE+HOupGgYNUXWwNvzXmGLoEYO2ylyirX04dmiAkMLFeO+wQgkh 0vSX/v0iH4v83YkI5N46MPSGBL/IIGcxXW1NJWlt6ZECFFwZgQr2rIyF+ZYNw2LkBqz32CrUkl2 doxlzp1oPiX8Z+BWGgaqhaZhyXEqjxQqVAsK8MVlz9d6egJS24Hm+1ZnqDHMnef2OE3MapDglor l3bIiSDv+9zRMJSW+vR8CUQgs4KcSXRW8w6y89NsBn3MtUhb3V6WhwqnLRjtllnyPBAUW9NskZx TZJ9F2K3AQA== X-Received: by 2002:a17:907:6091:b0:c3e:f39b:2286 with SMTP id a640c23a62f3a-c513a25e36bmr2530463966b.0.1795975678872; Sun, 29 Nov 2026 10:07:58 -0800 (PST) Received: from xeon ([188.163.112.54]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c513ae8ce16sm1061518266b.37.2026.11.29.10.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 10:07:57 -0800 (PST) From: Svyatoslav Ryhel To: Mauro Carvalho Chehab , Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Luca Ceresoli , Greg Kroah-Hartman , Svyatoslav Ryhel , Hans Verkuil , Mikko Perttunen Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH v2 11/15] media: tegra-video: video: Resolve video device via media graph on notifications Date: Sun, 29 Nov 2026 20:07:18 +0200 Message-ID: <20261129180722.142186-12-clamor95@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261129180722.142186-1-clamor95@gmail.com> References: <20261129180722.142186-1-clamor95@gmail.com> X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Walk downstream from the notifying subdevice along source pad links via find_pipeline_video_device() to locate the associated video_device and channel instead of relying on v4l2_get_subdev_hostdata(sd), and filter notifications to V4L2_EVENT_SOURCE_CHANGE before forwarding events and marking streaming vb2 queues in error. Signed-off-by: Svyatoslav Ryhel --- .../media/platform/nvidia/tegra-video/video.c | 74 +++++++++++++++---- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/drivers/media/platform/nvidia/tegra-video/video.c b/drivers/media/platform/nvidia/tegra-video/video.c index 2e84385708bac..9b8f57415778f 100644 --- a/drivers/media/platform/nvidia/tegra-video/video.c +++ b/drivers/media/platform/nvidia/tegra-video/video.c @@ -7,38 +7,82 @@ #include #include +#include +#include #include +#include #include "video.h" -static void tegra_v4l2_dev_release(struct v4l2_device *v4l2_dev) +/* Walk from the caller to the video device via active links */ +static struct video_device *find_pipeline_video_device(struct v4l2_subdev *sd) { - struct tegra_video_device *vid; + struct media_entity *entity = &sd->entity; + struct video_device *vdev = NULL; - vid = container_of(v4l2_dev, struct tegra_video_device, v4l2_dev); + while (entity) { + struct media_pad *src_pad = NULL; + struct media_pad *remote_pad; + unsigned int i; - /* cleanup channels here as all video device nodes are released */ - tegra_channels_cleanup(vid->vi); + if (is_media_entity_v4l2_video_device(entity)) { + vdev = media_entity_to_video_device(entity); + break; + } - v4l2_device_unregister(v4l2_dev); - media_device_unregister(&vid->media_dev); - media_device_cleanup(&vid->media_dev); - kfree(vid); + for (i = 0; i < entity->num_pads; i++) { + if (entity->pads[i].flags & MEDIA_PAD_FL_SOURCE) { + src_pad = &entity->pads[i]; + break; + } + } + + if (!src_pad) + break; + + remote_pad = media_pad_remote_pad_first(src_pad); + if (!remote_pad) + break; + + entity = remote_pad->entity; + } + + return vdev; } static void tegra_v4l2_dev_notify(struct v4l2_subdev *sd, unsigned int notification, void *arg) { - struct tegra_vi_channel *chan; const struct v4l2_event *ev = arg; + struct video_device *video; - if (notification != V4L2_DEVICE_NOTIFY_EVENT) + if (notification != V4L2_DEVICE_NOTIFY_EVENT || + ev->type != V4L2_EVENT_SOURCE_CHANGE) return; - chan = v4l2_get_subdev_hostdata(sd); - v4l2_event_queue(&chan->video, arg); - if (ev->type == V4L2_EVENT_SOURCE_CHANGE && vb2_is_streaming(&chan->queue)) - vb2_queue_error(&chan->queue); + video = find_pipeline_video_device(sd); + if (video) { + struct tegra_vi_channel *chan = video_get_drvdata(video); + + v4l2_event_queue(video, ev); + if (vb2_is_streaming(&chan->queue)) + vb2_queue_error(&chan->queue); + } +} + +static void tegra_v4l2_dev_release(struct v4l2_device *v4l2_dev) +{ + struct tegra_video_device *vid; + + vid = container_of(v4l2_dev, struct tegra_video_device, v4l2_dev); + + /* cleanup channels here as all video device nodes are released */ + tegra_channels_cleanup(vid->vi); + + v4l2_device_unregister(v4l2_dev); + media_device_unregister(&vid->media_dev); + media_device_cleanup(&vid->media_dev); + kfree(vid); } static int host1x_video_probe(struct host1x_device *dev) -- 2.53.0