crypto: caam - Fix error handling in caam_rng_init()
authorFabio Estevam <fabio.estevam@freescale.com>
Wed, 12 Aug 2015 14:48:42 +0000 (11:48 -0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 13 Aug 2015 07:13:29 +0000 (15:13 +0800)
In the error paths we should free the resources that were
previously acquired, so fix it accordingly.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Reviewed-by: Horia Geant? <horia.geanta@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/caam/caamrng.c

index 345024c224674d21da026eca51781c41b4d55118..fb0cc54fa70cc8223edef4cf6988955d4715b4e0 100644 (file)
@@ -352,14 +352,22 @@ static int __init caam_rng_init(void)
                return PTR_ERR(dev);
        }
        rng_ctx = kmalloc(sizeof(struct caam_rng_ctx), GFP_DMA);
-       if (!rng_ctx)
-               return -ENOMEM;
+       if (!rng_ctx) {
+               err = -ENOMEM;
+               goto free_caam_alloc;
+       }
        err = caam_init_rng(rng_ctx, dev);
        if (err)
-               return err;
+               goto free_rng_ctx;
 
        dev_info(dev, "registering rng-caam\n");
        return hwrng_register(&caam_rng);
+
+free_rng_ctx:
+       kfree(rng_ctx);
+free_caam_alloc:
+       caam_jr_free(dev);
+       return err;
 }
 
 module_init(caam_rng_init);