From f3fe0dce04cbc5ddfe36cdc05e4dbec4814f8d8a Mon Sep 17 00:00:00 2001 From: David Leach Date: Wed, 11 Aug 2021 17:51:18 -0500 Subject: [PATCH] drivers: entropy: mcux_trng: fix error after reset There are situations after certain types of resets of the board, that the underlying TRNG IP reports an error when making a request for TRNG_GetRandomData(). The function will clear the error bit but doesn't try to retrieve the entropy data so this change will retry once on the error. The observation is that the error only occurs once and since this function is likely only called a couple of times to provide a seed to RNG functions there is little impact. fixes: #37619 Signed-off-by: David Leach --- drivers/entropy/entropy_mcux_trng.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/entropy/entropy_mcux_trng.c b/drivers/entropy/entropy_mcux_trng.c index d3cfb2d663ffc..67c5b2af0f514 100644 --- a/drivers/entropy/entropy_mcux_trng.c +++ b/drivers/entropy/entropy_mcux_trng.c @@ -27,6 +27,16 @@ static int entropy_mcux_trng_get_entropy(const struct device *dev, ARG_UNUSED(dev); status = TRNG_GetRandomData(config->base, buffer, length); + if (unlikely(status)) { + /* + * There can be a situation after certain types of resets + * where the underlying TRNG IP reports an error. The + * TRNG_GetRandomData() function will clear the error but + * doesn't try to retrieve random data so make the request + * again. + */ + status = TRNG_GetRandomData(config->base, buffer, length); + } __ASSERT_NO_MSG(!status); return 0;