[PATCH v3 3/4] SecurityPkg/RngDxe: Conditionally install EFI_RNG_PROTOCOL


PierreGondois
 

From: Pierre Gondois <pierre.gondois@...>

On Arm platforms, the number of available RNG algorithms is
dynamically detected and can be 0 in the absence of FEAT_RNG
and firmware TRNG.
In this case, the EFI_RNG_PROTOCOL should not be installed to
prevent from installing an empty protocol.

Signed-off-by: Pierre Gondois <Pierre.Gondois@...>
---
.../RandomNumberGenerator/RngDxe/RngDxe.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/Security=
Pkg/RandomNumberGenerator/RngDxe/RngDxe.c
index 421abb52b8bf..d30cb7f47696 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
@@ -63,6 +63,18 @@ RngDriverEntry (
EFI_STATUS Status;
EFI_HANDLE Handle;
=20
+ //
+ // Get the list of available algorithm.
+ //
+ Status =3D GetAvailableAlgorithms ();
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (mAvailableAlgoArrayCount =3D=3D 0) {
+ return EFI_UNSUPPORTED;
+ }
+
//
// Install UEFI RNG (Random Number Generator) Protocol
//
@@ -74,13 +86,10 @@ RngDriverEntry (
NULL
);
if (EFI_ERROR (Status)) {
- return Status;
+ FreeAvailableAlgorithms ();
}
=20
- //
- // Get the list of available algorithm.
- //
- return GetAvailableAlgorithms ();
+ return Status;
}
=20
/**
--=20
2.25.1