[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHQ1cqHmn2JwNVjOGdbjuSnf6abfOUVe4xoCE=qvV8++jSFdZg@mail.gmail.com>
Date: Mon, 27 Jan 2020 05:44:32 -0800
From: Andrey Smirnov <andrew.smirnov@...il.com>
To: Horia Geanta <horia.geanta@....com>
Cc: "linux-crypto@...r.kernel.org" <linux-crypto@...r.kernel.org>,
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 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@....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
Powered by blists - more mailing lists