Skip to contentSkip to conversation

media: v4l: Don't turn on privacy LED if streamon fails

PATCH In review Sakari Ailus 5 participants 9 messages Apr 10, 2024 – Apr 15, 2024 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: v4l: Don't turn on privacy LED if streamon fails

Turn on the privacy LED only if streamon succeeds. This can be done after enabling streaming on the sensor.

Fixes b6e10ff6c23d ("media: v4l2-core: Make the v4l2-core code enable/disable the privacy LED if present")
---
 drivers/media/v4l2-core/v4l2-subdev.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +12 -10
index 4c6198c48dd6..012b757eac9f 100644
@@ -412,15 +412,6 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 	if (WARN_ON(!!sd->enabled_streams == !!enable))
 		return 0;
 
-#if IS_REACHABLE(CONFIG_LEDS_CLASS)
-	if (!IS_ERR_OR_NULL(sd->privacy_led)) {
-		if (enable)
-			led_set_brightness(sd->privacy_led,
-					   sd->privacy_led->max_brightness);
-		else
-			led_set_brightness(sd->privacy_led, 0);
-	}
-#endif
 	ret = sd->ops->video->s_stream(sd, enable);
 
 	if (!enable && ret < 0) {
@@ -428,9 +419,20 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		ret = 0;
 	}
 
-	if (!ret)
+	if (!ret) {
 		sd->enabled_streams = enable ? BIT(0) : 0;
 
+#if IS_REACHABLE(CONFIG_LEDS_CLASS)
+		if (!IS_ERR_OR_NULL(sd->privacy_led)) {
+			if (enable)
+				led_set_brightness(sd->privacy_led,
+						   sd->privacy_led->max_brightness);
+			else
+				led_set_brightness(sd->privacy_led, 0);
+		}
+#endif
+	}
+
 	return ret;
 }
 
Signature · 1 line
2.39.2
Reviewed-by on v2 1/1
#1 lore raw

Hi,

Quoted 5 lines · Sakari Ailus

Turn on the privacy LED only if streamon succeeds. This can be done after enabling streaming on the sensor.

Fixes b6e10ff6c23d ("media: v4l2-core: Make the v4l2-core code enable/disable the privacy LED if present")

Thanks, patch looks good to me:

Regards,

Hans

Quoted 46 lines
---
 drivers/media/v4l2-core/v4l2-subdev.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +12 -10
index 4c6198c48dd6..012b757eac9f 100644
@@ -412,15 +412,6 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 	if (WARN_ON(!!sd->enabled_streams == !!enable))
 		return 0;
 
-#if IS_REACHABLE(CONFIG_LEDS_CLASS)
-	if (!IS_ERR_OR_NULL(sd->privacy_led)) {
-		if (enable)
-			led_set_brightness(sd->privacy_led,
-					   sd->privacy_led->max_brightness);
-		else
-			led_set_brightness(sd->privacy_led, 0);
-	}
-#endif
 	ret = sd->ops->video->s_stream(sd, enable);
 
 	if (!enable && ret < 0) {
@@ -428,9 +419,20 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		ret = 0;
 	}
 
-	if (!ret)
+	if (!ret) {
 		sd->enabled_streams = enable ? BIT(0) : 0;
 
+#if IS_REACHABLE(CONFIG_LEDS_CLASS)
+		if (!IS_ERR_OR_NULL(sd->privacy_led)) {
+			if (enable)
+				led_set_brightness(sd->privacy_led,
+						   sd->privacy_led->max_brightness);
+			else
+				led_set_brightness(sd->privacy_led, 0);
+		}
+#endif
+	}
+
 	return ret;
 }
 
Reviewed-by
#2 lore raw

Hi Sakari,

Thank you for the patch

Quoted 9 lines · Hans de Goede

Hi,

Quoted 5 lines · Sakari Ailus

Turn on the privacy LED only if streamon succeeds. This can be done after enabling streaming on the sensor.

Fixes b6e10ff6c23d ("media: v4l2-core: Make the v4l2-core code enable/disable the privacy LED if present")

