Patchwork bios: smbios: minor re-structure of test1

login
register
mail settings
Submitter Colin King
Date June 20, 2013, 8:28 a.m.
Message ID <1371716929-10489-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/252798/
State Accepted
Headers show

Comments

Colin King - June 20, 2013, 8:28 a.m.
From: Colin Ian King <colin.king@canonical.com>

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/bios/smbios/smbios.c | 90 ++++++++++++++++++++++++------------------------
 1 file changed, 45 insertions(+), 45 deletions(-)
Keng-Yu Lin - June 20, 2013, 9:04 a.m.
On Thu, Jun 20, 2013 at 4:28 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/bios/smbios/smbios.c | 90 ++++++++++++++++++++++++------------------------
>  1 file changed, 45 insertions(+), 45 deletions(-)
>
> diff --git a/src/bios/smbios/smbios.c b/src/bios/smbios/smbios.c
> index 6fc2fa4..57c8999 100644
> --- a/src/bios/smbios/smbios.c
> +++ b/src/bios/smbios/smbios.c
> @@ -56,66 +56,66 @@ static int smbios_test1(fwts_framework *fw)
>         fwts_smbios_entry entry;
>         fwts_smbios_type  type;
>         uint16_t          version;
> +       uint8_t checksum;
> +       static char warning[] =
> +               "This field is not checked by the kernel, and so will not affect the system, "
> +               "however it should be fixed to conform to the latest version of the "
> +               "System Management BIOS (SMBIOS) Reference Specification. ";
>
>         fwts_log_info(fw,
>                 "This test tries to find and sanity check the SMBIOS "
>                 "data structures.");
> -       if ((addr = fwts_smbios_find_entry(fw, &entry, &type, &version)) == NULL)
> +
> +       if ((addr = fwts_smbios_find_entry(fw, &entry, &type, &version)) == NULL) {
>                 fwts_failed(fw, LOG_LEVEL_MEDIUM,
>                         "SMBIOSNoEntryPoint",
>                         "Could not find SMBIOS Table Entry Point.");
> -       else {
> -               uint8_t checksum;
> -               static char warning[] =
> -                       "This field is not checked by the kernel, and so will not affect the system, "
> -                       "however it should be fixed to conform to the latest version of the "
> -                       "System Management BIOS (SMBIOS) Reference Specification. ";
> -
> -               fwts_passed(fw, "Found SMBIOS Table Entry Point at %p", addr);
> +               return FWTS_OK;
> +       }
>
> -               smbios_dump_entry(fw, &entry, type);
> +       fwts_passed(fw, "Found SMBIOS Table Entry Point at %p", addr);
> +       smbios_dump_entry(fw, &entry, type);
>
> -               if (type == FWTS_SMBIOS) {
> -                       checksum = fwts_checksum((uint8_t*)&entry, sizeof(fwts_smbios_entry));
> -                       if (checksum != 0) {
> -                               fwts_failed(fw, LOG_LEVEL_HIGH,
> -                                       "SMBIOSBadChecksum",
> -                                       "SMBIOS Table Entry Point Checksum is 0x%2.2x, should be 0x%2.2x",
> -                                               entry.checksum, (uint8_t)(entry.checksum - checksum));
> -                       }
> -                       if (entry.length != 0x1f) {
> -                               fwts_failed(fw, LOG_LEVEL_LOW,
> -                                       "SMBIOSBadEntryLength",
> -                                       "SMBIOS Table Entry Point Length is 0x%2.2x, should be 0x1f", entry.length);
> -                               fwts_advice(fw, "%s Note that version 2.1 of the specification incorrectly stated that the "
> -                                       "Entry Point Length should be 0x1e when it should be 0x1f.", warning);
> -                       }
> -               }
> -               if (memcmp(entry.anchor_string, "_DMI_", 5) != 0) {
> -                       fwts_failed(fw, LOG_LEVEL_HIGH,
> -                               "SMBIOSBadIntermediateAnchor",
> -                               "SMBIOS Table Entry Intermediate Anchor String was '%5.5s' and should be '_DMI_'.",
> -                               entry.anchor_string);
> -                       fwts_advice(fw, "%s", warning);
> -               }
> -               /* Intermediate checksum for legacy DMI */
> -               checksum = fwts_checksum(((uint8_t*)&entry)+16, 15);
> +       if (type == FWTS_SMBIOS) {
> +               checksum = fwts_checksum((uint8_t*)&entry, sizeof(fwts_smbios_entry));
>                 if (checksum != 0) {
>                         fwts_failed(fw, LOG_LEVEL_HIGH,
>                                 "SMBIOSBadChecksum",
> -                               "SMBIOS Table Entry Point Intermediate Checksum is 0x%2.2x, should be 0x%2.2x",
> -                                       entry.intermediate_checksum,
> -                                       (uint8_t)(entry.intermediate_checksum - checksum));
> +                               "SMBIOS Table Entry Point Checksum is 0x%2.2x, should be 0x%2.2x",
> +                                       entry.checksum, (uint8_t)(entry.checksum - checksum));
>                 }
> -               if ((entry.struct_table_length > 0) && (entry.struct_table_address == 0)) {
> -                       fwts_failed(fw, LOG_LEVEL_HIGH,
> -                               "SMBIOSBadTableAddress",
> -                               "SMBIOS Table Entry Structure Table Address is NULL and should be defined.");
> -                       fwts_advice(fw,
> -                               "The address of the SMBIOS Structure Tables must be defined if the "
> -                               "length of these tables is defined.");
> +               if (entry.length != 0x1f) {
> +                       fwts_failed(fw, LOG_LEVEL_LOW,
> +                               "SMBIOSBadEntryLength",
> +                               "SMBIOS Table Entry Point Length is 0x%2.2x, should be 0x1f", entry.length);
> +                       fwts_advice(fw, "%s Note that version 2.1 of the specification incorrectly stated that the "
> +                               "Entry Point Length should be 0x1e when it should be 0x1f.", warning);
>                 }
>         }
> +       if (memcmp(entry.anchor_string, "_DMI_", 5) != 0) {
> +               fwts_failed(fw, LOG_LEVEL_HIGH,
> +                       "SMBIOSBadIntermediateAnchor",
> +                       "SMBIOS Table Entry Intermediate Anchor String was '%5.5s' and should be '_DMI_'.",
> +                       entry.anchor_string);
> +               fwts_advice(fw, "%s", warning);
> +       }
> +       /* Intermediate checksum for legacy DMI */
> +       checksum = fwts_checksum(((uint8_t*)&entry)+16, 15);
> +       if (checksum != 0) {
> +               fwts_failed(fw, LOG_LEVEL_HIGH,
> +                       "SMBIOSBadChecksum",
> +                       "SMBIOS Table Entry Point Intermediate Checksum is 0x%2.2x, should be 0x%2.2x",
> +                               entry.intermediate_checksum,
> +                               (uint8_t)(entry.intermediate_checksum - checksum));
> +       }
> +       if ((entry.struct_table_length > 0) && (entry.struct_table_address == 0)) {
> +               fwts_failed(fw, LOG_LEVEL_HIGH,
> +                       "SMBIOSBadTableAddress",
> +                       "SMBIOS Table Entry Structure Table Address is NULL and should be defined.");
> +               fwts_advice(fw,
> +                       "The address of the SMBIOS Structure Tables must be defined if the "
> +                       "length of these tables is defined.");
> +       }
>
>         return FWTS_OK;
>  }
> --
> 1.8.3.1
>

