Skip to contentSkip to conversation

media: v4l2-subdev: Return an error from set streaming if not supported

PATCH In review Sakari Ailus 2 participants 3 messages Mar 22 – Mar 23 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: v4l2-subdev: Return an error from set streaming if not supported

If a sub-device sets neither {enable_streams, disable_streams} pad ops nor s_stream video op, v4l2_subdev_s_stream_helper() calls v4l2_subdev_{enable,disable}_streams() recursively, exhausting the stack. Return -ENOIOCTLCMD if neither op is defined when enable_streams or disable_streams is called to handle the situation gracefully.

Fixes b62949ddaa52 ("media: subdev: Support single-stream case in v4l2_subdev_enable/disable_streams()")
---
 drivers/media/v4l2-core/v4l2-subdev.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +10 -6
index 831c69c958b8..f8ea4afc6cbb 100644
@@ -2334,11 +2334,13 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad,
 
 	/* Fallback on .s_stream() if .enable_streams() isn't available. */
 	use_s_stream = !v4l2_subdev_has_op(sd, pad, enable_streams);
-
-	if (!use_s_stream)
+	if (!use_s_stream) {
 		state = v4l2_subdev_lock_and_get_active_state(sd);
-	else
+	} else {
+		if (!v4l2_subdev_has_op(sd, video, s_stream))
+			return -ENOIOCTLCMD;
 		state = NULL;
+	}
 
 	/*
 	 * Verify that the requested streams exist and that they are not
@@ -2435,11 +2437,13 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
 
 	/* Fallback on .s_stream() if .disable_streams() isn't available. */
 	use_s_stream = !v4l2_subdev_has_op(sd, pad, disable_streams);
-
-	if (!use_s_stream)
+	if (!use_s_stream) {
 		state = v4l2_subdev_lock_and_get_active_state(sd);
-	else
+	} else {
+		if (!v4l2_subdev_has_op(sd, video, s_stream))
+			return -ENOIOCTLCMD;
 		state = NULL;
+	}
 
 	/*
 	 * Verify that the requested streams exist and that they are not
Signature · 1 line
2.47.3
#1 lore raw

Hi,

Quoted 5 lines · Sakari Ailus

If a sub-device sets neither {enable_streams, disable_streams} pad ops nor s_stream video op, v4l2_subdev_s_stream_helper() calls v4l2_subdev_{enable,disable}_streams() recursively, exhausting the stack. Return -ENOIOCTLCMD if neither op is defined when enable_streams or disable_streams is called to handle the situation gracefully.

How does this happen? I can't right away see where the recursion comes from.

Tomi

Quoted 46 lines
Fixes b62949ddaa52 ("media: subdev: Support single-stream case in v4l2_subdev_enable/disable_streams()")
---
 drivers/media/v4l2-core/v4l2-subdev.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +10 -6
index 831c69c958b8..f8ea4afc6cbb 100644
@@ -2334,11 +2334,13 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad,
 
 	/* Fallback on .s_stream() if .enable_streams() isn't available. */
 	use_s_stream = !v4l2_subdev_has_op(sd, pad, enable_streams);
-
-	if (!use_s_stream)
+	if (!use_s_stream) {
 		state = v4l2_subdev_lock_and_get_active_state(sd);
-	else
+	} else {
+		if (!v4l2_subdev_has_op(sd, video, s_stream))
+			return -ENOIOCTLCMD;
 		state = NULL;
+	}
 
 	/*
 	 * Verify that the requested streams exist and that they are not
@@ -2435,11 +2437,13 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
 
 	/* Fallback on .s_stream() if .disable_streams() isn't available. */
 	use_s_stream = !v4l2_subdev_has_op(sd, pad, disable_streams);
-
-	if (!use_s_stream)
+	if (!use_s_stream) {
 		state = v4l2_subdev_lock_and_get_active_state(sd);
-	else
+	} else {
+		if (!v4l2_subdev_has_op(sd, video, s_stream))
+			return -ENOIOCTLCMD;
 		state = NULL;
+	}
 
 	/*
 	 * Verify that the requested streams exist and that they are not
#2 lore raw

Moi,

Quoted 6 lines · Tomi Valkeinen

Hi,

Quoted 3 lines · Sakari Ailus

If a sub-device sets neither {enable_streams, disable_streams} pad ops nor s_stream video op, v4l2_subdev_s_stream_helper() calls v4l2_subdev_{enable,disable}_streams() recursively, exhausting the stack.

This should have been:

If a sub-device does not set {enable_streams, disable_streams} pad ops but assigns s_stream video op to v4l2_subdev_s_stream_helper(), both call each other recursively, exhausting the stack.

Quoted 4 lines
Quoted 2 lines

Return -ENOIOCTLCMD if neither op is defined when enable_streams or disable_streams is called to handle the situation gracefully.

How does this happen? I can't right away see where the recursion comes from.

v4l2_subdev_s_stream_helper() calls v4l2_subdev_enable_streams() and v4l2_subdev_enable_streams() in turn calls the s_stream() video op, which is assigned to v4l2_subdev_s_stream_helper(). This is not a regular configuration but still the failure should happen in form of a returned error code, not a system crash.

Signature · 3 lines
Terveisin,

Sakari Ailus