[PATCH v2 2/3] toshiba_acpi: Change error checking logic from TCI functions

2016-08-29 Thread Azael Avalos
Currently the success/error checking logic is intermixed, making the
code a bit cumbersome to understand.

This patch changes the affected functions to first check for errors
and take appropriate actions, then check for the supported features.

This patch also separates the error check from the acpi_status and
the tci_raw function call error check, as those two are completely
unrelated and were nested in if/else statements.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 226 ++--
 1 file changed, 138 insertions(+), 88 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 54dea64..cc14e80 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -476,10 +476,15 @@ static void toshiba_illumination_available(struct 
toshiba_acpi_dev *dev)
 
status = tci_raw(dev, in, out);
sci_close(dev);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query Illumination support failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->illumination_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->illumination_supported = 1;
 }
 
 static void toshiba_illumination_set(struct led_classdev *cdev,
@@ -544,24 +549,28 @@ static void toshiba_kbd_illum_available(struct 
toshiba_acpi_dev *dev)
sci_close(dev);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query kbd illumination support failed\n");
-   } else if (out[0] == TOS_SUCCESS) {
-   /*
-* Check for keyboard backlight timeout max value,
-* previous kbd backlight implementation set this to
-* 0x3c0003, and now the new implementation set this
-* to 0x3c001a, use this to distinguish between them.
-*/
-   if (out[3] == SCI_KBD_TIME_MAX)
-   dev->kbd_type = 2;
-   else
-   dev->kbd_type = 1;
-   /* Get the current keyboard backlight mode */
-   dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
-   /* Get the current time (1-60 seconds) */
-   dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
-   /* Flag as supported */
-   dev->kbd_illum_supported = 1;
+   return;
}
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   /*
+* Check for keyboard backlight timeout max value,
+* previous kbd backlight implementation set this to
+* 0x3c0003, and now the new implementation set this
+* to 0x3c001a, use this to distinguish between them.
+*/
+   if (out[3] == SCI_KBD_TIME_MAX)
+   dev->kbd_type = 2;
+   else
+   dev->kbd_type = 1;
+   /* Get the current keyboard backlight mode */
+   dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
+   /* Get the current time (1-60 seconds) */
+   dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
+   /* Flag as supported */
+   dev->kbd_illum_supported = 1;
 }
 
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
@@ -680,7 +689,10 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return;
+   }
+
+   if (out[0] == TOS_INPUT_DATA_ERROR) {
/*
 * If we receive 0x8300 (Input Data Error), it means that the
 * LED device is present, but that we just screwed the input
@@ -692,10 +704,15 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
 */
in[3] = 1;
status = tci_raw(dev, in, out);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->eco_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->eco_supported = 1;
}
 }
 
@@ -712,10 +729,11 @@ toshiba_eco_mode_get_status(struct led_classdev *cdev)
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
return LED_OFF;
-   } else if (out[0] != TOS_SUCCESS) {
-   return LED_OFF;
}
 
+   if (out[0] != TOS_SUCCESS)
+   return LED_OFF;
+
return out[2] ? LED_FULL : LED_OFF;
 }
 
@@ -749,10 +767,15 @@ static void toshiba_accelerometer_available(struct 

[PATCH v2 2/3] toshiba_acpi: Change error checking logic from TCI functions

2016-08-29 Thread Azael Avalos
Currently the success/error checking logic is intermixed, making the
code a bit cumbersome to understand.

This patch changes the affected functions to first check for errors
and take appropriate actions, then check for the supported features.

This patch also separates the error check from the acpi_status and
the tci_raw function call error check, as those two are completely
unrelated and were nested in if/else statements.

Signed-off-by: Azael Avalos 
---
 drivers/platform/x86/toshiba_acpi.c | 226 ++--
 1 file changed, 138 insertions(+), 88 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c 
b/drivers/platform/x86/toshiba_acpi.c
index 54dea64..cc14e80 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -476,10 +476,15 @@ static void toshiba_illumination_available(struct 
toshiba_acpi_dev *dev)
 
status = tci_raw(dev, in, out);
sci_close(dev);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query Illumination support failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->illumination_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->illumination_supported = 1;
 }
 
 static void toshiba_illumination_set(struct led_classdev *cdev,
@@ -544,24 +549,28 @@ static void toshiba_kbd_illum_available(struct 
toshiba_acpi_dev *dev)
sci_close(dev);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to query kbd illumination support failed\n");
-   } else if (out[0] == TOS_SUCCESS) {
-   /*
-* Check for keyboard backlight timeout max value,
-* previous kbd backlight implementation set this to
-* 0x3c0003, and now the new implementation set this
-* to 0x3c001a, use this to distinguish between them.
-*/
-   if (out[3] == SCI_KBD_TIME_MAX)
-   dev->kbd_type = 2;
-   else
-   dev->kbd_type = 1;
-   /* Get the current keyboard backlight mode */
-   dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
-   /* Get the current time (1-60 seconds) */
-   dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
-   /* Flag as supported */
-   dev->kbd_illum_supported = 1;
+   return;
}
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   /*
+* Check for keyboard backlight timeout max value,
+* previous kbd backlight implementation set this to
+* 0x3c0003, and now the new implementation set this
+* to 0x3c001a, use this to distinguish between them.
+*/
+   if (out[3] == SCI_KBD_TIME_MAX)
+   dev->kbd_type = 2;
+   else
+   dev->kbd_type = 1;
+   /* Get the current keyboard backlight mode */
+   dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
+   /* Get the current time (1-60 seconds) */
+   dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
+   /* Flag as supported */
+   dev->kbd_illum_supported = 1;
 }
 
 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
@@ -680,7 +689,10 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
status = tci_raw(dev, in, out);
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   } else if (out[0] == TOS_INPUT_DATA_ERROR) {
+   return;
+   }
+
+   if (out[0] == TOS_INPUT_DATA_ERROR) {
/*
 * If we receive 0x8300 (Input Data Error), it means that the
 * LED device is present, but that we just screwed the input
@@ -692,10 +704,15 @@ static void toshiba_eco_mode_available(struct 
toshiba_acpi_dev *dev)
 */
in[3] = 1;
status = tci_raw(dev, in, out);
-   if (ACPI_FAILURE(status))
+   if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
-   else if (out[0] == TOS_SUCCESS)
-   dev->eco_supported = 1;
+   return;
+   }
+
+   if (out[0] != TOS_SUCCESS)
+   return;
+
+   dev->eco_supported = 1;
}
 }
 
@@ -712,10 +729,11 @@ toshiba_eco_mode_get_status(struct led_classdev *cdev)
if (ACPI_FAILURE(status)) {
pr_err("ACPI call to get ECO led failed\n");
return LED_OFF;
-   } else if (out[0] != TOS_SUCCESS) {
-   return LED_OFF;
}
 
+   if (out[0] != TOS_SUCCESS)
+   return LED_OFF;
+
return out[2] ? LED_FULL : LED_OFF;
 }
 
@@ -749,10 +767,15 @@ static void toshiba_accelerometer_available(struct 
toshiba_acpi_dev *dev)
 *