Re: [PATCH 1/2] crypto: hisilicon/trng - use DEFINE_MUTEX() and LIST_HEAD()
From: Herbert Xu
Date: Thu Dec 18 2025 - 22:04:57 EST
On Thu, Nov 20, 2025 at 09:58:11PM +0800, Chenghai Huang wrote:
>
> @@ -308,12 +302,10 @@ static void hisi_trng_remove(struct platform_device *pdev)
> struct hisi_trng *trng = platform_get_drvdata(pdev);
>
> /* Wait until the task is finished */
> - while (hisi_trng_del_from_list(trng))
> - ;
> -
> - if (trng->ver != HISI_TRNG_VER_V1 &&
> - atomic_dec_return(&trng_active_devs) == 0)
> - crypto_unregister_rng(&hisi_trng_alg);
> + while (hisi_trng_crypto_unregister(trng)) {
> + dev_info(&pdev->dev, "trng is in using!\n");
> + msleep(WAIT_PERIOD);
> + }
Please use the new CRYPTO_ALG_DUP_FIRST flag to let the Crypto API
deal with reference count tracking. With that, you should be able
to unregister the RNG even if there are still tfms using it.
The RNG will be freed after all tfms using it are freed.
Of course you should create a way to mark the trng as dead so
that the hisi_trng_generate returns an error instead of trying
to read from the non-existant RNG.
Cheers,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt