[PATCH v2 1/2] media: ipu6: isys: csi2: guard remote pad lookups in stream ops

From: Mikhail Lobanov
Date: Wed Dec 17 2025 - 16:42:44 EST


ipu6_isys_csi2_enable_streams() and ipu6_isys_csi2_disable_streams()
use media_pad_remote_pad_first() on the CSI-2 sink pad and dereference
the returned remote pad unconditionally. media_pad_remote_pad_first()
only returns a pad for an enabled link, and the external subdev -> CSI-2
sink link is created only when the external subdev is successfully bound
in isys_complete_ext_device_registration().

CSI-2 subdevs are registered independently of external devices and are
created with HAS_DEVNODE and STREAMS flags. As a result, the CSI-2 stream
callbacks can be reached even when a given CSI-2 port has no enabled
upstream link, in which case media_pad_remote_pad_first() returns NULL.

Check the remote pad before dereferencing it. Return -ENOTCONN from the
enable path when no remote pad is found. In the disable path, always stop
the local CSI-2 receiver and return success when the remote link is
missing to keep teardown best-effort and consistent with the existing
behaviour (remote disable errors are not propagated today).

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 3a5c59ad926b ("media: ipu6: Rework CSI-2 sub-device streaming control")
Signed-off-by: Mikhail Lobanov <m.lobanov@xxxxxxx>
---
v1: https://lore.kernel.org/lkml/20251211221040.19870-1-m.lobanov@xxxxxxx
drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
index 43a2a16a3c2a..29791b66d479 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
@@ -356,6 +356,9 @@ static int ipu6_isys_csi2_enable_streams(struct v4l2_subdev *sd,
int ret;

remote_pad = media_pad_remote_pad_first(&sd->entity.pads[CSI2_PAD_SINK]);
+ if (!remote_pad)
+ return -ENOTCONN;
+
remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);

sink_streams =
@@ -393,6 +396,11 @@ static int ipu6_isys_csi2_disable_streams(struct v4l2_subdev *sd,
&streams_mask);

remote_pad = media_pad_remote_pad_first(&sd->entity.pads[CSI2_PAD_SINK]);
+ if (!remote_pad) {
+ ipu6_isys_csi2_set_stream(sd, NULL, 0, false);
+ return 0;
+ }
+
remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);

ipu6_isys_csi2_set_stream(sd, NULL, 0, false);
--
2.47.2