media: v4l2-flash: Check whether setting LED brightness succeeded
authorSakari Ailus <sakari.ailus@linux.intel.com>
Thu, 24 Jun 2021 12:32:02 +0000 (14:32 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Wed, 4 Aug 2021 12:43:51 +0000 (14:43 +0200)
Setting LED brightness may return an error but the return value was never
checked by the V4L2 flash LED class. Do it now.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/v4l2-core/v4l2-flash-led-class.c

index 4c096ae4648d988bd618270085b21fdc40d2f7ae..e70e128ccc9c578f6e414a46313ca160937a8045 100644 (file)
@@ -76,8 +76,8 @@ static s32 __led_brightness_to_intensity(struct v4l2_ctrl *ctrl,
        return (brightness * ctrl->step) + ctrl->minimum;
 }
 
-static void v4l2_flash_set_led_brightness(struct v4l2_flash *v4l2_flash,
-                                       struct v4l2_ctrl *ctrl)
+static int v4l2_flash_set_led_brightness(struct v4l2_flash *v4l2_flash,
+                                        struct v4l2_ctrl *ctrl)
 {
        struct v4l2_ctrl **ctrls = v4l2_flash->ctrls;
        struct led_classdev *led_cdev;
@@ -103,20 +103,20 @@ static void v4l2_flash_set_led_brightness(struct v4l2_flash *v4l2_flash,
 
        if (ctrl == ctrls[TORCH_INTENSITY]) {
                if (ctrls[LED_MODE]->val != V4L2_FLASH_LED_MODE_TORCH)
-                       return;
+                       return 0;
 
                if (WARN_ON_ONCE(!v4l2_flash->fled_cdev))
-                       return;
+                       return -EINVAL;
 
                led_cdev = &v4l2_flash->fled_cdev->led_cdev;
        } else {
                if (WARN_ON_ONCE(!v4l2_flash->iled_cdev))
-                       return;
+                       return -EINVAL;
 
                led_cdev = v4l2_flash->iled_cdev;
        }
 
-       led_set_brightness_sync(led_cdev, brightness);
+       return led_set_brightness_sync(led_cdev, brightness);
 }
 
 static int v4l2_flash_update_led_brightness(struct v4l2_flash *v4l2_flash,
@@ -222,8 +222,7 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)
        switch (c->id) {
        case V4L2_CID_FLASH_TORCH_INTENSITY:
        case V4L2_CID_FLASH_INDICATOR_INTENSITY:
-               v4l2_flash_set_led_brightness(v4l2_flash, c);
-               return 0;
+               return v4l2_flash_set_led_brightness(v4l2_flash, c);
        }
 
        if (!fled_cdev)
@@ -262,9 +261,8 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)
                        if (ret < 0)
                                return ret;
 
-                       v4l2_flash_set_led_brightness(v4l2_flash,
-                                                       ctrls[TORCH_INTENSITY]);
-                       return 0;
+                       return v4l2_flash_set_led_brightness(v4l2_flash,
+                                                            ctrls[TORCH_INTENSITY]);
                }
                break;
        case V4L2_CID_FLASH_STROBE_SOURCE:
@@ -511,13 +509,19 @@ static int __sync_device_with_v4l2_controls(struct v4l2_flash *v4l2_flash)
        struct v4l2_ctrl **ctrls = v4l2_flash->ctrls;
        int ret = 0;
 
-       if (ctrls[TORCH_INTENSITY])
-               v4l2_flash_set_led_brightness(v4l2_flash,
-                                             ctrls[TORCH_INTENSITY]);
+       if (ctrls[TORCH_INTENSITY]) {
+               ret = v4l2_flash_set_led_brightness(v4l2_flash,
+                                                   ctrls[TORCH_INTENSITY]);
+               if (ret < 0)
+                       return ret;
+       }
 
-       if (ctrls[INDICATOR_INTENSITY])
-               v4l2_flash_set_led_brightness(v4l2_flash,
-                                               ctrls[INDICATOR_INTENSITY]);
+       if (ctrls[INDICATOR_INTENSITY]) {
+               ret = v4l2_flash_set_led_brightness(v4l2_flash,
+                                                   ctrls[INDICATOR_INTENSITY]);
+               if (ret < 0)
+                       return ret;
+       }
 
        if (ctrls[FLASH_TIMEOUT]) {
                if (WARN_ON_ONCE(!fled_cdev))