Skip to contentSkip to conversation

media: v4l: subdev: Make link validation safer

PATCH New Sakari Ailus 1 participant 1 message Mar 13, 2023 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 media: v4l: subdev: Make link validation safer

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a warning message, as this is how it used to work previously.

Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")

---
since v2:

- Print the entire link and the problematic end of it.

 drivers/media/v4l2-core/v4l2-subdev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/media/v4l2-core/v4l2-subdev.c +10 -0
index 03dc5f68ffad6..c7154a7f696a7 100644
@@ -1258,6 +1258,16 @@ int v4l2_subdev_link_validate(struct media_link *link)
 	bool states_locked;
 	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);
+		return 0;
+	}
+
 	sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);
 	source_sd = media_entity_to_v4l2_subdev(link->source->entity);
 
Signature · 1 line
2.30.2