many thanks, Colin. :-)

Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Ivan Hu - June 20, 2013, 9:50 a.m.
On 06/20/2013 04:28 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/bios/smbios/smbios.c | 90 ++++++++++++++++++++++++------------------------
>   1 file changed, 45 insertions(+), 45 deletions(-)
>
> diff --git a/src/bios/smbios/smbios.c b/src/bios/smbios/smbios.c
> index 6fc2fa4..57c8999 100644
> --- a/src/bios/smbios/smbios.c
> +++ b/src/bios/smbios/smbios.c
> @@ -56,66 +56,66 @@ static int smbios_test1(fwts_framework *fw)
>   	fwts_smbios_entry entry;
>   	fwts_smbios_type  type;
>   	uint16_t	  version;
> +	uint8_t checksum;
> +	static char warning[] =
> +		"This field is not checked by the kernel, and so will not affect the system, "
> +		"however it should be fixed to conform to the latest version of the "
> +		"System Management BIOS (SMBIOS) Reference Specification. ";
>
>   	fwts_log_info(fw,
>   		"This test tries to find and sanity check the SMBIOS "
>   		"data structures.");
> -	if ((addr = fwts_smbios_find_entry(fw, &entry, &type, &version)) == NULL)
> +
> +	if ((addr = fwts_smbios_find_entry(fw, &entry, &type, &version)) == NULL) {
>   		fwts_failed(fw, LOG_LEVEL_MEDIUM,
>   			"SMBIOSNoEntryPoint",
>   			"Could not find SMBIOS Table Entry Point.");
> -	else {
> -		uint8_t checksum;
> -		static char warning[] =
> -			"This field is not checked by the kernel, and so will not affect the system, "
> -			"however it should be fixed to conform to the latest version of the "
> -			"System Management BIOS (SMBIOS) Reference Specification. ";
> -
> -		fwts_passed(fw, "Found SMBIOS Table Entry Point at %p", addr);
> +		return FWTS_OK;
> +	}
>
> -		smbios_dump_entry(fw, &entry, type);
> +	fwts_passed(fw, "Found SMBIOS Table Entry Point at %p", addr);
> +	smbios_dump_entry(fw, &entry, type);
>   		
> -		if (type == FWTS_SMBIOS) {
> -			checksum = fwts_checksum((uint8_t*)&entry, sizeof(fwts_smbios_entry));
> -			if (checksum != 0) {
> -				fwts_failed(fw, LOG_LEVEL_HIGH,
> -					"SMBIOSBadChecksum",
> -					"SMBIOS Table Entry Point Checksum is 0x%2.2x, should be 0x%2.2x",
> -						entry.checksum, (uint8_t)(entry.checksum - checksum));
> -			}
> -			if (entry.length != 0x1f) {
> -				fwts_failed(fw, LOG_LEVEL_LOW,
> -					"SMBIOSBadEntryLength",
> -					"SMBIOS Table Entry Point Length is 0x%2.2x, should be 0x1f", entry.length);
> -				fwts_advice(fw, "%s Note that version 2.1 of the specification incorrectly stated that the "
> -					"Entry Point Length should be 0x1e when it should be 0x1f.", warning);
> -			}
> -		}
> -		if (memcmp(entry.anchor_string, "_DMI_", 5) != 0) {
> -			fwts_failed(fw, LOG_LEVEL_HIGH,
> -				"SMBIOSBadIntermediateAnchor",
> -				"SMBIOS Table Entry Intermediate Anchor String was '%5.5s' and should be '_DMI_'.",
> -				entry.anchor_string);
> -			fwts_advice(fw, "%s", warning);
> -		}
> -		/* Intermediate checksum for legacy DMI */
> -		checksum = fwts_checksum(((uint8_t*)&entry)+16, 15);
> +	if (type == FWTS_SMBIOS) {
> +		checksum = fwts_checksum((uint8_t*)&entry, sizeof(fwts_smbios_entry));
>   		if (checksum != 0) {
>   			fwts_failed(fw, LOG_LEVEL_HIGH,
>   				"SMBIOSBadChecksum",
> -				"SMBIOS Table Entry Point Intermediate Checksum is 0x%2.2x, should be 0x%2.2x",
> -					entry.intermediate_checksum,
> -					(uint8_t)(entry.intermediate_checksum - checksum));
> +				"SMBIOS Table Entry Point Checksum is 0x%2.2x, should be 0x%2.2x",
> +					entry.checksum, (uint8_t)(entry.checksum - checksum));
>   		}
> -		if ((entry.struct_table_length > 0) && (entry.struct_table_address == 0)) {
> -			fwts_failed(fw, LOG_LEVEL_HIGH,
> -				"SMBIOSBadTableAddress",
> -				"SMBIOS Table Entry Structure Table Address is NULL and should be defined.");
> -			fwts_advice(fw,
> -				"The address of the SMBIOS Structure Tables must be defined if the "
> -				"length of these tables is defined.");
> +		if (entry.length != 0x1f) {
> +			fwts_failed(fw, LOG_LEVEL_LOW,
> +				"SMBIOSBadEntryLength",
> +				"SMBIOS Table Entry Point Length is 0x%2.2x, should be 0x1f", entry.length);
> +			fwts_advice(fw, "%s Note that version 2.1 of the specification incorrectly stated that the "
> +				"Entry Point Length should be 0x1e when it should be 0x1f.", warning);
>   		}
>   	}
> +	if (memcmp(entry.anchor_string, "_DMI_", 5) != 0) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH,
> +			"SMBIOSBadIntermediateAnchor",
> +			"SMBIOS Table Entry Intermediate Anchor String was '%5.5s' and should be '_DMI_'.",
> +			entry.anchor_string);
> +		fwts_advice(fw, "%s", warning);
> +	}
> +	/* Intermediate checksum for legacy DMI */
> +	checksum = fwts_checksum(((uint8_t*)&entry)+16, 15);
> +	if (checksum != 0) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH,
> +			"SMBIOSBadChecksum",
> +			"SMBIOS Table Entry Point Intermediate Checksum is 0x%2.2x, should be 0x%2.2x",
> +				entry.intermediate_checksum,
> +				(uint8_t)(entry.intermediate_checksum - checksum));
> +	}
> +	if ((entry.struct_table_length > 0) && (entry.struct_table_address == 0)) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH,
> +			"SMBIOSBadTableAddress",
> +			"SMBIOS Table Entry Structure Table Address is NULL and should be defined.");
> +		fwts_advice(fw,
> +			"The address of the SMBIOS Structure Tables must be defined if the "
> +			"length of these tables is defined.");
> +	}
>
>   	return FWTS_OK;
>   }
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/bios/smbios/smbios.c b/src/bios/smbios/smbios.c
index 6fc2fa4..57c8999 100644
--- a/src/bios/smbios/smbios.c
+++ b/src/bios/smbios/smbios.c
@@ -56,66 +56,66 @@  static int smbios_test1(fwts_framework *fw)
 	fwts_smbios_entry entry;
 	fwts_smbios_type  type;
 	uint16_t	  version;