Thanks, patch looks good to me:

Looks good to me too

Quoted 2 lines
Quoted 53 lines

Regards,

Hans

Quoted 46 lines
---
  drivers/media/v4l2-core/v4l2-subdev.c | 22 ++++++++++++----------
  1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +12 -10
index 4c6198c48dd6..012b757eac9f 100644
@@ -412,15 +412,6 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
  	if (WARN_ON(!!sd->enabled_streams == !!enable))
  		return 0;
 
-#if IS_REACHABLE(CONFIG_LEDS_CLASS)
-	if (!IS_ERR_OR_NULL(sd->privacy_led)) {
-		if (enable)
-			led_set_brightness(sd->privacy_led,
-					   sd->privacy_led->max_brightness);
-		else
-			led_set_brightness(sd->privacy_led, 0);
-	}
-#endif
  	ret = sd->ops->video->s_stream(sd, enable);
 
  	if (!enable && ret < 0) {
@@ -428,9 +419,20 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
  		ret = 0;
  	}
 
-	if (!ret)
+	if (!ret) {
  		sd->enabled_streams = enable ? BIT(0) : 0;
 
+#if IS_REACHABLE(CONFIG_LEDS_CLASS)
+		if (!IS_ERR_OR_NULL(sd->privacy_led)) {
+			if (enable)
+				led_set_brightness(sd->privacy_led,
+						   sd->privacy_led->max_brightness);
+			else
+				led_set_brightness(sd->privacy_led, 0);
+		}
+#endif
+	}
+
  	return ret;
  }
 
Reviewed-by on v2 1/1
#3 lore raw
In reply to Sakari Ailus
Quoted 41 lines · Sakari Ailus

Turn on the privacy LED only if streamon succeeds. This can be done after enabling streaming on the sensor.

Fixes b6e10ff6c23d ("media: v4l2-core: Make the v4l2-core code enable/disable the privacy LED if present")
---
  drivers/media/v4l2-core/v4l2-subdev.c | 22 ++++++++++++----------
  1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +5 -10
index 4c6198c48dd6..012b757eac9f 100644
@@ -412,15 +412,6 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
  	if (WARN_ON(!!sd->enabled_streams == !!enable))
  		return 0;
 
-#if IS_REACHABLE(CONFIG_LEDS_CLASS)
-	if (!IS_ERR_OR_NULL(sd->privacy_led)) {
-		if (enable)
-			led_set_brightness(sd->privacy_led,
-					   sd->privacy_led->max_brightness);
-		else
-			led_set_brightness(sd->privacy_led, 0);
-	}
-#endif
  	ret = sd->ops->video->s_stream(sd, enable);
 
  	if (!enable && ret < 0) {
@@ -428,9 +419,20 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
  		ret = 0;
  	}
 
-	if (!ret)
+	if (!ret) {
  		sd->enabled_streams = enable ? BIT(0) : 0;
 
+#if IS_REACHABLE(CONFIG_LEDS_CLASS)
+		if (!IS_ERR_OR_NULL(sd->privacy_led)) {
+			if (enable)
+				led_set_brightness(sd->privacy_led,

drivers/media/v4l2-core/v4l2-subdev.c static int call_s_stream(struct v4l2_subdev *sd, int enable) · line 438

Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7 -0
+						   sd->privacy_led->max_brightness);
+			else
+				led_set_brightness(sd->privacy_led, 0);
+		}
+#endif
+	}
+
  	return ret;
  }
 

Tomi

#4 lore raw
In reply to Sakari Ailus

Hi Sakari,

Thank you for the patch.

Quoted 36 lines · Sakari Ailus

Turn on the privacy LED only if streamon succeeds. This can be done after enabling streaming on the sensor.

Fixes b6e10ff6c23d ("media: v4l2-core: Make the v4l2-core code enable/disable the privacy LED if present")
---
 drivers/media/v4l2-core/v4l2-subdev.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +1 -10
