From: Nicolai Stange Date: Mon, 15 Nov 2021 14:18:08 +0000 (+0100) Subject: crypto: drbg - make drbg_prepare_hrng() handle jent instantiation errors X-Git-Tag: baikal/aarch64/sdk5.10~345 X-Git-Url: https://git.baikalelectronics.ru/?a=commitdiff_plain;h=b3b4d6b7abe83be2f6d609942703e6a92afd5286;p=kernel.git crypto: drbg - make drbg_prepare_hrng() handle jent instantiation errors [ Upstream commit e9c170444078969c6b74933c1e35aacef739224b ] Now that drbg_prepare_hrng() doesn't do anything but to instantiate a jitterentropy crypto_rng instance, it looks a little odd to have the related error handling at its only caller, drbg_instantiate(). Move the handling of jitterentropy allocation failures from drbg_instantiate() close to the allocation itself in drbg_prepare_hrng(). There is no change in behaviour. Signed-off-by: Nicolai Stange Reviewed-by: Stephan Müller Signed-off-by: Herbert Xu Stable-dep-of: 686cd976b6dd ("crypto: drbg - Only fail when jent is unavailable in FIPS mode") Signed-off-by: Sasha Levin --- diff --git a/crypto/drbg.c b/crypto/drbg.c index 9329d9dcc210f..732b72e4ee4dd 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1515,6 +1515,14 @@ static int drbg_prepare_hrng(struct drbg_state *drbg) return 0; drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0); + if (IS_ERR(drbg->jent)) { + const int err = PTR_ERR(drbg->jent); + + drbg->jent = NULL; + if (fips_enabled || err != -ENOENT) + return err; + pr_info("DRBG: Continuing without Jitter RNG\n"); + } return 0; } @@ -1570,14 +1578,6 @@ static int drbg_instantiate(struct drbg_state *drbg, struct drbg_string *pers, if (ret) goto free_everything; - if (IS_ERR(drbg->jent)) { - ret = PTR_ERR(drbg->jent); - drbg->jent = NULL; - if (fips_enabled || ret != -ENOENT) - goto free_everything; - pr_info("DRBG: Continuing without Jitter RNG\n"); - } - reseed = false; }