Patchwork acpi: method: use a helper function for MethodReturnNullObj errors

login
register
mail settings
Submitter Colin King
Date Jan. 8, 2013, 6:11 p.m.
Message ID <1357668677-17955-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/210469/
State Accepted
Headers show

Comments

Colin King - Jan. 8, 2013, 6:11 p.m.
From: Colin Ian King <colin.king@canonical.com>

Add and use a helper function for conditions where a null object
is returned.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/method/method.c | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)
Keng-Yu Lin - Jan. 23, 2013, 7:17 a.m.
On Wed, Jan 9, 2013 at 2:11 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Add and use a helper function for conditions where a null object
> is returned.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/method/method.c | 45 ++++++++++++++++++++++++++-------------------
>  1 file changed, 26 insertions(+), 19 deletions(-)
>
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index 371fcb5..2014755 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -298,6 +298,20 @@ static void method_passed_sane_uint64(
>  }
>
>  /*
> + *  method_failed_null_return()
> + *     helper function to report often used failed NULL object return
> + */
> +static void method_failed_null_object(
> +       fwts_framework *fw,
> +       const char *name,
> +       const char *type)
> +{
> +       fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> +               "%s returned a NULL object, and did not "
> +               "return %s.", name, type);
> +}
> +
> +/*
>   *  method_init()
>   *     initialize ACPI
>   */
> @@ -518,10 +532,8 @@ static int method_check_type__(
>  {
>         ACPI_OBJECT *obj;
>
> -       if ((buf == NULL) || (buf->Pointer == NULL)){
> -               fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> -                       "Method %s returned a NULL object, and did not "
> -                       "return %s.", name, type_name);
> +       if ((buf == NULL) || (buf->Pointer == NULL)) {
> +               method_failed_null_object(fw, name, type_name);
>                 return FWTS_ERROR;
>         }
>
> @@ -762,11 +774,10 @@ static void method_test_HID_return(
>         FWTS_UNUSED(private);
>
>         if (obj == NULL) {
> -               fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> -                       "Method %s returned a NULL object, and did not "
> -                       "return a buffer or integer.", name);
> +               method_failed_null_object(fw, name, "a buffer or integer");
>                 return;
>         }
> +
>         switch (obj->Type) {
>         case ACPI_TYPE_STRING:
>                 if (obj->String.Pointer) {
> @@ -873,11 +884,10 @@ static void method_test_SUB_return(
>         FWTS_UNUSED(private);
>
>         if (obj == NULL) {
> -               fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> -                       "Method %s returned a NULL object, and did not "
> -                       "return a buffer or integer.", name);
> +               method_failed_null_object(fw, name, "a buffer or integer");
>                 return;
>         }
> +
>         if (obj->Type == ACPI_TYPE_STRING)
>                 if (obj->String.Pointer) {
>                         if (method_valid_HID_string(obj->String.Pointer))
> @@ -928,12 +938,11 @@ static void method_test_UID_return(
>         FWTS_UNUSED(buf);
>         FWTS_UNUSED(private);
>
> -       if (obj == NULL){
> -               fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> -                       "%s returned a NULL object, and did not "
> -                       "return a buffer or integer.", name);
> +       if (obj == NULL) {
> +               method_failed_null_object(fw, name, "a buffer or integer");
>                 return;
>         }
> +
>         switch (obj->Type) {
>         case ACPI_TYPE_STRING:
>                 if (obj->String.Pointer)
> @@ -4618,13 +4627,11 @@ static void method_test_DDC_return(
>
>         FWTS_UNUSED(buf);
>
> -       if (obj == NULL){
> -               fwts_failed(fw, LOG_LEVEL_MEDIUM,
> -                       "MethodReturnNullObj",
> -                       "Method %s returned a NULL object, and did not "
> -                       "return a buffer or integer.", name);
> +       if (obj == NULL) {
> +               method_failed_null_object(fw, name, "a buffer or integer");
>                 return;
>         }
> +
>         switch (obj->Type) {
>         case ACPI_TYPE_BUFFER:
>                 if (requested != obj->Buffer.Length) {
> --
> 1.8.0
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Ivan Hu - Jan. 31, 2013, 6:17 a.m.
On 01/09/2013 02:11 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Add and use a helper function for conditions where a null object
> is returned.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/method/method.c | 45 ++++++++++++++++++++++++++-------------------
>   1 file changed, 26 insertions(+), 19 deletions(-)
>
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index 371fcb5..2014755 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -298,6 +298,20 @@ static void method_passed_sane_uint64(
>   }
>
>   /*
> + *  method_failed_null_return()
> + *	helper function to report often used failed NULL object return
> + */
> +static void method_failed_null_object(
> +	fwts_framework *fw,
> +	const char *name,
> +	const char *type)
> +{
> +	fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> +		"%s returned a NULL object, and did not "
> +		"return %s.", name, type);
> +}
> +
> +/*
>    *  method_init()
>    *	initialize ACPI
>    */
> @@ -518,10 +532,8 @@ static int method_check_type__(
>   {
>   	ACPI_OBJECT *obj;
>
> -	if ((buf == NULL) || (buf->Pointer == NULL)){
> -		fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> -			"Method %s returned a NULL object, and did not "
> -			"return %s.", name, type_name);
> +	if ((buf == NULL) || (buf->Pointer == NULL)) {
> +		method_failed_null_object(fw, name, type_name);
>   		return FWTS_ERROR;
>   	}
>
> @@ -762,11 +774,10 @@ static void method_test_HID_return(
>   	FWTS_UNUSED(private);
>
>   	if (obj == NULL) {
> -		fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> -			"Method %s returned a NULL object, and did not "
> -			"return a buffer or integer.", name);
> +		method_failed_null_object(fw, name, "a buffer or integer");
>   		return;
>   	}
> +
>   	switch (obj->Type) {
>   	case ACPI_TYPE_STRING:
>   		if (obj->String.Pointer) {
> @@ -873,11 +884,10 @@ static void method_test_SUB_return(
>   	FWTS_UNUSED(private);
>
>   	if (obj == NULL) {
> -		fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> -			"Method %s returned a NULL object, and did not "
> -			"return a buffer or integer.", name);
> +		method_failed_null_object(fw, name, "a buffer or integer");
>   		return;
>   	}
> +
>   	if (obj->Type == ACPI_TYPE_STRING)
>   		if (obj->String.Pointer) {
>   			if (method_valid_HID_string(obj->String.Pointer))
> @@ -928,12 +938,11 @@ static void method_test_UID_return(
>   	FWTS_UNUSED(buf);
>   	FWTS_UNUSED(private);
>
> -	if (obj == NULL){
> -		fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
> -			"%s returned a NULL object, and did not "
> -			"return a buffer or integer.", name);
> +	if (obj == NULL) {
> +		method_failed_null_object(fw, name, "a buffer or integer");
>   		return;
>   	}
> +
>   	switch (obj->Type) {
>   	case ACPI_TYPE_STRING:
>   		if (obj->String.Pointer)
> @@ -4618,13 +4627,11 @@ static void method_test_DDC_return(
>
>   	FWTS_UNUSED(buf);
>
> -	if (obj == NULL){
> -		fwts_failed(fw, LOG_LEVEL_MEDIUM,
> -			"MethodReturnNullObj",
> -			"Method %s returned a NULL object, and did not "
> -			"return a buffer or integer.", name);
> +	if (obj == NULL) {
> +		method_failed_null_object(fw, name, "a buffer or integer");
>   		return;
>   	}
> +
>   	switch (obj->Type) {
>   	case ACPI_TYPE_BUFFER:
>   		if (requested != obj->Buffer.Length) {
>
Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
index 371fcb5..2014755 100644
--- a/src/acpi/method/method.c
+++ b/src/acpi/method/method.c
@@ -298,6 +298,20 @@  static void method_passed_sane_uint64(
 }
 
 /*
+ *  method_failed_null_return()
+ *	helper function to report often used failed NULL object return
+ */
+static void method_failed_null_object(
+	fwts_framework *fw,
+	const char *name,
+	const char *type)
+{
+	fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
+		"%s returned a NULL object, and did not "
+		"return %s.", name, type);
+}
+
+/*
  *  method_init()
  *	initialize ACPI
  */
@@ -518,10 +532,8 @@  static int method_check_type__(
 {
 	ACPI_OBJECT *obj;
 
-	if ((buf == NULL) || (buf->Pointer == NULL)){
-		fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
-			"Method %s returned a NULL object, and did not "
-			"return %s.", name, type_name);
+	if ((buf == NULL) || (buf->Pointer == NULL)) {
+		method_failed_null_object(fw, name, type_name);
 		return FWTS_ERROR;
 	}
 
@@ -762,11 +774,10 @@  static void method_test_HID_return(
 	FWTS_UNUSED(private);
 
 	if (obj == NULL) {
-		fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
-			"Method %s returned a NULL object, and did not "
-			"return a buffer or integer.", name);
+		method_failed_null_object(fw, name, "a buffer or integer");
 		return;
 	}
+
 	switch (obj->Type) {
 	case ACPI_TYPE_STRING:
 		if (obj->String.Pointer) {
@@ -873,11 +884,10 @@  static void method_test_SUB_return(
 	FWTS_UNUSED(private);
 
 	if (obj == NULL) {
-		fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
-			"Method %s returned a NULL object, and did not "
-			"return a buffer or integer.", name);
+		method_failed_null_object(fw, name, "a buffer or integer");
 		return;
 	}
+
 	if (obj->Type == ACPI_TYPE_STRING)
 		if (obj->String.Pointer) {
 			if (method_valid_HID_string(obj->String.Pointer))
@@ -928,12 +938,11 @@  static void method_test_UID_return(
 	FWTS_UNUSED(buf);
 	FWTS_UNUSED(private);
 
-	if (obj == NULL){
-		fwts_failed(fw, LOG_LEVEL_MEDIUM, "MethodReturnNullObj",
-			"%s returned a NULL object, and did not "
-			"return a buffer or integer.", name);
+	if (obj == NULL) {
+		method_failed_null_object(fw, name, "a buffer or integer");
 		return;
 	}
+
 	switch (obj->Type) {
 	case ACPI_TYPE_STRING:
 		if (obj->String.Pointer)
@@ -4618,13 +4627,11 @@  static void method_test_DDC_return(
 
 	FWTS_UNUSED(buf);
 
-	if (obj == NULL){
-		fwts_failed(fw, LOG_LEVEL_MEDIUM,
-			"MethodReturnNullObj",
-			"Method %s returned a NULL object, and did not "
-			"return a buffer or integer.", name);
+	if (obj == NULL) {
+		method_failed_null_object(fw, name, "a buffer or integer");
 		return;
 	}
+
 	switch (obj->Type) {
 	case ACPI_TYPE_BUFFER:
 		if (requested != obj->Buffer.Length) {