Merge branch 'x86-apic-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / drivers / acpi / acpica / uthex.c
index 8ad086e..36d2fc7 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2015, Intel Corp.
+ * Copyright (C) 2000 - 2016, Intel Corp.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -73,11 +73,43 @@ char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
        return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
 }
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ut_ascii_to_hex_byte
+ *
+ * PARAMETERS:  two_ascii_chars             - Pointer to two ASCII characters
+ *              return_byte                 - Where converted byte is returned
+ *
+ * RETURN:      Status and converted hex byte
+ *
+ * DESCRIPTION: Perform ascii-to-hex translation, exactly two ASCII characters
+ *              to a single converted byte value.
+ *
+ ******************************************************************************/
+
+acpi_status acpi_ut_ascii_to_hex_byte(char *two_ascii_chars, u8 *return_byte)
+{
+
+       /* Both ASCII characters must be valid hex digits */
+
+       if (!isxdigit((int)two_ascii_chars[0]) ||
+           !isxdigit((int)two_ascii_chars[1])) {
+               return (AE_BAD_HEX_CONSTANT);
+       }
+
+       *return_byte =
+           acpi_ut_ascii_char_to_hex(two_ascii_chars[1]) |
+           (acpi_ut_ascii_char_to_hex(two_ascii_chars[0]) << 4);
+
+       return (AE_OK);
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ut_ascii_char_to_hex
  *
- * PARAMETERS:  hex_char                - Hex character in Ascii
+ * PARAMETERS:  hex_char                - Hex character in Ascii. Must be:
+ *                                        0-9 or A-F or a-f
  *
  * RETURN:      The binary value of the ascii/hex character
  *
@@ -88,13 +120,19 @@ char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
 u8 acpi_ut_ascii_char_to_hex(int hex_char)
 {
 
-       if (hex_char <= 0x39) {
-               return ((u8)(hex_char - 0x30));
+       /* Values 0-9 */
+
+       if (hex_char <= '9') {
+               return ((u8)(hex_char - '0'));
        }
 
-       if (hex_char <= 0x46) {
+       /* Upper case A-F */
+
+       if (hex_char <= 'F') {
                return ((u8)(hex_char - 0x37));
        }
 
+       /* Lower case a-f */
+
        return ((u8)(hex_char - 0x57));
 }