]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
MdeModulePkg: Unify the definitions of size_t
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmHotkey.c
index b49758b236a2bf136652a37eeb4be4c970c088f4..c2d1447f59289fa20b0a669e0a73088c2b53987c 100644 (file)
@@ -1,14 +1,9 @@
 /** @file\r
   Hotkey library functions.\r
 \r
-Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -41,7 +36,7 @@ VOID                         *mBmTxtInExRegistration  = NULL;
 **/\r
 UINTN\r
 BmSizeOfKeyOption (\r
-  EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption\r
+  IN CONST EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption\r
   )\r
 {\r
   return OFFSET_OF (EFI_BOOT_MANAGER_KEY_OPTION, Keys)\r
@@ -60,8 +55,8 @@ BmSizeOfKeyOption (
 **/\r
 BOOLEAN\r
 BmIsKeyOptionValid (\r
-  IN EFI_BOOT_MANAGER_KEY_OPTION     *KeyOption,\r
-  IN UINTN                           KeyOptionSize\r
+  IN CONST EFI_BOOT_MANAGER_KEY_OPTION *KeyOption,\r
+  IN       UINTN                       KeyOptionSize\r
 )\r
 {\r
   UINT16   OptionName[BM_OPTION_NAME_LEN];\r
@@ -115,7 +110,7 @@ BmIsKeyOptionVariable (
 {\r
   UINTN         Index;\r
   UINTN         Uint;\r
-  \r
+\r
   if (!CompareGuid (Guid, &gEfiGlobalVariableGuid) ||\r
       (StrSize (Name) != sizeof (L"Key####")) ||\r
       (StrnCmp (Name, L"Key", 3) != 0)\r
@@ -157,16 +152,15 @@ BmCollectKeyOptions (
 {\r
   UINTN                        Index;\r
   BM_COLLECT_KEY_OPTIONS_PARAM *Param;\r
-  EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption;\r
+  VOID                         *KeyOption;\r
   UINT16                       OptionNumber;\r
   UINTN                        KeyOptionSize;\r
 \r
   Param = (BM_COLLECT_KEY_OPTIONS_PARAM *) Context;\r
 \r
   if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) {\r
-    GetEfiGlobalVariable2 (Name, (VOID**) &KeyOption, &KeyOptionSize);\r
+    GetEfiGlobalVariable2 (Name, &KeyOption, &KeyOptionSize);\r
     ASSERT (KeyOption != NULL);\r
-    KeyOption->OptionNumber = OptionNumber;\r
     if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) {\r
       Param->KeyOptions = ReallocatePool (\r
                             Param->KeyOptionCount * sizeof (EFI_BOOT_MANAGER_KEY_OPTION),\r
@@ -178,12 +172,13 @@ BmCollectKeyOptions (
       // Insert the key option in order\r
       //\r
       for (Index = 0; Index < Param->KeyOptionCount; Index++) {\r
-        if (KeyOption->OptionNumber < Param->KeyOptions[Index].OptionNumber) {\r
+        if (OptionNumber < Param->KeyOptions[Index].OptionNumber) {\r
           break;\r
         }\r
       }\r
       CopyMem (&Param->KeyOptions[Index + 1], &Param->KeyOptions[Index], (Param->KeyOptionCount - Index) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION));\r
-      CopyMem (&Param->KeyOptions[Index], KeyOption, BmSizeOfKeyOption (KeyOption));\r
+      CopyMem (&Param->KeyOptions[Index], KeyOption, KeyOptionSize);\r
+      Param->KeyOptions[Index].OptionNumber = OptionNumber;\r
       Param->KeyOptionCount++;\r
     }\r
     FreePool (KeyOption);\r
@@ -219,21 +214,6 @@ BmGetKeyOptions (
   return Param.KeyOptions;\r
 }\r
 \r
-/**\r
-  Callback function for event.\r
-  \r
-  @param    Event          Event for this callback function.\r
-  @param    Context        Context pass to this function.\r
-**/\r
-VOID\r
-EFIAPI\r
-BmEmptyFunction (\r
-  IN EFI_EVENT                Event,\r
-  IN VOID                     *Context\r
-  )\r
-{\r
-}\r
-\r
 /**\r
   Check whether the bit is set in the value.\r
 \r
@@ -389,7 +369,7 @@ BmHotkeyCallback (
     HotkeyData = &Hotkey->KeyData[Hotkey->WaitingKey];\r
     if ((KeyData->Key.ScanCode == HotkeyData->Key.ScanCode) &&\r
         (KeyData->Key.UnicodeChar == HotkeyData->Key.UnicodeChar) &&\r
-        (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) ? \r
+        (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) ?\r
           (KeyData->KeyState.KeyShiftState == HotkeyData->KeyState.KeyShiftState) : TRUE\r
         )\r
        ) {\r
@@ -471,8 +451,10 @@ BmGetActiveConsoleIn (
                     EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
                     );\r
     if (!EFI_ERROR (Status)) {\r
-      Handles = AllocateCopyPool (sizeof (EFI_HANDLE *), &gST->ConsoleInHandle);\r
-      *Count  = 1;\r
+      Handles = AllocateCopyPool (sizeof (EFI_HANDLE), &gST->ConsoleInHandle);\r
+      if (Handles != NULL) {\r
+        *Count = 1;\r
+      }\r
     }\r
   } else {\r
     Status = gBS->LocateHandleBuffer (\r
@@ -677,7 +659,7 @@ BmProcessKeyOption (
 \r
   KeyShiftStateCount = 0;\r
   BmGenerateKeyShiftState (0, KeyOption, EFI_SHIFT_STATE_VALID, KeyShiftStates, &KeyShiftStateCount);\r
-  ASSERT (KeyShiftStateCount <= sizeof (KeyShiftStates) / sizeof (KeyShiftStates[0]));\r
+  ASSERT (KeyShiftStateCount <= ARRAY_SIZE (KeyShiftStates));\r
 \r
   EfiAcquireLock (&mBmHotkeyLock);\r
 \r
@@ -811,7 +793,7 @@ EfiBootManagerRegisterContinueKeyOption (
   EFI_STATUS                   Status;\r
   EFI_BOOT_MANAGER_KEY_OPTION  KeyOption;\r
   VA_LIST                      Args;\r
-  \r
+\r
   if (mBmContinueKeyOption != NULL) {\r
     return EFI_ALREADY_STARTED;\r
   }\r
@@ -834,7 +816,7 @@ EfiBootManagerRegisterContinueKeyOption (
 \r
 /**\r
   Stop the hotkey processing.\r
-  \r
+\r
   @param    Event          Event pointer related to hotkey service.\r
   @param    Context        Context pass to this function.\r
 **/\r
@@ -864,7 +846,7 @@ BmStopHotkeyService (
 /**\r
   Start the hot key service so that the key press can trigger the boot option.\r
 \r
-  @param HotkeyTriggered  Return the waitable event and it will be signaled \r
+  @param HotkeyTriggered  Return the waitable event and it will be signaled\r
                           when a valid hot key is pressed.\r
 \r
   @retval EFI_SUCCESS     The hot key service is started.\r
@@ -882,13 +864,13 @@ EfiBootManagerStartHotkeyService (
   EFI_EVENT                    Event;\r
   UINT32                       *BootOptionSupport;\r
 \r
-  Status = GetEfiGlobalVariable2 (EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME, (VOID **) &BootOptionSupport, NULL);\r
-  ASSERT (BootOptionSupport != NULL);\r
-\r
-  if ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_KEY)  != 0) {\r
-    mBmHotkeySupportCount = ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_COUNT) >> LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT));\r
+  GetEfiGlobalVariable2 (EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME, (VOID **) &BootOptionSupport, NULL);\r
+  if (BootOptionSupport != NULL) {\r
+    if ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_KEY)  != 0) {\r
+      mBmHotkeySupportCount = ((*BootOptionSupport & EFI_BOOT_OPTION_SUPPORT_COUNT) >> LowBitSet32 (EFI_BOOT_OPTION_SUPPORT_COUNT));\r
+    }\r
+    FreePool (BootOptionSupport);\r
   }\r
-  FreePool (BootOptionSupport);\r
 \r
   if (mBmHotkeySupportCount == 0) {\r
     DEBUG ((EFI_D_INFO, "Bds: BootOptionSupport NV variable forbids starting the hotkey service.\n"));\r
@@ -898,7 +880,7 @@ EfiBootManagerStartHotkeyService (
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
                   TPL_CALLBACK,\r
-                  BmEmptyFunction,\r
+                  EfiEventEmptyFunction,\r
                   NULL,\r
                   &mBmHotkeyTriggered\r
                   );\r