linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: "Horia Geantă" <horia.geanta@nxp.com>
Cc: "linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	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: Thu, 19 Mar 2020 06:00:10 -0700	[thread overview]
Message-ID: <CAHQ1cqGcR=u8QPeD7PQtsZYEQL=5VQWv4r=LPC=VFET2X1VOHw@mail.gmail.com> (raw)
In-Reply-To: <49971beb-0681-de92-95f5-b18e1be05ce3@nxp.com>

On Tue, Mar 17, 2020 at 9:45 AM Horia Geantă <horia.geanta@nxp.com> wrote:
>
> 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.
>

Why do we want this change though? It doesn't allow us to constify
"struct hwrng", don't seem to give any other benefits (maybe I am
missing something?) at the same time creating a new implicit global
variable. I'd rather not do this.

Thanks,
Andrey Smirnov

  reply	other threads:[~2020-03-19 13:01 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ă
2020-03-19 13:00     ` Andrey Smirnov [this message]
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='CAHQ1cqGcR=u8QPeD7PQtsZYEQL=5VQWv4r=LPC=VFET2X1VOHw@mail.gmail.com' \
    --to=andrew.smirnov@gmail.com \
    --cc=cphealy@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --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 \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).