Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ VariableNotifySmmReady (
VOID
);

/**
Revert the variable ready notification.
This function will be called when an error happens in variable initializing process.
**/
VOID
VariableClearNotifySmmReady (
VOID
);

/**
Notify the system that the SMM variable write driver is ready.
**/
Expand All @@ -114,7 +123,12 @@ VariableNotifySmmWriteReady (
for variable read and write services being available. It also registers
a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.

@retval EFI_SUCCESS Variable service successfully initialized.
@retval EFI_SUCCESS Variable service successfully initialized.
@retval EFI_OUT_OF_RESOURCES Insufficient memory to allocate variable
storage or communication buffers.
@retval EFI_VOLUME_CORRUPTED The non-volatile variable store is corrupted.
@retval Others An error from protocol installation, SMI handler
registration, or protocol notification registration.
**/
EFI_STATUS
EFIAPI
Expand Down
59 changes: 44 additions & 15 deletions MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -3843,6 +3843,9 @@ GetHobVariableStore (
/**
Initializes variable store area for non-volatile and volatile variable.

On any failure, the caller must invoke VariableCommonUninitialize() to
release resources that may have been partially allocated.

@retval EFI_SUCCESS Function successfully executed.
@retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.

Expand Down Expand Up @@ -3872,7 +3875,6 @@ VariableCommonInitialize (
//
Status = InitNonVolatileVariableStore ();
if (EFI_ERROR (Status)) {
FreePool (mVariableModuleGlobal);
return Status;
}

Expand All @@ -3898,11 +3900,6 @@ VariableCommonInitialize (
//
Status = GetHobVariableStore (VariableGuid);
if (EFI_ERROR (Status)) {
if (mNvFvHeaderCache != NULL) {
FreePool (mNvFvHeaderCache);
}

FreePool (mVariableModuleGlobal);
return Status;
}

Expand All @@ -3917,15 +3914,6 @@ VariableCommonInitialize (
mVariableModuleGlobal->ScratchBufferSize = ScratchSize;
VolatileVariableStore = AllocateRuntimePool (PcdGet32 (PcdVariableStoreSize) + ScratchSize);
if (VolatileVariableStore == NULL) {
if (mVariableModuleGlobal->VariableGlobal.HobVariableBase != 0) {
FreePool ((VOID *)(UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase);
}

if (mNvFvHeaderCache != NULL) {
FreePool (mNvFvHeaderCache);
}

FreePool (mVariableModuleGlobal);
return EFI_OUT_OF_RESOURCES;
}

Expand All @@ -3947,6 +3935,47 @@ VariableCommonInitialize (
return EFI_SUCCESS;
}

/**
Uninitialize variable store area, freeing all resources allocated by
VariableCommonInitialize().

**/
VOID
VariableCommonUninitialize (
VOID
)
{
if (mVariableModuleGlobal != NULL) {
if (mVariableModuleGlobal->VariableGlobal.HobVariableBase != 0) {
FreePool ((VOID *)(UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase);
mVariableModuleGlobal->VariableGlobal.HobVariableBase = 0;
}

if (mVariableModuleGlobal->VariableGlobal.VolatileVariableBase != 0) {
FreePool ((VOID *)(UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase);
}

FreePool (mVariableModuleGlobal);
mVariableModuleGlobal = NULL;
}

if (mNvFvHeaderCache != NULL) {
//
// In real NV mode, mNvVariableCache points into the same allocation as mNvFvHeaderCache.
//
ASSERT ((UINTN)mNvVariableCache == (UINTN)mNvFvHeaderCache + mNvFvHeaderCache->HeaderLength);
FreePool (mNvFvHeaderCache);
mNvFvHeaderCache = NULL;
mNvVariableCache = NULL;
} else if ((mNvVariableCache != NULL) && (PcdGet64 (PcdEmuVariableNvStoreReserved) == 0)) {
//
// In emulated NV mode without a pre-reserved store, mNvVariableCache is a dynamic allocation.
//
FreePool (mNvVariableCache);
mNvVariableCache = NULL;
}
}

/**
Get the proper fvb handle and/or fvb protocol by the given Flash address.

Expand Down
10 changes: 10 additions & 0 deletions MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ VariableCommonInitialize (
VOID
);

/**
Uninitialize variable store area, freeing all resources allocated by
VariableCommonInitialize().

**/
VOID
VariableCommonUninitialize (
VOID
);

/**
This function reclaims variable storage if free size is below the threshold.

Expand Down
Loading
Loading