index 4c6198c48dd6..012b757eac9f 100644
@@ -412,15 +412,6 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 	if (WARN_ON(!!sd->enabled_streams == !!enable))
 		return 0;
 
-#if IS_REACHABLE(CONFIG_LEDS_CLASS)
-	if (!IS_ERR_OR_NULL(sd->privacy_led)) {
-		if (enable)
-			led_set_brightness(sd->privacy_led,
-					   sd->privacy_led->max_brightness);
-		else
-			led_set_brightness(sd->privacy_led, 0);
-	}
-#endif
 	ret = sd->ops->video->s_stream(sd, enable);
 
 	if (!enable && ret < 0) {
@@ -428,9 +419,20 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		ret = 0;
 	}
 
-	if (!ret)
+	if (!ret) {
 		sd->enabled_streams = enable ? BIT(0) : 0;

drivers/media/v4l2-core/v4l2-subdev.c static int call_s_stream(struct v4l2_subdev *sd, int enable) · line 433

Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +9 -0
 
+#if IS_REACHABLE(CONFIG_LEDS_CLASS)
+		if (!IS_ERR_OR_NULL(sd->privacy_led)) {
+			if (enable)
+				led_set_brightness(sd->privacy_led,
+						   sd->privacy_led->max_brightness);
+			else
+				led_set_brightness(sd->privacy_led, 0);
+		}
+#endif

This means that the LED will be turned slightly after the camera is enabled. I don't think it's an issue in practice. Another possibly more important concern is that we should maybe check the return value of led_set_brightness(), and fail .s_stream() when we can't enable the privacy LED at stream on time. In that case, it would be best to keep turning the privacy LED on before calling .s_stream(). It should still be turned off only after calling .s_stream() though.

Quoted 5 lines
drivers/media/v4l2-core/v4l2-subdev.c +2 -0
+	}
+
 	return ret;
 }
 
Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw

Hi Laurent,

Quoted 42 lines · Laurent Pinchart

Hi Sakari,

Thank you for the patch.

Quoted 37 lines · Sakari Ailus

Turn on the privacy LED only if streamon succeeds. This can be done after enabling streaming on the sensor.

Fixes b6e10ff6c23d ("media: v4l2-core: Make the v4l2-core code enable/disable the privacy LED if present")
---
 drivers/media/v4l2-core/v4l2-subdev.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +1 -10
index 4c6198c48dd6..012b757eac9f 100644
@@ -412,15 +412,6 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 	if (WARN_ON(!!sd->enabled_streams == !!enable))
 		return 0;
 
-#if IS_REACHABLE(CONFIG_LEDS_CLASS)
-	if (!IS_ERR_OR_NULL(sd->privacy_led)) {
-		if (enable)
-			led_set_brightness(sd->privacy_led,
-					   sd->privacy_led->max_brightness);
-		else
-			led_set_brightness(sd->privacy_led, 0);
-	}
-#endif
 	ret = sd->ops->video->s_stream(sd, enable);
 
 	if (!enable && ret < 0) {
@@ -428,9 +419,20 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		ret = 0;
 	}
 
