lkml.org 
[lkml]   [2020]   [Jan]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v6 2/7] crypto: caam - drop global context pointer and init_done
Date
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

\
 
 \ /
  Last update: 2020-01-13 10:42    [W:0.258 / U:1.264 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site