Skip to contentSkip to conversation

v4l: subdev: Warn if disabling streaming failed, return success

PATCH In review Sakari Ailus 3 participants 3 messages Oct 26, 2022 – Nov 22, 2022 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v4l: subdev: Warn if disabling streaming failed, return success

Complain in the newly added s_stream video op wrapper if disabling streaming failed. Also return zero in this case as there's nothing the caller can do to return the error.

This way drivers also won't need to bother with printing error messages.

---
 drivers/media/v4l2-core/v4l2-subdev.c | 15 +++++++++++++++
 include/media/v4l2-subdev.h           |  6 ++++--
 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +15 -0
index 5c27bac772ea4..8a4ca2bd1584d 100644
@@ -318,6 +318,20 @@ static int call_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
 	       sd->ops->pad->get_mbus_config(sd, pad, config);
 }
 
+static int call_s_stream(struct v4l2_subdev *sd, int enable)
+{
+	int ret;
+
+	ret = sd->ops->video->s_stream(sd, enable);
+
+	if (!enable && ret < 0) {
+		dev_warn(sd->dev, "disabling streaming failed (%d)\n", ret);
+		return 0;
+	}
+
+	return ret;
+}
+
 #ifdef CONFIG_MEDIA_CONTROLLER
 /*
  * Create state-management wrapper for pad ops dealing with subdev state. The
@@ -377,6 +391,7 @@ static const struct v4l2_subdev_pad_ops v4l2_subdev_call_pad_wrappers = {
 static const struct v4l2_subdev_video_ops v4l2_subdev_call_video_wrappers = {
 	.g_frame_interval	= call_g_frame_interval,
 	.s_frame_interval	= call_s_frame_interval,
+	.s_stream		= call_s_stream,
 };
 
 const struct v4l2_subdev_ops v4l2_subdev_call_wrappers = {
include/media/v4l2-subdev.h +4 -2
index 54566d139da79..b15fa9930f30c 100644
@@ -440,8 +440,10 @@ enum v4l2_subdev_pre_streamon_flags {
  * @g_input_status: get input status. Same as the status field in the
  *	&struct v4l2_input
  *
- * @s_stream: used to notify the driver that a video stream will start or has
- *	stopped.
+ * @s_stream: start (enabled == 1) or stop (enabled == 0) streaming on the
+ *	sub-device. Failure on stop will remove any resources acquired in
+ *	streaming start, while the error code is still returned by the driver.
+ *	Also see call_s_stream wrapper in v4l2-subdev.c.
  *
  * @g_pixelaspect: callback to return the pixelaspect ratio.
  *
Signature · 1 line
2.30.2
Reviewed-by Lad Prabhakar on v1 1/1
#1 lore raw

Hi Sakari,

Thank you for the patch.

Quoted 5 lines · Sakari Ailus

Complain in the newly added s_stream video op wrapper if disabling streaming failed. Also return zero in this case as there's nothing the caller can do to return the error.

Quoted 8 lines

This way drivers also won't need to bother with printing error messages.

---
 drivers/media/v4l2-core/v4l2-subdev.c | 15 +++++++++++++++
 include/media/v4l2-subdev.h           |  6 ++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

Cheers,
Prabhakar

Quoted 53 lines
drivers/media/v4l2-core/v4l2-subdev.c +15 -0
index 5c27bac772ea4..8a4ca2bd1584d 100644
@@ -318,6 +318,20 @@ static int call_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
               sd->ops->pad->get_mbus_config(sd, pad, config);
 }
 
+static int call_s_stream(struct v4l2_subdev *sd, int enable)
+{
+       int ret;
+
+       ret = sd->ops->video->s_stream(sd, enable);
+
+       if (!enable && ret < 0) {
+               dev_warn(sd->dev, "disabling streaming failed (%d)\n", ret);
+               return 0;
+       }
+
+       return ret;
+}
+
 #ifdef CONFIG_MEDIA_CONTROLLER
 /*
  * Create state-management wrapper for pad ops dealing with subdev state. The
@@ -377,6 +391,7 @@ static const struct v4l2_subdev_pad_ops v4l2_subdev_call_pad_wrappers = {
 static const struct v4l2_subdev_video_ops v4l2_subdev_call_video_wrappers = {
        .g_frame_interval       = call_g_frame_interval,
        .s_frame_interval       = call_s_frame_interval,
+       .s_stream               = call_s_stream,
 };
 
 const struct v4l2_subdev_ops v4l2_subdev_call_wrappers = {
include/media/v4l2-subdev.h +4 -3
index 54566d139da79..b15fa9930f30c 100644
@@ -440,8 +440,10 @@ enum v4l2_subdev_pre_streamon_flags {
  * @g_input_status: get input status. Same as the status field in the
  *     &struct v4l2_input
  *
- * @s_stream: used to notify the driver that a video stream will start or has
- *     stopped.
+ * @s_stream: start (enabled == 1) or stop (enabled == 0) streaming on the
+ *     sub-device. Failure on stop will remove any resources acquired in
+ *     streaming start, while the error code is still returned by the driver.
+ *     Also see call_s_stream wrapper in v4l2-subdev.c.
  *
  * @g_pixelaspect: callback to return the pixelaspect ratio.
  *
--

2.30.2

Reviewed-by on v1 1/1
#2 lore raw
In reply to Sakari Ailus

Hi Sakari,

Thank you for the patch.

Quoted 7 lines · Sakari Ailus

Complain in the newly added s_stream video op wrapper if disabling streaming failed. Also return zero in this case as there's nothing the caller can do to return the error.

This way drivers also won't need to bother with printing error messages.

Quoted 55 lines
---
 drivers/media/v4l2-core/v4l2-subdev.c | 15 +++++++++++++++
 include/media/v4l2-subdev.h           |  6 ++++--
 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +15 -0
index 5c27bac772ea4..8a4ca2bd1584d 100644
@@ -318,6 +318,20 @@ static int call_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
 	       sd->ops->pad->get_mbus_config(sd, pad, config);
 }
 
+static int call_s_stream(struct v4l2_subdev *sd, int enable)
+{
+	int ret;
+
+	ret = sd->ops->video->s_stream(sd, enable);
+
+	if (!enable && ret < 0) {
+		dev_warn(sd->dev, "disabling streaming failed (%d)\n", ret);
+		return 0;
+	}
+
+	return ret;
+}
+
 #ifdef CONFIG_MEDIA_CONTROLLER
 /*
  * Create state-management wrapper for pad ops dealing with subdev state. The
@@ -377,6 +391,7 @@ static const struct v4l2_subdev_pad_ops v4l2_subdev_call_pad_wrappers = {
 static const struct v4l2_subdev_video_ops v4l2_subdev_call_video_wrappers = {
 	.g_frame_interval	= call_g_frame_interval,
 	.s_frame_interval	= call_s_frame_interval,
+	.s_stream		= call_s_stream,
 };
 
 const struct v4l2_subdev_ops v4l2_subdev_call_wrappers = {
include/media/v4l2-subdev.h +4 -2
index 54566d139da79..b15fa9930f30c 100644
@@ -440,8 +440,10 @@ enum v4l2_subdev_pre_streamon_flags {
  * @g_input_status: get input status. Same as the status field in the
  *	&struct v4l2_input
  *
- * @s_stream: used to notify the driver that a video stream will start or has
- *	stopped.
+ * @s_stream: start (enabled == 1) or stop (enabled == 0) streaming on the
+ *	sub-device. Failure on stop will remove any resources acquired in
+ *	streaming start, while the error code is still returned by the driver.
+ *	Also see call_s_stream wrapper in v4l2-subdev.c.
  *
  * @g_pixelaspect: callback to return the pixelaspect ratio.
  *
Signature · 3 lines
Regards,

Laurent Pinchart