Patchwork acpi: brightness: check get_setting return

login
register
mail settings
Submitter Colin King
Date May 7, 2013, 9:31 a.m.
Message ID <1367919077-19455-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/242089/
State Accepted
Headers show

Comments

Colin King - May 7, 2013, 9:31 a.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID #997319: Unchecked return value (CHECKED_RETURN)

We should really check the get_setting() return to see if it failed
rather than blindly assuming it worked OK.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/brightness/brightness.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Alex Hung - May 9, 2013, 5:53 a.m.
On 05/07/2013 05:31 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997319: Unchecked return value (CHECKED_RETURN)
>
> We should really check the get_setting() return to see if it failed
> rather than blindly assuming it worked OK.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/brightness/brightness.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/acpi/brightness/brightness.c b/src/acpi/brightness/brightness.c
> index f523cbf..b4b588e 100644
> --- a/src/acpi/brightness/brightness.c
> +++ b/src/acpi/brightness/brightness.c
> @@ -158,7 +158,11 @@ static int brightness_test2(fwts_framework *fw)
>
>   					for (i=0;i<=max_brightness;i++) {
>   						set_setting(entry->d_name, "brightness", i);
> -						get_setting(entry->d_name, "actual_brightness", &actual_brightness);
> +						if (get_setting(entry->d_name, "actual_brightness", &actual_brightness) != FWTS_OK) {
> +							fwts_log_info(fw, "Cannot get brightness setting %d for backlight %s.", i, entry->d_name);
> +							failed++;
> +							continue;
> +						}
>   						if (actual_brightness != i)  {
>   							fwts_log_info(fw, "Actual brightness %d does not match the brightnesss level %d just set for backlight %s.", actual_brightness, i, entry->d_name);
>   							failed++;
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - May 20, 2013, 7:41 a.m.
On Tue, May 7, 2013 at 5:31 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997319: Unchecked return value (CHECKED_RETURN)
>
> We should really check the get_setting() return to see if it failed
> rather than blindly assuming it worked OK.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/brightness/brightness.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/acpi/brightness/brightness.c b/src/acpi/brightness/brightness.c
> index f523cbf..b4b588e 100644
> --- a/src/acpi/brightness/brightness.c
> +++ b/src/acpi/brightness/brightness.c
> @@ -158,7 +158,11 @@ static int brightness_test2(fwts_framework *fw)
>
>                                         for (i=0;i<=max_brightness;i++) {
>                                                 set_setting(entry->d_name, "brightness", i);
> -                                               get_setting(entry->d_name, "actual_brightness", &actual_brightness);
> +                                               if (get_setting(entry->d_name, "actual_brightness", &actual_brightness) != FWTS_OK) {
> +                                                       fwts_log_info(fw, "Cannot get brightness setting %d for backlight %s.", i, entry->d_name);
> +                                                       failed++;
> +                                                       continue;
> +                                               }
>                                                 if (actual_brightness != i)  {
>                                                         fwts_log_info(fw, "Actual brightness %d does not match the brightnesss level %d just set for backlight %s.", actual_brightness, i, entry->d_name);
>                                                         failed++;
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>>

Patch

diff --git a/src/acpi/brightness/brightness.c b/src/acpi/brightness/brightness.c
index f523cbf..b4b588e 100644
--- a/src/acpi/brightness/brightness.c
+++ b/src/acpi/brightness/brightness.c
@@ -158,7 +158,11 @@  static int brightness_test2(fwts_framework *fw)
 
 					for (i=0;i<=max_brightness;i++) {
 						set_setting(entry->d_name, "brightness", i);
-						get_setting(entry->d_name, "actual_brightness", &actual_brightness);
+						if (get_setting(entry->d_name, "actual_brightness", &actual_brightness) != FWTS_OK) {
+							fwts_log_info(fw, "Cannot get brightness setting %d for backlight %s.", i, entry->d_name);
+							failed++;
+							continue;
+						}
 						if (actual_brightness != i)  {
 							fwts_log_info(fw, "Actual brightness %d does not match the brightnesss level %d just set for backlight %s.", actual_brightness, i, entry->d_name);
 							failed++;