Skip to contentSkip to conversation

ACPI: fix test for hex digit.

PATCH In review Arjun Sreedharan 4 participants 7 messages Jul 30, 2014 – Jul 31, 2014 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: fix test for hex digit.

decimal 0 is ascii for NULL. Hex digit matching should be from '0' (decimal 30 of ascii) to '9' and 'A' to 'F'.
Unfixed version returns true for #,$,%,& etc.

---
 drivers/acpi/acpi_pnp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_pnp.c +1 -1
index 4ddb0dc..a4945a5 100644
@@ -322,7 +322,7 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 
 static bool is_hex_digit(char c)
 {
-	return (c >= 0 && c <= '9') || (c >= 'A' && c <= 'F');
+	return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F');
 }
 
 static bool matching_id(char *idstr, char *list_id)
Signature · 1 line
1.8.1.msysgit.1
#1 lore raw
Quoted 3 lines · Arjun Sreedharan

decimal 0 is ascii for NULL. Hex digit matching should be from '0' (decimal 30 of ascii) to '9' and 'A' to 'F'.
Unfixed version returns true for #,$,%,& etc.

[]

drivers/acpi/acpi_pnp.c

Quoted 1 line
drivers/acpi/acpi_pnp.c +0 -0

[]

drivers/acpi/acpi_pnp.c static const struct acpi_device_id acpi_pnp_device_ids[] = { · line 326

Quoted 7 lines
drivers/acpi/acpi_pnp.c +1 -1
@@ -322,7 +322,7 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 
 static bool is_hex_digit(char c)
 {
-	return (c >= 0 && c <= '9') || (c >= 'A' && c <= 'F');
+	return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F');
 }

Maybe delete this and do s/is_hex_digit/isxdigit/ ?

#2 lore raw

PATCH 1/1 Replace faulty is_hex_digit() by isxdigit()

0 is ascii for NULL. Hex digit matching should be from '0'. Unfixed version returns true for #,$,%,& etc.

---
 drivers/acpi/acpi_pnp.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/acpi/acpi_pnp.c +1 -6
index 4ddb0dc..6d5922d 100644
@@ -320,11 +320,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{""},
 };
 
