media: v4l: Don't turn on privacy LED if streamon fails
PATCH 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.
--- drivers/media/v4l2-core/v4l2-subdev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +10 -9
@@ -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 ) {
@@ -431,6 +422,16 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)if (!ret) sd->enabled_streams = enable ?BIT (0 ) :0 ; +#if IS_REACHABLE (CONFIG_LEDS_CLASS ) +if (!IS_ERR_OR_NULL (sd->privacy_led) && !(enable && ret <0 )) { +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
Hi Sakari,
Thank you for fixing this.
Quoted 30 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")Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/v4l2-core/v4l2-subdev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)drivers/media/v4l2-core/v4l2-subdev.c +0
-9@@ -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 ) {
drivers/media/v4l2-core/v4l2-subdev.c static int call_s_stream(struct v4l2_subdev *sd, int enable) · line 426
Quoted 5 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0@@ -431,6 +422,16 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)if (!ret) sd->enabled_streams = enable ?BIT (0 ) :0 ; +#if IS_REACHABLE (CONFIG_LEDS_CLASS ) +if (!IS_ERR_OR_NULL (sd->privacy_led) && !(enable && ret <0 )) {
There already is a:
if (!enable && ret < 0) ret = 0;
block above to ignore stream-off errors, so you can just test for:
if (!ret && !IS_ERR_OR_NULL(sd->privacy_led)) {
...
}And then you can move the whole block to inside the existing:
if (!ret) sd->enabled_streams = enable ? BIT(0) : 0;
block, so you get something like this:
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
}Which then cleans up nicely by Tomi's patch
introducing the privacy LED helper functions,
to something like this:
if (!ret {
if (enable) {
sd->enabled_streams = BIT(0);
v4l2_subdev_enable_privacy_led(sd);
} else {
sd->enabled_streams = 0;
v4l2_subdev_disable_privacy_led(sd);
}
}Regards,
Hans
Hi Hans,
Thanks for the review.
Quoted 59 lines · Hans de Goede
Hi Sakari,
Thank you for fixing this.
Quoted 30 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")Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/v4l2-core/v4l2-subdev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)drivers/media/v4l2-core/v4l2-subdev.c +0
-9@@ -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 ) {drivers/media/v4l2-core/v4l2-subdev.c static int call_s_stream(struct v4l2_subdev *sd, int enable) · line 426
Quoted 5 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0@@ -431,6 +422,16 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)if (!ret) sd->enabled_streams = enable ?BIT (0 ) :0 ; +#if IS_REACHABLE (CONFIG_LEDS_CLASS ) +if (!IS_ERR_OR_NULL (sd->privacy_led) && !(enable && ret <0 )) {There already is a:
if (!enable && ret < 0) ret = 0;block above to ignore stream-off errors, so you can just test for:
if (!ret && !IS_ERR_OR_NULL(sd->privacy_led)) { ... }And then you can move the whole block to inside the existing:
if (!ret) sd->enabled_streams = enable ? BIT(0) : 0;block, so you get something like this:
Quoted 12 lines
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
}Seems reasonable, I'll send v2.
Quoted 15 lines
Which then cleans up nicely by Tomi's patch
introducing the privacy LED helper functions,
to something like this:if (!ret { if (enable) { sd->enabled_streams = BIT(0); v4l2_subdev_enable_privacy_led(sd); } else { sd->enabled_streams = 0; v4l2_subdev_disable_privacy_led(sd); } }
Signature · 3 lines
Kind regards, Sakari Ailus
Quoted 77 lines · Sakari Ailus
Hi Hans,
Thanks for the review.
Quoted 59 lines · Hans de Goede
Hi Sakari,
Thank you for fixing this.
Quoted 30 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")Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/v4l2-core/v4l2-subdev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)drivers/media/v4l2-core/v4l2-subdev.c +0
-9@@ -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 ) {drivers/media/v4l2-core/v4l2-subdev.c static int call_s_stream(struct v4l2_subdev *sd, int enable) · line 426
Quoted 5 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0@@ -431,6 +422,16 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)if (!ret) sd->enabled_streams = enable ?BIT (0 ) :0 ; +#if IS_REACHABLE (CONFIG_LEDS_CLASS ) +if (!IS_ERR_OR_NULL (sd->privacy_led) && !(enable && ret <0 )) {There already is a:
if (!enable && ret < 0) ret = 0;block above to ignore stream-off errors, so you can just test for:
if (!ret && !IS_ERR_OR_NULL(sd->privacy_led)) { ... }And then you can move the whole block to inside the existing:
if (!ret) sd->enabled_streams = enable ? BIT(0) : 0;block, so you get something like this:
Quoted 12 lines
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 }
Quoted 1 line
Seems reasonable, I'll send v2.
I was a bit too fast to hit y. ret will be non-zero if streamon fails (enable non-zero), in which case the LED needs to be turned off. So you can't have !ret condition for all LED control.
Quoted 17 lines
Quoted 16 lines
Which then cleans up nicely by Tomi's patch
introducing the privacy LED helper functions,
to something like this:if (!ret { if (enable) { sd->enabled_streams = BIT(0); v4l2_subdev_enable_privacy_led(sd); } else { sd->enabled_streams = 0; v4l2_subdev_disable_privacy_led(sd); } }
Signature · 1 line
Sakari Ailus
Hi,
Quoted 78 lines · Sakari Ailus
Quoted 77 lines · Sakari Ailus
Hi Hans,
Thanks for the review.
Quoted 71 lines · Hans de Goede
Hi Sakari,
Thank you for fixing this.
Quoted 30 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")Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/v4l2-core/v4l2-subdev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)drivers/media/v4l2-core/v4l2-subdev.c +0
-9@@ -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 ) {drivers/media/v4l2-core/v4l2-subdev.c static int call_s_stream(struct v4l2_subdev *sd, int enable) · line 426
Quoted 5 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0@@ -431,6 +422,16 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)if (!ret) sd->enabled_streams = enable ?BIT (0 ) :0 ; +#if IS_REACHABLE (CONFIG_LEDS_CLASS ) +if (!IS_ERR_OR_NULL (sd->privacy_led) && !(enable && ret <0 )) {There already is a:
if (!enable && ret < 0) ret = 0;block above to ignore stream-off errors, so you can just test for:
if (!ret && !IS_ERR_OR_NULL(sd->privacy_led)) { ... }And then you can move the whole block to inside the existing:
if (!ret) sd->enabled_streams = enable ? BIT(0) : 0;block, so you get something like this:
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 }
Quoted 5 lines
Quoted 1 line
Seems reasonable, I'll send v2.
I was a bit too fast to hit y. ret will be non-zero if streamon fails (enable non-zero), in which case the LED needs to be turned off. So you can't have !ret condition for all LED control.
But if stream-on fails then AFAICT the LED was never turned on in the first place. stream on / off calls must always be balanced, right ?
IOW stream-on is not supposed to get called if the device is already streaming and if the device is not already streaming then the LED will already be off.
Regards,
Hans
Quoted 19 lines
Quoted 18 lines
Quoted 17 lines
Which then cleans up nicely by Tomi's patch
introducing the privacy LED helper functions,
to something like this:if (!ret { if (enable) { sd->enabled_streams = BIT(0); v4l2_subdev_enable_privacy_led(sd); } else { sd->enabled_streams = 0; v4l2_subdev_disable_privacy_led(sd); } }
Quoted 87 lines · Hans de Goede
Hi,
Quoted 78 lines · Sakari Ailus
Quoted 77 lines · Sakari Ailus
Hi Hans,
Thanks for the review.
Quoted 71 lines · Hans de Goede
Hi Sakari,
Thank you for fixing this.
Quoted 30 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")Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/v4l2-core/v4l2-subdev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)drivers/media/v4l2-core/v4l2-subdev.c +0
-9@@ -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 ) {drivers/media/v4l2-core/v4l2-subdev.c static int call_s_stream(struct v4l2_subdev *sd, int enable) · line 426
Quoted 5 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0@@ -431,6 +422,16 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable)if (!ret) sd->enabled_streams = enable ?BIT (0 ) :0 ; +#if IS_REACHABLE (CONFIG_LEDS_CLASS ) +if (!IS_ERR_OR_NULL (sd->privacy_led) && !(enable && ret <0 )) {There already is a:
if (!enable && ret < 0) ret = 0;block above to ignore stream-off errors, so you can just test for:
if (!ret && !IS_ERR_OR_NULL(sd->privacy_led)) { ... }And then you can move the whole block to inside the existing:
if (!ret) sd->enabled_streams = enable ? BIT(0) : 0;block, so you get something like this:
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 }Quoted 5 lines
Quoted 1 line
Seems reasonable, I'll send v2.
I was a bit too fast to hit y. ret will be non-zero if streamon fails (enable non-zero), in which case the LED needs to be turned off. So you can't have !ret condition for all LED control.
Quoted 6 lines
But if stream-on fails then AFAICT the LED was never turned on in the first place. stream on / off calls must always be balanced, right ?
IOW stream-on is not supposed to get called if the device is already streaming and if the device is not already streaming then the LED will already be off.
Ah, right. I missed that part. I'll send v2 after all. :-)
Signature · 1 line
Sakari Ailus