ShellPkg/UefiShellBcfgCommandLib: Handle memory allocation failure
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
Main file for BCFG command.
|
Main file for BCFG command.
|
||||||
|
|
||||||
(C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
|
(C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<BR>
|
||||||
Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -553,36 +553,37 @@ BcfgAdd(
|
|||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellBcfgHiiHandle, L"bcfg", OptionStr);
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellBcfgHiiHandle, L"bcfg", OptionStr);
|
||||||
} else {
|
} else {
|
||||||
NewOrder = AllocateZeroPool((OrderCount+1)*sizeof(NewOrder[0]));
|
NewOrder = AllocateZeroPool ((OrderCount + 1) * sizeof (NewOrder[0]));
|
||||||
ASSERT(NewOrder != NULL);
|
if (NewOrder != NULL) {
|
||||||
CopyMem(NewOrder, CurrentOrder, (OrderCount)*sizeof(NewOrder[0]));
|
CopyMem (NewOrder, CurrentOrder, (OrderCount) * sizeof (NewOrder[0]));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Insert target into order list
|
// Insert target into order list
|
||||||
//
|
//
|
||||||
for (Index=OrderCount; Index > Position; Index--) {
|
for (Index = OrderCount; Index > Position; Index--) {
|
||||||
NewOrder[Index] = NewOrder[Index-1];
|
NewOrder[Index] = NewOrder[Index - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
NewOrder[Position] = (UINT16) TargetLocation;
|
NewOrder[Position] = (UINT16) TargetLocation;
|
||||||
Status = gRT->SetVariable (
|
Status = gRT->SetVariable (
|
||||||
Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder",
|
Target == BcfgTargetBootOrder ? L"BootOrder" : L"DriverOrder",
|
||||||
&gEfiGlobalVariableGuid,
|
&gEfiGlobalVariableGuid,
|
||||||
EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,
|
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
||||||
(OrderCount+1) * sizeof(UINT16),
|
(OrderCount + 1) * sizeof (UINT16),
|
||||||
NewOrder
|
NewOrder
|
||||||
);
|
);
|
||||||
|
|
||||||
FreePool(NewOrder);
|
FreePool (NewOrder);
|
||||||
|
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellBcfgHiiHandle, L"bcfg", Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder");
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellBcfgHiiHandle, L"bcfg", Target == BcfgTargetBootOrder ? L"BootOrder" : L"DriverOrder");
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
Print (L"bcfg: Add %s as %x\n", OptionStr, Position);
|
Print (L"bcfg: Add %s as %x\n", OptionStr, Position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//If always Free FilePath, will free devicepath in system when use "addh"
|
//If always Free FilePath, will free devicepath in system when use "addh"
|
||||||
|
Reference in New Issue
Block a user