-static bool is_hex_digit(char c)
-{
-	return (c >= 0 && c <= '9') || (c >= 'A' && c <= 'F');
-}
-
 static bool matching_id(char *idstr, char *list_id)
 {
 	int i;
@@ -335,7 +330,7 @@ static bool matching_id(char *idstr, char *list_id)
 	for (i = 3; i < 7; i++) {
 		char c = toupper(idstr[i]);
 
-		if (!is_hex_digit(c)
+		if (!isxdigit(c)
 		    || (list_id[i] != 'X' && c != toupper(list_id[i])))
 			return false;
 	}
Signature · 1 line
1.7.11.7
#3 lore raw

Re: [PATCH] Replace faulty is_hex_digit() by isxdigit()

drivers/acpi/acpi_pnp.c

Quoted 12 lines · Arjun Sreedharan

0 is ascii for NULL. Hex digit matching should be from '0'. Unfixed version returns true for #,$,%,& etc.

---
 drivers/acpi/acpi_pnp.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/acpi/acpi_pnp.c +0 -0
index 4ddb0dc..6d5922d 100644

#include <linux/ctype.h>

Thanks.

Quoted 22 lines
drivers/acpi/acpi_pnp.c +1 -6
@@ -320,11 +320,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{""},
 };
 
-static bool is_hex_digit(char c)
-{
-	return (c >= 0 && c <= '9') || (c >= 'A' && c <= 'F');
-}
-
 static bool matching_id(char *idstr, char *list_id)
 {
 	int i;
@@ -335,7 +330,7 @@ static bool matching_id(char *idstr, char *list_id)
 	for (i = 3; i < 7; i++) {
 		char c = toupper(idstr[i]);
 
-		if (!is_hex_digit(c)
+		if (!isxdigit(c)
 		    || (list_id[i] != 'X' && c != toupper(list_id[i])))
 			return false;
 	}
Signature · 1 line
~Randy
#4 lore raw

PATCH 1/1 Replace faulty is_hex_digit() by isxdigit()

0 is ascii for NULL. Hex digit matching should be from '0'. Faulty version returns true for #,$,%,& etc.

---
 drivers/acpi/acpi_pnp.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/acpi/acpi_pnp.c +2 -6
index 4ddb0dc..996fa19 100644
@@ -12,6 +12,7 @@
 
 #include <linux/acpi.h>
 #include <linux/module.h>
+#include <linux/ctype.h>
 
 static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	/* soc_button_array */
@@ -320,11 +321,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{""},
 };
 
-static bool is_hex_digit(char c)
-{
-	return (c >= 0 && c <= '9') || (c >= 'A' && c <= 'F');
-}
-
 static bool matching_id(char *idstr, char *list_id)
 {
 	int i;
@@ -335,7 +331,7 @@ static bool matching_id(char *idstr, char *list_id)
 	for (i = 3; i < 7; i++) {
 		char c = toupper(idstr[i]);
 
-		if (!is_hex_digit(c)
+		if (!isxdigit(c)
 		    || (list_id[i] != 'X' && c != toupper(list_id[i])))
 			return false;
 	}
Signature · 1 line
1.7.11.7
Acked-by on v1 1/1
#5 lore raw

Re: [PATCH] Replace faulty is_hex_digit() by isxdigit()

Quoted 4 lines · Arjun Sreedharan

0 is ascii for NULL. Hex digit matching should be from '0'. Faulty version returns true for #,$,%,& etc.

Thanks.

Quoted 38 lines
---
 drivers/acpi/acpi_pnp.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/acpi/acpi_pnp.c +2 -6
index 4ddb0dc..996fa19 100644
@@ -12,6 +12,7 @@
 
 #include <linux/acpi.h>
 #include <linux/module.h>
+#include <linux/ctype.h>
 
 static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	/* soc_button_array */
@@ -320,11 +321,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{""},
 };
 
-static bool is_hex_digit(char c)
-{
-	return (c >= 0 && c <= '9') || (c >= 'A' && c <= 'F');
-}
-
 static bool matching_id(char *idstr, char *list_id)
 {
 	int i;
@@ -335,7 +331,7 @@ static bool matching_id(char *idstr, char *list_id)
 	for (i = 3; i < 7; i++) {
 		char c = toupper(idstr[i]);
 
-		if (!is_hex_digit(c)
+		if (!isxdigit(c)
 		    || (list_id[i] != 'X' && c != toupper(list_id[i])))
 			return false;
 	}
Signature · 1 line
~Randy
#6 lore raw

Re: [PATCH] Replace faulty is_hex_digit() by isxdigit()

Quoted 7 lines · Randy Dunlap
Quoted 4 lines · Arjun Sreedharan

0 is ascii for NULL. Hex digit matching should be from '0'. Faulty version returns true for #,$,%,& etc.

Applied, thanks!

Quoted 43 lines

Thanks.

Quoted 38 lines
---
 drivers/acpi/acpi_pnp.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/acpi/acpi_pnp.c +2 -6
index 4ddb0dc..996fa19 100644
@@ -12,6 +12,7 @@
 
 #include <linux/acpi.h>
 #include <linux/module.h>
+#include <linux/ctype.h>
 
 static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	/* soc_button_array */
@@ -320,11 +321,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{""},
 };
 
-static bool is_hex_digit(char c)
-{
-	return (c >= 0 && c <= '9') || (c >= 'A' && c <= 'F');
-}
-
 static bool matching_id(char *idstr, char *list_id)
 {
 	int i;
@@ -335,7 +331,7 @@ static bool matching_id(char *idstr, char *list_id)
 	for (i = 3; i < 7; i++) {
 		char c = toupper(idstr[i]);
 
-		if (!is_hex_digit(c)
+		if (!isxdigit(c)
 		    || (list_id[i] != 'X' && c != toupper(list_id[i])))
 			return false;
 	}
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.