2014-03-07 05:23:37

by [email protected]

[permalink] [raw]
Subject: [PATCH] crypto: caam - Dynamic memory allocation for caam_rng_ctx object

This patch allocates memory from DMAable region to the caam_rng_ctx object,
earlier it had been statically allocated which resulted in errorneous
behaviour on inserting the caamrng module at the runtime.

Signed-off-by: Nitesh Lal <[email protected]>
---
drivers/crypto/caam/caamrng.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index 28486b1..403d8d5 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -76,7 +76,7 @@ struct caam_rng_ctx {
struct buf_data bufs[2];
};

-static struct caam_rng_ctx rng_ctx;
+static struct caam_rng_ctx *rng_ctx;

static inline void rng_unmap_buf(struct device *jrdev, struct buf_data *bd)
{
@@ -137,7 +137,7 @@ static inline int submit_job(struct caam_rng_ctx *ctx, int to_current)

static int caam_read(struct hwrng *rng, void *data, size_t max, bool wait)
{
- struct caam_rng_ctx *ctx = &rng_ctx;
+ struct caam_rng_ctx *ctx = rng_ctx;
struct buf_data *bd = &ctx->bufs[ctx->current_buf];
int next_buf_idx, copied_idx;
int err;
@@ -237,12 +237,12 @@ static void caam_cleanup(struct hwrng *rng)
struct buf_data *bd;

for (i = 0; i < 2; i++) {
- bd = &rng_ctx.bufs[i];
+ bd = &rng_ctx->bufs[i];
if (atomic_read(&bd->empty) == BUF_PENDING)
wait_for_completion(&bd->filled);
}

- rng_unmap_ctx(&rng_ctx);
+ rng_unmap_ctx(rng_ctx);
}

static void caam_init_buf(struct caam_rng_ctx *ctx, int buf_id)
@@ -273,8 +273,9 @@ static struct hwrng caam_rng = {

static void __exit caam_rng_exit(void)
{
- caam_jr_free(rng_ctx.jrdev);
+ caam_jr_free(rng_ctx->jrdev);
hwrng_unregister(&caam_rng);
+ kfree(rng_ctx);
}

static int __init caam_rng_init(void)
@@ -286,7 +287,9 @@ static int __init caam_rng_init(void)
pr_err("Job Ring Device allocation for transform failed\n");
return PTR_ERR(dev);
}
-
+ rng_ctx = kmalloc(sizeof(struct caam_rng_ctx), GFP_DMA);
+ if (!rng_ctx)
+ return -ENOMEM;
caam_init_rng(&rng_ctx, dev);

dev_info(dev, "registering rng-caam\n");
--
1.8.1.4


2014-03-07 06:28:00

by Ruchika Gupta

[permalink] [raw]
Subject: RE: [PATCH] crypto: caam - Dynamic memory allocation for caam_rng_ctx object

Acked-by: Ruchika Gupta <[email protected]>

> -----Original Message-----
> From: Nitesh Lal [mailto:[email protected]]
> Sent: Friday, March 07, 2014 4:06 PM
> To: [email protected]; Gupta Ruchika-R66431; Dutta Yashpal-
> B05456; [email protected]
> Cc: Lal Nitesh-B44382
> Subject: [PATCH] crypto: caam - Dynamic memory allocation for caam_rng_ctx
> object
>
> This patch allocates memory from DMAable region to the caam_rng_ctx object,
> earlier it had been statically allocated which resulted in errorneous
> behaviour on inserting the caamrng module at the runtime.
>
> Signed-off-by: Nitesh Lal <[email protected]>
> ---
> drivers/crypto/caam/caamrng.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
> index 28486b1..403d8d5 100644
> --- a/drivers/crypto/caam/caamrng.c
> +++ b/drivers/crypto/caam/caamrng.c
> @@ -76,7 +76,7 @@ struct caam_rng_ctx {
> struct buf_data bufs[2];
> };
>
> -static struct caam_rng_ctx rng_ctx;
> +static struct caam_rng_ctx *rng_ctx;
>
> static inline void rng_unmap_buf(struct device *jrdev, struct buf_data *bd)
> { @@ -137,7 +137,7 @@ static inline int submit_job(struct caam_rng_ctx *ctx,
> int to_current)
>
> static int caam_read(struct hwrng *rng, void *data, size_t max, bool wait)
> {
> - struct caam_rng_ctx *ctx = &rng_ctx;
> + struct caam_rng_ctx *ctx = rng_ctx;
> struct buf_data *bd = &ctx->bufs[ctx->current_buf];
> int next_buf_idx, copied_idx;
> int err;
> @@ -237,12 +237,12 @@ static void caam_cleanup(struct hwrng *rng)
> struct buf_data *bd;
>
> for (i = 0; i < 2; i++) {
> - bd = &rng_ctx.bufs[i];
> + bd = &rng_ctx->bufs[i];
> if (atomic_read(&bd->empty) == BUF_PENDING)
> wait_for_completion(&bd->filled);
> }
>
> - rng_unmap_ctx(&rng_ctx);
> + rng_unmap_ctx(rng_ctx);
> }
>
> static void caam_init_buf(struct caam_rng_ctx *ctx, int buf_id) @@ -273,8
> +273,9 @@ static struct hwrng caam_rng = {
>
> static void __exit caam_rng_exit(void)
> {
> - caam_jr_free(rng_ctx.jrdev);
> + caam_jr_free(rng_ctx->jrdev);
> hwrng_unregister(&caam_rng);
> + kfree(rng_ctx);
> }
>
> static int __init caam_rng_init(void)
> @@ -286,7 +287,9 @@ static int __init caam_rng_init(void)
> pr_err("Job Ring Device allocation for transform failed\n");
> return PTR_ERR(dev);
> }
> -
> + rng_ctx = kmalloc(sizeof(struct caam_rng_ctx), GFP_DMA);
> + if (!rng_ctx)
> + return -ENOMEM;
> caam_init_rng(&rng_ctx, dev);
>
> dev_info(dev, "registering rng-caam\n");
> --
> 1.8.1.4
>

2014-03-10 12:23:14

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] crypto: caam - Dynamic memory allocation for caam_rng_ctx object

On Fri, Mar 07, 2014 at 06:27:58AM +0000, Ruchika Gupta wrote:
> Acked-by: Ruchika Gupta <[email protected]>

Patch applied.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt