linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Horia Geantă" <horia.geanta@nxp.com>
To: Andrey Smirnov <andrew.smirnov@gmail.com>,
	"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>
Cc: Chris Healy <cphealy@gmail.com>,
	Lucas Stach <l.stach@pengutronix.de>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Iuliana Prodan <iuliana.prodan@nxp.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	dl-linux-imx <linux-imx@nxp.com>
Subject: Re: [PATCH v8 3/8] crypto: caam - drop global context pointer and init_done
Date: Tue, 17 Mar 2020 18:45:29 +0200	[thread overview]
Message-ID: <49971beb-0681-de92-95f5-b18e1be05ce3@nxp.com> (raw)
In-Reply-To: <20200316150047.30828-4-andrew.smirnov@gmail.com>

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

  reply	other threads:[~2020-03-17 16:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-16 15:00 [PATCH v8 0/8] enable CAAM's HWRNG as default Andrey Smirnov
2020-03-16 15:00 ` [PATCH v8 1/8] crypto: caam - allocate RNG instantiation descriptor with GFP_DMA Andrey Smirnov
2020-03-17 15:22   ` Horia Geantă
2020-03-16 15:00 ` [PATCH v8 2/8] crypto: caam - use struct hwrng's .init for initialization Andrey Smirnov
2020-03-16 15:00 ` [PATCH v8 3/8] crypto: caam - drop global context pointer and init_done Andrey Smirnov
2020-03-17 16:45   ` Horia Geantă [this message]
2020-03-19 13:00     ` Andrey Smirnov
2020-03-16 15:00 ` [PATCH v8 4/8] crypto: caam - simplify RNG implementation Andrey Smirnov
2020-03-17 21:37   ` Horia Geantă
2020-03-17 21:58   ` Horia Geantă
2020-03-19 13:07     ` Andrey Smirnov
2020-03-16 15:00 ` [PATCH v8 5/8] crypto: caam - check if RNG job failed Andrey Smirnov
2020-03-17 17:09   ` Horia Geantă
2020-03-16 15:00 ` [PATCH v8 6/8] crypto: caam - invalidate entropy register during RNG initialization Andrey Smirnov
2020-03-16 15:00 ` [PATCH v8 7/8] crypto: caam - enable prediction resistance in HRWNG Andrey Smirnov
2020-03-17 17:41   ` Horia Geantă
2020-03-17 17:59   ` Horia Geantă
2020-03-16 15:00 ` [PATCH v8 8/8] crypto: caam - limit single JD RNG output to maximum of 16 bytes Andrey Smirnov
2020-03-17 21:56   ` Horia Geantă
2020-03-17 11:16 ` [PATCH v8 0/8] enable CAAM's HWRNG as default Horia Geantă

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49971beb-0681-de92-95f5-b18e1be05ce3@nxp.com \
    --to=horia.geanta@nxp.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=cphealy@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=iuliana.prodan@nxp.com \
    --cc=l.stach@pengutronix.de \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH v8 3/8] crypto: caam - drop global context pointer and init_done' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).