[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <49971beb-0681-de92-95f5-b18e1be05ce3@nxp.com>
Date: Tue, 17 Mar 2020 18:45:29 +0200
From: Horia Geantă <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 v8 3/8] crypto: caam - drop global context pointer and
init_done
On 3/16/2020 5:01 PM, Andrey Smirnov wrote:
> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
> index 69a02ac5de54..753625f2b2c0 100644
> --- a/drivers/crypto/caam/caamrng.c
> +++ b/drivers/crypto/caam/caamrng.c
> @@ -70,6 +70,7 @@ struct buf_data {
>
> /* rng per-device context */
> struct caam_rng_ctx {
> + struct hwrng rng;
> struct device *jrdev;
> dma_addr_t sh_desc_dma;
> u32 sh_desc[DESC_RNG_LEN];
> @@ -78,13 +79,10 @@ struct caam_rng_ctx {
> struct buf_data bufs[2];
> };
[...]
> +static struct caam_rng_ctx *to_caam_rng_ctx(struct hwrng *r)
> +{
> + return (struct caam_rng_ctx *)r->priv;
> +}
[...]
> -static struct hwrng caam_rng = {
> - .name = "rng-caam",
> - .init = caam_init,
> - .cleanup = caam_cleanup,
> - .read = caam_read,
> -};
I would keep this statically allocated, see below.
> @@ -342,18 +332,27 @@ 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)
> + if (!devres_open_group(ctrldev, caam_rng_init, GFP_KERNEL))
> + return -ENOMEM;
> +
> + ctx = devm_kzalloc(ctrldev, sizeof(*ctx), GFP_DMA | GFP_KERNEL);
> + if (!ctx)
> return -ENOMEM;
>
> + ctx->rng.name = "rng-caam";
> + ctx->rng.init = caam_init;
> + ctx->rng.cleanup = caam_cleanup;
> + ctx->rng.read = caam_read;
> + ctx->rng.priv = (unsigned long)ctx;
> +
> dev_info(ctrldev, "registering rng-caam\n");
>
> - err = hwrng_register(&caam_rng);
> - if (!err) {
> - init_done = true;
> - return err;
> + ret = devm_hwrng_register(ctrldev, &ctx->rng);
Now that hwrng.priv is used to keep driver's private data / caam_rng_ctx,
and thus container_of() is no longer needed to get from hwrng struct
to caam_rng_ctx, it's no longer needed to embed struct hwrng
into caam_rng_ctx.
Horia
Powered by blists - more mailing lists