lkml.org 
[lkml]   [2020]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v6 2/7] crypto: caam - drop global context pointer and init_done
On Mon, Jan 13, 2020 at 1:41 AM Horia Geanta <horia.geanta@nxp.com> wrote:
>
> 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.
>

True, but the logic you describe is broken in reality due to circular
reference from HWRNG, which we never fixed. I'll fix both in v7.

Thanks,
Andrey Smirnov

\
 
 \ /
  Last update: 2020-01-27 14:45    [W:0.058 / U:1.780 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site