[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <VI1PR0402MB3485A38A9A71500E632191AD98350@VI1PR0402MB3485.eurprd04.prod.outlook.com>
Date: Mon, 13 Jan 2020 09:41:47 +0000
From: Horia Geanta <horia.geanta@....com>
To: Andrey Smirnov <andrew.smirnov@...il.com>,
"linux-crypto@...r.kernel.org" <linux-crypto@...r.kernel.org>
CC: Chris Healy <cphealy@...il.com>,
Lucas Stach <l.stach@...gutronix.de>,
Herbert Xu <herbert@...dor.apana.org.au>,
Iuliana Prodan <iuliana.prodan@....com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
dl-linux-imx <linux-imx@....com>
Subject: Re: [PATCH v6 2/7] crypto: caam - drop global context pointer and
init_done
On 1/8/2020 5:42 PM, Andrey Smirnov wrote:
> @@ -342,18 +324,16 @@ int caam_rng_init(struct device *ctrldev)
> if (!rng_inst)
> return 0;
>
> - rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA | GFP_KERNEL);
> - if (!rng_ctx)
> + ctx = devm_kzalloc(ctrldev, sizeof(*ctx), GFP_DMA | GFP_KERNEL);
> + if (!ctx)
> return -ENOMEM;
>
> - dev_info(ctrldev, "registering rng-caam\n");
> + ctx->rng.name = "rng-caam";
> + ctx->rng.init = caam_init;
> + ctx->rng.cleanup = caam_cleanup;
> + ctx->rng.read = caam_read;
>
> - err = hwrng_register(&caam_rng);
> - if (!err) {
> - init_done = true;
> - return err;
> - }
> + dev_info(ctrldev, "registering rng-caam\n");
>
> - kfree(rng_ctx);
> - return err;
> + return devm_hwrng_register(ctrldev, &ctx->rng);
This means hwrng_unregister() is called only when ctrldev is removed.
OTOH caam_rng_init() could be called multiple times, e.g. if there's only one
jrdev left in the system and it's removed then added back.
This will lead to caam_rng_init() -> hwrng_register() called twice
with the same "rng-caam" name, without a hwrng_unregister() called in-between.
Horia
Powered by blists - more mailing lists