-	if (!ret)
+	if (!ret) {
 		sd->enabled_streams = enable ? BIT(0) : 0;
 
Quoted 12 lines

drivers/media/v4l2-core/v4l2-subdev.c static int call_s_stream(struct v4l2_subdev *sd, int enable) · line 433

Quoted 9 lines
drivers/media/v4l2-core/v4l2-subdev.c +9 -0
+#if IS_REACHABLE(CONFIG_LEDS_CLASS)
+		if (!IS_ERR_OR_NULL(sd->privacy_led)) {
+			if (enable)
+				led_set_brightness(sd->privacy_led,
+						   sd->privacy_led->max_brightness);
+			else
+				led_set_brightness(sd->privacy_led, 0);
+		}
+#endif

This means that the LED will be turned slightly after the camera is enabled. I don't think it's an issue in practice. Another possibly more

That's what I'd think as well. Typically even the exposure time is much, much longer than what it takes to get here.

Quoted 5 lines

important concern is that we should maybe check the return value of led_set_brightness(), and fail .s_stream() when we can't enable the privacy LED at stream on time. In that case, it would be best to keep turning the privacy LED on before calling .s_stream(). It should still be turned off only after calling .s_stream() though.

The return type of led_set_brightness() is void. Maybe because a large majority is GPIO-controlled?

Signature · 3 lines
Regards,

Sakari Ailus
#6 lore raw
Quoted 61 lines · Sakari Ailus

Hi Laurent,

Quoted 42 lines · Laurent Pinchart

Hi Sakari,

Thank you for the patch.

Quoted 37 lines · Sakari Ailus

Turn on the privacy LED only if streamon succeeds. This can be done after enabling streaming on the sensor.

Fixes b6e10ff6c23d ("media: v4l2-core: Make the v4l2-core code enable/disable the privacy LED if present")
---
 drivers/media/v4l2-core/v4l2-subdev.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +1 -10
index 4c6198c48dd6..012b757eac9f 100644
@@ -412,15 +412,6 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 	if (WARN_ON(!!sd->enabled_streams == !!enable))
 		return 0;
 
-#if IS_REACHABLE(CONFIG_LEDS_CLASS)
-	if (!IS_ERR_OR_NULL(sd->privacy_led)) {
-		if (enable)
-			led_set_brightness(sd->privacy_led,
-					   sd->privacy_led->max_brightness);
-		else
-			led_set_brightness(sd->privacy_led, 0);
-	}
-#endif
 	ret = sd->ops->video->s_stream(sd, enable);
 
 	if (!enable && ret < 0) {
@@ -428,9 +419,20 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)
 		ret = 0;
 	}
 
-	if (!ret)
+	if (!ret) {
 		sd->enabled_streams = enable ? BIT(0) : 0;
 
Quoted 12 lines

drivers/media/v4l2-core/v4l2-subdev.c static int call_s_stream(struct v4l2_subdev *sd, int enable) · line 433

Quoted 9 lines
drivers/media/v4l2-core/v4l2-subdev.c +9 -0
+#if IS_REACHABLE(CONFIG_LEDS_CLASS)
+		if (!IS_ERR_OR_NULL(sd->privacy_led)) {
+			if (enable)
+				led_set_brightness(sd->privacy_led,
+						   sd->privacy_led->max_brightness);
+			else
+				led_set_brightness(sd->privacy_led, 0);
+		}
+#endif

This means that the LED will be turned slightly after the camera is enabled. I don't think it's an issue in practice. Another possibly more

That's what I'd think as well. Typically even the exposure time is much, much longer than what it takes to get here.

Quoted 7 lines
Quoted 5 lines

important concern is that we should maybe check the return value of led_set_brightness(), and fail .s_stream() when we can't enable the privacy LED at stream on time. In that case, it would be best to keep turning the privacy LED on before calling .s_stream(). It should still be turned off only after calling .s_stream() though.

The return type of led_set_brightness() is void.

Oops :-S

Quoted 1 line

Maybe because a large majority is GPIO-controlled?

GPIOs can fail, in particular when they're on I2C GPIO expanders.

Signature · 3 lines
Regards,

Laurent Pinchart
#7 lore raw
Quoted 3 lines · Laurent Pinchart
Quoted 1 line

Maybe because a large majority is GPIO-controlled?

GPIOs can fail, in particular when they're on I2C GPIO expanders.

Sure, but gpiod_set_value() return type is also void.

It just works... right?

Signature · 1 line
Sakari Ailus
#8 lore raw
Quoted 6 lines · Sakari Ailus
Quoted 3 lines · Laurent Pinchart
Quoted 1 line

Maybe because a large majority is GPIO-controlled?

GPIOs can fail, in particular when they're on I2C GPIO expanders.

Sure, but gpiod_set_value() return type is also void.

I know, so there's nothing we can do short term.

Quoted 1 line

It just works... right?

Until it doesn't :-)

Signature · 3 lines
Regards,

Laurent Pinchart