+	uint8_t checksum;
+	static char warning[] = 
+		"This field is not checked by the kernel, and so will not affect the system, "
+		"however it should be fixed to conform to the latest version of the "
+		"System Management BIOS (SMBIOS) Reference Specification. ";
 
 	fwts_log_info(fw,
 		"This test tries to find and sanity check the SMBIOS "
 		"data structures.");
-	if ((addr = fwts_smbios_find_entry(fw, &entry, &type, &version)) == NULL)
+
+	if ((addr = fwts_smbios_find_entry(fw, &entry, &type, &version)) == NULL) {
 		fwts_failed(fw, LOG_LEVEL_MEDIUM,
 			"SMBIOSNoEntryPoint",
 			"Could not find SMBIOS Table Entry Point.");
-	else {
-		uint8_t checksum;
-		static char warning[] = 
-			"This field is not checked by the kernel, and so will not affect the system, "
-			"however it should be fixed to conform to the latest version of the "
-			"System Management BIOS (SMBIOS) Reference Specification. ";
-
-		fwts_passed(fw, "Found SMBIOS Table Entry Point at %p", addr);
+		return FWTS_OK;
+	}
 
-		smbios_dump_entry(fw, &entry, type);
+	fwts_passed(fw, "Found SMBIOS Table Entry Point at %p", addr);
+	smbios_dump_entry(fw, &entry, type);
 		
-		if (type == FWTS_SMBIOS) {
-			checksum = fwts_checksum((uint8_t*)&entry, sizeof(fwts_smbios_entry));
-			if (checksum != 0) {
-				fwts_failed(fw, LOG_LEVEL_HIGH,
-					"SMBIOSBadChecksum",
-					"SMBIOS Table Entry Point Checksum is 0x%2.2x, should be 0x%2.2x",
-						entry.checksum, (uint8_t)(entry.checksum - checksum));
-			}
-			if (entry.length != 0x1f) {
-				fwts_failed(fw, LOG_LEVEL_LOW,
-					"SMBIOSBadEntryLength",
-					"SMBIOS Table Entry Point Length is 0x%2.2x, should be 0x1f", entry.length);
-				fwts_advice(fw, "%s Note that version 2.1 of the specification incorrectly stated that the "
-					"Entry Point Length should be 0x1e when it should be 0x1f.", warning);
-			}
-		}
-		if (memcmp(entry.anchor_string, "_DMI_", 5) != 0) {
-			fwts_failed(fw, LOG_LEVEL_HIGH,
-				"SMBIOSBadIntermediateAnchor", 
-				"SMBIOS Table Entry Intermediate Anchor String was '%5.5s' and should be '_DMI_'.", 
-				entry.anchor_string);
-			fwts_advice(fw, "%s", warning);
-		}
-		/* Intermediate checksum for legacy DMI */
-		checksum = fwts_checksum(((uint8_t*)&entry)+16, 15);
+	if (type == FWTS_SMBIOS) {
+		checksum = fwts_checksum((uint8_t*)&entry, sizeof(fwts_smbios_entry));
 		if (checksum != 0) {
 			fwts_failed(fw, LOG_LEVEL_HIGH,
 				"SMBIOSBadChecksum",
-				"SMBIOS Table Entry Point Intermediate Checksum is 0x%2.2x, should be 0x%2.2x",
-					entry.intermediate_checksum,
-					(uint8_t)(entry.intermediate_checksum - checksum));
+				"SMBIOS Table Entry Point Checksum is 0x%2.2x, should be 0x%2.2x",
+					entry.checksum, (uint8_t)(entry.checksum - checksum));
 		}
-		if ((entry.struct_table_length > 0) && (entry.struct_table_address == 0)) {
-			fwts_failed(fw, LOG_LEVEL_HIGH,
-				"SMBIOSBadTableAddress",
-				"SMBIOS Table Entry Structure Table Address is NULL and should be defined.");
-			fwts_advice(fw,
-				"The address of the SMBIOS Structure Tables must be defined if the "
-				"length of these tables is defined.");
+		if (entry.length != 0x1f) {
+			fwts_failed(fw, LOG_LEVEL_LOW,
+				"SMBIOSBadEntryLength",
+				"SMBIOS Table Entry Point Length is 0x%2.2x, should be 0x1f", entry.length);
+			fwts_advice(fw, "%s Note that version 2.1 of the specification incorrectly stated that the "
+				"Entry Point Length should be 0x1e when it should be 0x1f.", warning);
 		}
 	}
+	if (memcmp(entry.anchor_string, "_DMI_", 5) != 0) {
+		fwts_failed(fw, LOG_LEVEL_HIGH,
+			"SMBIOSBadIntermediateAnchor", 
+			"SMBIOS Table Entry Intermediate Anchor String was '%5.5s' and should be '_DMI_'.", 
+			entry.anchor_string);
+		fwts_advice(fw, "%s", warning);
+	}
+	/* Intermediate checksum for legacy DMI */
+	checksum = fwts_checksum(((uint8_t*)&entry)+16, 15);
+	if (checksum != 0) {
+		fwts_failed(fw, LOG_LEVEL_HIGH,
+			"SMBIOSBadChecksum",
+			"SMBIOS Table Entry Point Intermediate Checksum is 0x%2.2x, should be 0x%2.2x",
+				entry.intermediate_checksum,
+				(uint8_t)(entry.intermediate_checksum - checksum));
+	}
+	if ((entry.struct_table_length > 0) && (entry.struct_table_address == 0)) {
+		fwts_failed(fw, LOG_LEVEL_HIGH,
+			"SMBIOSBadTableAddress",
+			"SMBIOS Table Entry Structure Table Address is NULL and should be defined.");
+		fwts_advice(fw,
+			"The address of the SMBIOS Structure Tables must be defined if the "
+			"length of these tables is defined.");
+	}
 
 	return FWTS_OK;
 }