Patchwork dmi: dmi_decode: remove some redundant range changes on uint8_t values

login
register
mail settings
Submitter Colin King
Date Oct. 25, 2012, 1 p.m.
Message ID <1351170007-17456-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/194147/
State Accepted
Headers show

Comments

Colin King - Oct. 25, 2012, 1 p.m.
From: Colin Ian King <colin.king@canonical.com>

-Wextra shows that we are doing some redundant range checks on uint8_t
values, so just remove them to clean up the code.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/dmi/dmi_decode/dmi_decode.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Alex Hung - Oct. 29, 2012, 6:30 a.m.
On 10/25/2012 09:00 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> -Wextra shows that we are doing some redundant range checks on uint8_t
> values, so just remove them to clean up the code.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/dmi/dmi_decode/dmi_decode.c |    8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/src/dmi/dmi_decode/dmi_decode.c b/src/dmi/dmi_decode/dmi_decode.c
> index aa1ce15..183be3c 100644
> --- a/src/dmi/dmi_decode/dmi_decode.c
> +++ b/src/dmi/dmi_decode/dmi_decode.c
> @@ -773,8 +773,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   			if (hdr->length < 0x14)
>   				break;
>   			val = hdr->data[0x0a];
> -			if (!(((val >= 0x00) && (val <= 0x04)) ||
> -			      ((val >= 0x80) && (val <= 0xff)))) {
> +			if (!((val <= 0x04) || (val >= 0x80))) {
>   				fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
>   					"Out of range value 0x%2.2" PRIx8 " "
>   					"(range allowed 0x00..0x01, "
> @@ -785,8 +784,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   			if (hdr->length < 0x17)
>   				break;
>   			val = hdr->data[0x14];
> -			if (!(((val >= 0x00) && (val <= 0x01)) ||
> -			      ((val >= 0x80) && (val <= 0xff)))) {
> +			if (!((val <= 0x01) || (val >= 0x80))) {
>   				fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
>   					"Out of range value 0x%2.2" PRIx8 " "
>   					"(range allowed 0x00..0x01, "
> @@ -804,7 +802,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   					val = ptr[j];
>   					if (!(((val >= 0x01) && (val <= 0x0e)) ||
>   					      ((val >= 0x10) && (val <= 0x17)) ||
> -					      ((val >= 0x80) && (val <= 0xff)))) {
> +					      (val >= 0x80))) {
>   						fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
>   							"Out of range value 0x%2.2" PRIx8 " "
>   							"(range allowed 0x01..0x0e, 0x10..0x17, "
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - Oct. 31, 2012, 11:20 a.m.
On 10/25/2012 09:00 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> -Wextra shows that we are doing some redundant range checks on uint8_t
> values, so just remove them to clean up the code.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/dmi/dmi_decode/dmi_decode.c |    8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/src/dmi/dmi_decode/dmi_decode.c b/src/dmi/dmi_decode/dmi_decode.c
> index aa1ce15..183be3c 100644
> --- a/src/dmi/dmi_decode/dmi_decode.c
> +++ b/src/dmi/dmi_decode/dmi_decode.c
> @@ -773,8 +773,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   			if (hdr->length < 0x14)
>   				break;
>   			val = hdr->data[0x0a];
> -			if (!(((val >= 0x00) && (val <= 0x04)) ||
> -			      ((val >= 0x80) && (val <= 0xff)))) {
> +			if (!((val <= 0x04) || (val >= 0x80))) {
>   				fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
>   					"Out of range value 0x%2.2" PRIx8 " "
>   					"(range allowed 0x00..0x01, "
> @@ -785,8 +784,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   			if (hdr->length < 0x17)
>   				break;
>   			val = hdr->data[0x14];
> -			if (!(((val >= 0x00) && (val <= 0x01)) ||
> -			      ((val >= 0x80) && (val <= 0xff)))) {
> +			if (!((val <= 0x01) || (val >= 0x80))) {
>   				fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
>   					"Out of range value 0x%2.2" PRIx8 " "
>   					"(range allowed 0x00..0x01, "
> @@ -804,7 +802,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   					val = ptr[j];
>   					if (!(((val >= 0x01) && (val <= 0x0e)) ||
>   					      ((val >= 0x10) && (val <= 0x17)) ||
> -					      ((val >= 0x80) && (val <= 0xff)))) {
> +					      (val >= 0x80))) {
>   						fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
>   							"Out of range value 0x%2.2" PRIx8 " "
>   							"(range allowed 0x01..0x0e, 0x10..0x17, "
>


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

Patch

diff --git a/src/dmi/dmi_decode/dmi_decode.c b/src/dmi/dmi_decode/dmi_decode.c
index aa1ce15..183be3c 100644
--- a/src/dmi/dmi_decode/dmi_decode.c
+++ b/src/dmi/dmi_decode/dmi_decode.c
@@ -773,8 +773,7 @@  static void dmi_decode_entry(fwts_framework *fw,
 			if (hdr->length < 0x14)
 				break;
 			val = hdr->data[0x0a];
-			if (!(((val >= 0x00) && (val <= 0x04)) ||
-			      ((val >= 0x80) && (val <= 0xff)))) {
+			if (!((val <= 0x04) || (val >= 0x80))) {
 				fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
 					"Out of range value 0x%2.2" PRIx8 " "
 					"(range allowed 0x00..0x01, "
@@ -785,8 +784,7 @@  static void dmi_decode_entry(fwts_framework *fw,
 			if (hdr->length < 0x17)
 				break;
 			val = hdr->data[0x14];
-			if (!(((val >= 0x00) && (val <= 0x01)) ||
-			      ((val >= 0x80) && (val <= 0xff)))) {
+			if (!((val <= 0x01) || (val >= 0x80))) {
 				fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
 					"Out of range value 0x%2.2" PRIx8 " "
 					"(range allowed 0x00..0x01, "
@@ -804,7 +802,7 @@  static void dmi_decode_entry(fwts_framework *fw,
 					val = ptr[j];
 					if (!(((val >= 0x01) && (val <= 0x0e)) ||
 					      ((val >= 0x10) && (val <= 0x17)) ||
-					      ((val >= 0x80) && (val <= 0xff)))) {
+					      (val >= 0x80))) {
 						fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
 							"Out of range value 0x%2.2" PRIx8 " "
 							"(range allowed 0x01..0x0e, 0x10..0x17, "