diff mbox

[3/4] dmi: dmicheck: add a helper function to check a reserved offset

Message ID 1494554782-20436-3-git-send-email-alex.hung@canonical.com
State Accepted
Headers show

Commit Message

Alex Hung May 12, 2017, 2:06 a.m. UTC
dmi_reserved_uint8_checkk is a function to check reserved
offset is zero. This patch also check reserved offset in type 13.

Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 src/dmi/dmicheck/dmicheck.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Colin Ian King May 12, 2017, 12:57 p.m. UTC | #1
On 12/05/17 03:06, Alex Hung wrote:
> dmi_reserved_uint8_checkk is a function to check reserved
> offset is zero. This patch also check reserved offset in type 13.
> 
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/dmi/dmicheck/dmicheck.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
> index 3234153..c7fb11b 100644
> --- a/src/dmi/dmicheck/dmicheck.c
> +++ b/src/dmi/dmicheck/dmicheck.c
> @@ -54,6 +54,7 @@
>  #define DMI_INVALID_HARDWARE_ENTRY	"DMIInvalidHardwareEntry"
>  #define DMI_RESERVED_VALUE_USED		"DMIReservedValueUsed"
>  #define DMI_RESERVED_BIT_USED		"DMIReservedBitUsed"
> +#define DMI_RESERVED_OFFSET_NONZERO	"DMIReservedOffsetNonZero"
>  
>  #define GET_UINT16(x) (uint16_t)(*(const uint16_t *)(x))
>  #define GET_UINT32(x) (uint32_t)(*(const uint32_t *)(x))
> @@ -842,6 +843,22 @@ static void dmi_reserved_bits_check(fwts_framework *fw,
>  	}
>  }
>  
> +static void dmi_reserved_uint8_check(fwts_framework *fw,
> +	const char *table,
> +	uint32_t addr,
> +	const char *field,
> +	const fwts_dmi_header *hdr,
> +	uint8_t offset)
> +{
> +	if (hdr->data[offset] != 0) {
> +		fwts_failed(fw, LOG_LEVEL_MEDIUM, DMI_RESERVED_OFFSET_NONZERO,
> +			"Reserved offset value is 0x%2.2" PRIx8 " (nonzero) "
> +			"while accessing entry '%s' @ 0x%8.8" PRIx32
> +			", field '%s', offset 0x%2.2" PRIx8,
> +			hdr->data[offset], table, addr, field, offset);
> +	}
> +}
> +
>  static void dmi_min_max_uint16_check(fwts_framework *fw,
>  	const char *table,
>  	uint32_t addr,
> @@ -1367,6 +1384,10 @@ static void dmicheck_entry(fwts_framework *fw,
>  			if (hdr->length < 0x6)
>  				break;
>  			dmi_reserved_bits_check(fw, table, addr, "Flags", hdr, sizeof(uint8_t), 0x5, 1, 7);
> +			if (hdr->length < 0x15)
> +				break;
> +			for (i = 0x6; i < 0x15; i++)
> +				dmi_reserved_uint8_check(fw, table, addr, "Reserved", hdr, i);
>  			if (hdr->length < 0x16)
>  				break;
>  			for (i = 1; i <= hdr->data[4]; i++) {
> 
Acked-by: Colin Ian King <colin.king@canonical.com>
Ivan Hu May 23, 2017, 7:54 a.m. UTC | #2
On 05/12/2017 10:06 AM, Alex Hung wrote:
> dmi_reserved_uint8_checkk is a function to check reserved
> offset is zero. This patch also check reserved offset in type 13.
>
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>   src/dmi/dmicheck/dmicheck.c | 21 +++++++++++++++++++++
>   1 file changed, 21 insertions(+)
>
> diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
> index 3234153..c7fb11b 100644
> --- a/src/dmi/dmicheck/dmicheck.c
> +++ b/src/dmi/dmicheck/dmicheck.c
> @@ -54,6 +54,7 @@
>   #define DMI_INVALID_HARDWARE_ENTRY	"DMIInvalidHardwareEntry"
>   #define DMI_RESERVED_VALUE_USED		"DMIReservedValueUsed"
>   #define DMI_RESERVED_BIT_USED		"DMIReservedBitUsed"
> +#define DMI_RESERVED_OFFSET_NONZERO	"DMIReservedOffsetNonZero"
>   
>   #define GET_UINT16(x) (uint16_t)(*(const uint16_t *)(x))
>   #define GET_UINT32(x) (uint32_t)(*(const uint32_t *)(x))
> @@ -842,6 +843,22 @@ static void dmi_reserved_bits_check(fwts_framework *fw,
>   	}
>   }
>   
> +static void dmi_reserved_uint8_check(fwts_framework *fw,
> +	const char *table,
> +	uint32_t addr,
> +	const char *field,
> +	const fwts_dmi_header *hdr,
> +	uint8_t offset)
> +{
> +	if (hdr->data[offset] != 0) {
> +		fwts_failed(fw, LOG_LEVEL_MEDIUM, DMI_RESERVED_OFFSET_NONZERO,
> +			"Reserved offset value is 0x%2.2" PRIx8 " (nonzero) "
> +			"while accessing entry '%s' @ 0x%8.8" PRIx32
> +			", field '%s', offset 0x%2.2" PRIx8,
> +			hdr->data[offset], table, addr, field, offset);
> +	}
> +}
> +
>   static void dmi_min_max_uint16_check(fwts_framework *fw,
>   	const char *table,
>   	uint32_t addr,
> @@ -1367,6 +1384,10 @@ static void dmicheck_entry(fwts_framework *fw,
>   			if (hdr->length < 0x6)
>   				break;
>   			dmi_reserved_bits_check(fw, table, addr, "Flags", hdr, sizeof(uint8_t), 0x5, 1, 7);
> +			if (hdr->length < 0x15)
> +				break;
> +			for (i = 0x6; i < 0x15; i++)
> +				dmi_reserved_uint8_check(fw, table, addr, "Reserved", hdr, i);
>   			if (hdr->length < 0x16)
>   				break;
>   			for (i = 1; i <= hdr->data[4]; i++) {
Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
index 3234153..c7fb11b 100644
--- a/src/dmi/dmicheck/dmicheck.c
+++ b/src/dmi/dmicheck/dmicheck.c
@@ -54,6 +54,7 @@ 
 #define DMI_INVALID_HARDWARE_ENTRY	"DMIInvalidHardwareEntry"
 #define DMI_RESERVED_VALUE_USED		"DMIReservedValueUsed"
 #define DMI_RESERVED_BIT_USED		"DMIReservedBitUsed"
+#define DMI_RESERVED_OFFSET_NONZERO	"DMIReservedOffsetNonZero"
 
 #define GET_UINT16(x) (uint16_t)(*(const uint16_t *)(x))
 #define GET_UINT32(x) (uint32_t)(*(const uint32_t *)(x))
@@ -842,6 +843,22 @@  static void dmi_reserved_bits_check(fwts_framework *fw,
 	}
 }
 
+static void dmi_reserved_uint8_check(fwts_framework *fw,
+	const char *table,
+	uint32_t addr,
+	const char *field,
+	const fwts_dmi_header *hdr,
+	uint8_t offset)
+{
+	if (hdr->data[offset] != 0) {
+		fwts_failed(fw, LOG_LEVEL_MEDIUM, DMI_RESERVED_OFFSET_NONZERO,
+			"Reserved offset value is 0x%2.2" PRIx8 " (nonzero) "
+			"while accessing entry '%s' @ 0x%8.8" PRIx32
+			", field '%s', offset 0x%2.2" PRIx8,
+			hdr->data[offset], table, addr, field, offset);
+	}
+}
+
 static void dmi_min_max_uint16_check(fwts_framework *fw,
 	const char *table,
 	uint32_t addr,
@@ -1367,6 +1384,10 @@  static void dmicheck_entry(fwts_framework *fw,
 			if (hdr->length < 0x6)
 				break;
 			dmi_reserved_bits_check(fw, table, addr, "Flags", hdr, sizeof(uint8_t), 0x5, 1, 7);
+			if (hdr->length < 0x15)
+				break;
+			for (i = 0x6; i < 0x15; i++)
+				dmi_reserved_uint8_check(fw, table, addr, "Reserved", hdr, i);
 			if (hdr->length < 0x16)
 				break;
 			for (i = 1; i <= hdr->data[4]; i++) {