From nobody Sun May 24 19:34:23 2026 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 146F0334C3C for ; Sat, 23 May 2026 06:48:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779518905; cv=none; b=D7QjSFjTnCzbrOXVzw6SHBWjxKrsm1+SqhwVXuRphxWGlKi5FOsXOJzQJ3YqFiIKoch3eNIsXAz6VyW7bJ07mzii/eVvFoByolkf98OHsiQ3kg+tjf0e3/dRKVNFHnl7VfhyNZVQoAXvYdIL+3e7kxAjzlu+X6ND4fogashRFS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779518905; c=relaxed/simple; bh=ruHWhs/NAmjUK/E6UKPL9THibS9Ul5SiTJSCwblcQ2k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W/SU672HawsEcGZR/pCOef2Zx9Bt9TvtO3BDKpWJV40FC92GTdwKV1tthgc55pkf4/GPgX/FkinBtv6QzBDvIYTgr0kd8NlWBOaf1KFYNseIds9G/bzfcKtJgE85PpfWsqqEf6GkKIoDN6OEWabZ3r9lBOZa6ZhF6kH61J+f5gY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BKLxM6w7; arc=none smtp.client-ip=209.85.208.43 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.b="BKLxM6w7" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-67da63ae541so1434760a12.0 for ; Fri, 22 May 2026 23:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779518902; x=1780123702; 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; bh=uQNJLijS1LXC3DyCF2fRyHh6+k3ll0IPAv+Qb62GcJI=; b=BKLxM6w7XhZTtxUt7w2IQgp+Hv9g6ksT1AiYqS+RCy9152kW8O7T3uKEGxegTDG2TV uUF7uqBn6ej4FJ6lnSQSC8oXpzD1YAlyELnNUDbaGndHHGwCgS7Ykn36xmR2ofoWeX+P 77xuMn2t3qvPDJJHYsGpgWG2Kt2DsNOqTKwFMqiJOz5KFqg76Me16kKRqr3jypiiger3 gO7StR2V0ivgmyJ7/RbH/0T1sMubnh3vayp3nsqEwNPWNAFqrNknDY9cDdaqTviElCrq FJkJfjJ25v8RW0J0F+TW1HzCeyjqvCNVhE3yX82GjmwpBmkdmEfhmHc+dY5ZMN3ADKZ6 jGvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779518902; x=1780123702; 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; bh=uQNJLijS1LXC3DyCF2fRyHh6+k3ll0IPAv+Qb62GcJI=; b=K1byL1NKw958ks2q/xUWuvTnYmxWdFlOZSvQEMfFNqNJTwJdKL1UEgIcNNwViYhBRu ed7i7Xo1XwOv7F7QHI7kIA6AnlFnv9yYZw2vWcvlcYWm9n5BHZ1h3hAuOxiSd9xCMX/t gF0XN7wGBOf/1fwLTtk/A9U6j2RKB87+JnkAEqpH71VwmU5XAd4PuKDGrCfGhzTnWn1P EsNCW0Lw9PR4vpxYTXQx+tU6RlzXXER9QvDvrNoCgeFtk/QiaAOezEg2uvpzFveQUnSX a3if6DRw5AcAGBxSOK9Frr7dgV48yWpnOxaJv/Oiyj7hjgg+cuVWndDdE078368lFd19 JpxA== X-Forwarded-Encrypted: i=1; AFNElJ93cZot1/Ubvyo4h8FKubulqRyDFn60wSMopsA2wZaaH1MnY7rGJJQAMrGuMODjr3ogD8h9vQ2lDPM0WBY=@vger.kernel.org X-Gm-Message-State: AOJu0Yzl8BfHLEC8i0EvRY22UVGTlFQxSF6RsZ11KE1/YbfFYj+/bVF2 RKtMjqHJXXeWme14hFetwzAPo7JEbtlEZ4Lwb0syEUjuXDEr9OiVwwEB X-Gm-Gg: Acq92OGcuje+/0ZrGUMCZiThKKyXx4UJ3zvXyzc0xmrpMEKA5X55x95PQBBpMFO/VxQ iKEKYb6YqP1c6oMuChqCZWeUZRZZ+Typ9j9TiM0SgOQ8954FZerin4PIqNP79hhjJWbbM1LEY61 U8NhZ9ECSokXDfjj9b35BBT8r4vh1i+t1+KhBnunO/MJ1UWJ+NqGqsq72tvpXSs2Adn92aEb6PG ahh9TuCghcQTiKgY3aG6vUfihyAr4xJPM5NLdyI1Vy88BgGVZWfCvKqcDV5iEFlMKjkv/QzdhSK eFDQWiJSxO22KU/1g7x82i+rMo9IIIeLbAhImXn5pgCB2VbuJM1AY+Rud2bR/xhKtxd7pEzEF99 IGhHSnte/JfcI8ptWoZZ1NXmYWLoy4tkAG0CtoXDN3LCYPiasvBDCqjUjyQBLEJRIG0pDPfoHBK MrH6z0vjLPpK8S X-Received: by 2002:a05:6402:3896:b0:680:1e7:cfa4 with SMTP id 4fb4d7f45d1cf-6889cc78d76mr3740625a12.24.1779518902334; Fri, 22 May 2026 23:48:22 -0700 (PDT) Received: from xeon ([188.163.112.61]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-688bb62b6dfsm1532272a12.30.2026.05.22.23.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 23:48:20 -0700 (PDT) From: Svyatoslav Ryhel To: Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Luca Ceresoli , Mauro Carvalho Chehab , Hans Verkuil , Greg Kroah-Hartman , Svyatoslav Ryhel Cc: linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/1] staging: media: tegra-video: vi: Improve media graph building logic Date: Sat, 23 May 2026 09:47:50 +0300 Message-ID: <20260523064750.35553-2-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260523064750.35553-1-clamor95@gmail.com> References: <20260523064750.35553-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing tegra_vi_graph_build function relies heavily on a one-to-one match between Device Tree nodes and media pad links. While this works for simpler configurations, it causes issues when Device Tree nodes do not match media pad link logic (e.g., mt9m114). Switch to the media_entity_get_fwnode_pad helper to verify and retrieve the correct pad linked to an endpoint, rather than assuming the endpoint ID matches the pad ID. Signed-off-by: Svyatoslav Ryhel --- drivers/staging/media/tegra-video/vi.c | 78 ++++++++++++-------------- 1 file changed, 35 insertions(+), 43 deletions(-) diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media= /tegra-video/vi.c index f14cdc7b5211..24e4bd438678 100644 --- a/drivers/staging/media/tegra-video/vi.c +++ b/drivers/staging/media/tegra-video/vi.c @@ -1468,7 +1468,6 @@ static int tegra_vi_graph_build(struct tegra_vi_chann= el *chan, struct tegra_vi *vi =3D chan->vi; struct tegra_vi_graph_entity *ent; struct fwnode_handle *ep =3D NULL; - struct v4l2_fwnode_link link; struct media_entity *local =3D entity->entity; struct media_entity *remote; struct media_pad *local_pad; @@ -1478,70 +1477,64 @@ static int tegra_vi_graph_build(struct tegra_vi_cha= nnel *chan, =20 dev_dbg(vi->dev, "creating links for entity %s\n", local->name); =20 - while (1) { - ep =3D fwnode_graph_get_next_endpoint(entity->asd.match.fwnode, - ep); - if (!ep) - break; + fwnode_graph_for_each_endpoint(entity->asd.match.fwnode, ep) { + struct fwnode_handle *remote_parent __free(fwnode_handle) =3D NULL; + struct fwnode_handle *sink_ep __free(fwnode_handle) =3D NULL; + int src_idx, sink_idx; =20 - ret =3D v4l2_fwnode_parse_link(ep, &link); - if (ret < 0) { - dev_err(vi->dev, "failed to parse link for %pOF: %d\n", - to_of_node(ep), ret); + src_idx =3D media_entity_get_fwnode_pad(local, ep, + MEDIA_PAD_FL_SOURCE); + if (src_idx < 0) { + dev_dbg(vi->dev, "no source pad found for %pfw\n", ep); continue; } =20 - if (link.local_port >=3D local->num_pads) { - dev_err(vi->dev, "invalid port number %u on %pOF\n", - link.local_port, to_of_node(link.local_node)); - v4l2_fwnode_put_link(&link); - ret =3D -EINVAL; - break; + remote_parent =3D fwnode_graph_get_remote_port_parent(ep); + if (!remote_parent) { + dev_dbg(vi->dev, "no remote parent found for %pfw\n", + ep); + continue; } =20 - local_pad =3D &local->pads[link.local_port]; + local_pad =3D &local->pads[src_idx]; /* Remote node is vi node. So use channel video entity and pad * as remote/sink. */ - if (link.remote_node =3D=3D of_fwnode_handle(vi->dev->of_node)) { + if (remote_parent =3D=3D of_fwnode_handle(vi->dev->of_node)) { remote =3D &chan->video.entity; remote_pad =3D &chan->pad; goto create_link; } =20 - /* - * Skip sink ports, they will be processed from the other end - * of the link. - */ - if (local_pad->flags & MEDIA_PAD_FL_SINK) { - dev_dbg(vi->dev, "skipping sink port %pOF:%u\n", - to_of_node(link.local_node), link.local_port); - v4l2_fwnode_put_link(&link); - continue; - } - /* find the remote entity from notifier list */ ent =3D tegra_vi_graph_find_entity(&chan->notifier.done_list, - link.remote_node); + remote_parent); if (!ent) { - dev_err(vi->dev, "no entity found for %pOF\n", - to_of_node(link.remote_node)); - v4l2_fwnode_put_link(&link); + fwnode_handle_put(ep); + dev_err(vi->dev, "no entity found for %pfw\n", + remote_parent); ret =3D -ENODEV; break; } =20 remote =3D ent->entity; - if (link.remote_port >=3D remote->num_pads) { - dev_err(vi->dev, "invalid port number %u on %pOF\n", - link.remote_port, - to_of_node(link.remote_node)); - v4l2_fwnode_put_link(&link); - ret =3D -EINVAL; - break; + + sink_ep =3D fwnode_graph_get_remote_endpoint(ep); + if (!sink_ep) { + dev_dbg(vi->dev, "no sink ep found for %pfw\n", + ep); + continue; + } + + sink_idx =3D media_entity_get_fwnode_pad(remote, sink_ep, + MEDIA_PAD_FL_SINK); + if (sink_idx < 0) { + dev_dbg(vi->dev, "no sink pad found for %pfw\n", + sink_ep); + continue; } =20 - remote_pad =3D &remote->pads[link.remote_port]; + remote_pad =3D &remote->pads[sink_idx]; =20 create_link: dev_dbg(vi->dev, "creating %s:%u -> %s:%u link\n", @@ -1551,8 +1544,8 @@ static int tegra_vi_graph_build(struct tegra_vi_chann= el *chan, ret =3D media_create_pad_link(local, local_pad->index, remote, remote_pad->index, link_flags); - v4l2_fwnode_put_link(&link); if (ret < 0) { + fwnode_handle_put(ep); dev_err(vi->dev, "failed to create %s:%u -> %s:%u link: %d\n", local->name, local_pad->index, @@ -1561,7 +1554,6 @@ static int tegra_vi_graph_build(struct tegra_vi_chann= el *chan, } } =20 - fwnode_handle_put(ep); return ret; } =20 --=20 2.51.0