public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] media: v4l2-subdev: Fail {enable,disable}_streams and s_streaming nicely
@ 2026-05-04 12:35 Sakari Ailus
  2026-05-04 12:37 ` Sakari Ailus
  2026-05-04 13:22 ` Laurent Pinchart
  0 siblings, 2 replies; 3+ messages in thread
From: Sakari Ailus @ 2026-05-04 12:35 UTC (permalink / raw)
  To: linux-media
  Cc: Laurent Pinchart, David Heidelberg, Hans Verkuil, Tomi Valkeinen,
	Jacopo Mondi

If a sub-device does not set enable_streams() and disable_streams() pad
ops while it sets the s_stream() video op to
v4l2_subdev_s_stream_helper(), enabling or disabling streaming either way
on the sub-device will result calling v4l2_subdev_s_stream_helper() and
v4l2_subdev_{enable,disable}_streams() recursively, exhausting the stack.
Return -ENOIOCTLCMD in this case to handle the situation gracefully.

Reported-by: David Heidelberg <david@ixit.cz>
Fixes: b62949ddaa52 ("media: subdev: Support single-stream case in v4l2_subdev_enable/disable_streams()")
Cc: stable@vger.kernel.org
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
since v2:

- Move the check, with checking the pad ops, to
  v4l2_subdev_s_stream_helper().

 drivers/media/v4l2-core/v4l2-subdev.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index 831c69c958b8..3b726f044d3f 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -2504,6 +2504,10 @@ int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable)
 	u64 source_mask = 0;
 	int pad_index = -1;
 
+	if (WARN_ON_ONCE(!v4l2_subdev_has_op(sd, pad, enable_streams) ||
+			 !v4l2_subdev_has_op(sd, pad, disable_streams)))
+		return -ENOIOCTLCMD;
+
 	/*
 	 * Find the source pad. This helper is meant for subdevs that have a
 	 * single source pad, so failures shouldn't happen, but catch them
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] media: v4l2-subdev: Fail {enable,disable}_streams and s_streaming nicely
  2026-05-04 12:35 [PATCH 1/1] media: v4l2-subdev: Fail {enable,disable}_streams and s_streaming nicely Sakari Ailus
@ 2026-05-04 12:37 ` Sakari Ailus
  2026-05-04 13:22 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Sakari Ailus @ 2026-05-04 12:37 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, Laurent Pinchart, David Heidelberg, Hans Verkuil,
	Tomi Valkeinen, Jacopo Mondi

On Mon, May 04, 2026 at 03:35:03PM +0300, Sakari Ailus wrote:
> since v2:

This was indeed meant to be v3.

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] media: v4l2-subdev: Fail {enable,disable}_streams and s_streaming nicely
  2026-05-04 12:35 [PATCH 1/1] media: v4l2-subdev: Fail {enable,disable}_streams and s_streaming nicely Sakari Ailus
  2026-05-04 12:37 ` Sakari Ailus
@ 2026-05-04 13:22 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Pinchart @ 2026-05-04 13:22 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, David Heidelberg, Hans Verkuil, Tomi Valkeinen,
	Jacopo Mondi

On Mon, May 04, 2026 at 03:35:03PM +0300, Sakari Ailus wrote:
> If a sub-device does not set enable_streams() and disable_streams() pad
> ops while it sets the s_stream() video op to
> v4l2_subdev_s_stream_helper(), enabling or disabling streaming either way
> on the sub-device will result calling v4l2_subdev_s_stream_helper() and
> v4l2_subdev_{enable,disable}_streams() recursively, exhausting the stack.
> Return -ENOIOCTLCMD in this case to handle the situation gracefully.
> 
> Reported-by: David Heidelberg <david@ixit.cz>
> Fixes: b62949ddaa52 ("media: subdev: Support single-stream case in v4l2_subdev_enable/disable_streams()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
> since v2:
> 
> - Move the check, with checking the pad ops, to
>   v4l2_subdev_s_stream_helper().
> 
>  drivers/media/v4l2-core/v4l2-subdev.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index 831c69c958b8..3b726f044d3f 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -2504,6 +2504,10 @@ int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable)
>  	u64 source_mask = 0;
>  	int pad_index = -1;
>  
> +	if (WARN_ON_ONCE(!v4l2_subdev_has_op(sd, pad, enable_streams) ||
> +			 !v4l2_subdev_has_op(sd, pad, disable_streams)))

Is this indicates a clear bug, I would use WARN_ON() instead of
WARN_ON_ONCE(). Up to you.

Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

> +		return -ENOIOCTLCMD;
> +
>  	/*
>  	 * Find the source pad. This helper is meant for subdevs that have a
>  	 * single source pad, so failures shouldn't happen, but catch them

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-04 13:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-04 12:35 [PATCH 1/1] media: v4l2-subdev: Fail {enable,disable}_streams and s_streaming nicely Sakari Ailus
2026-05-04 12:37 ` Sakari Ailus
2026-05-04 13:22 ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox