Revision: 18855
          http://sourceforge.net/p/edk2/code/18855
Author:   niruiyu
Date:     2015-11-17 10:08:40 +0000 (Tue, 17 Nov 2015)
Log Message:
-----------
MdeModulePkg: Use BmCharToUint in BmIsKeyOptionVariable

The patch also moves the BmCharToUint to BmMisc.c because it
belongs to misc functions.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <[email protected]>
Reviewed-by: Sunny Wang <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
    trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
    trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
    trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h

Modified: trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
===================================================================
--- trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c       
2015-11-17 10:07:43 UTC (rev 18854)
+++ trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c       
2015-11-17 10:08:40 UTC (rev 18855)
@@ -88,6 +88,7 @@
   )
 {
   UINTN         Index;
+  UINTN         Uint;
   
   if (!CompareGuid (Guid, &gEfiGlobalVariableGuid) ||
       (StrSize (Name) != sizeof (L"Key####")) ||
@@ -98,12 +99,11 @@
 
   *OptionNumber = 0;
   for (Index = 3; Index < 7; Index++) {
-    if ((Name[Index] >= L'0') && (Name[Index] <= L'9')) {
-      *OptionNumber = *OptionNumber * 16 + Name[Index] - L'0';
-    } else if ((Name[Index] >= L'A') && (Name[Index] <= L'F')) {
-      *OptionNumber = *OptionNumber * 16 + Name[Index] - L'A' + 10;
+    Uint = BmCharToUint (Name[Index]);
+    if (Uint == -1) {
+      return FALSE;
     } else {
-      return FALSE;
+      *OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;
     }
   }
 

Modified: trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
===================================================================
--- trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c   
2015-11-17 10:07:43 UTC (rev 18854)
+++ trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c   
2015-11-17 10:08:40 UTC (rev 18855)
@@ -587,29 +587,6 @@
 }
 
 /**
-  Convert a single character to number.
-  It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
-
-  @param    Char   The input char which need to convert to int.
-**/
-UINTN
-BmCharToUint (
-  IN CHAR16                           Char
-  )
-{
-  if ((Char >= L'0') && (Char <= L'9')) {
-    return (UINTN) (Char - L'0');
-  }
-
-  if ((Char >= L'A') && (Char <= L'F')) {
-    return (UINTN) (Char - L'A' + 0xA);
-  }
-
-  ASSERT (FALSE);
-  return (UINTN) -1;
-}
-
-/**
   Returns the size of a device path in bytes.
 
   This function returns the size, in bytes, of the device path data structure 

Modified: trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
===================================================================
--- trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c 2015-11-17 
10:07:43 UTC (rev 18854)
+++ trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c 2015-11-17 
10:08:40 UTC (rev 18855)
@@ -384,3 +384,29 @@
     FreePool (Str);
   }
 }
+
+/**
+  Convert a single character to number.
+  It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
+
+  @param    Char   The input char which need to convert to int.
+
+  @return  The converted 8-bit number or (UINTN) -1 if conversion failed.
+**/
+UINTN
+BmCharToUint (
+  IN CHAR16                           Char
+  )
+{
+  if ((Char >= L'0') && (Char <= L'9')) {
+    return (UINTN) (Char - L'0');
+  }
+
+  if ((Char >= L'A') && (Char <= L'F')) {
+    return (UINTN) (Char - L'A' + 0xA);
+  }
+
+  ASSERT (FALSE);
+  return (UINTN) -1;
+}
+

Modified: trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h
===================================================================
--- trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h     
2015-11-17 10:07:43 UTC (rev 18854)
+++ trunk/edk2/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h     
2015-11-17 10:08:40 UTC (rev 18855)
@@ -434,4 +434,17 @@
   EFI_DEVICE_PATH_PROTOCOL            *DevicePath
   );
 
+/**
+  Convert a single character to number.
+  It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
+
+  @param    Char   The input char which need to convert to int.
+
+  @return  The converted 8-bit number or (UINTN) -1 if conversion failed.
+**/
+UINTN
+BmCharToUint (
+  IN CHAR16                           Char
+  );
+
 #endif // _INTERNAL_BM_H_


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to