crypto: chelsio - Fix memory leak
authorHarsh Jain <harsh@chelsio.com>
Sun, 8 Oct 2017 08:07:24 +0000 (13:37 +0530)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 3 Nov 2017 13:50:46 +0000 (21:50 +0800)
Fix memory leak when device does not support crypto.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Harsh Jain <harsh@chelsio.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/chelsio/chcr_core.c

index 32618bf0ab3bb99be5a04f81e782707910288f59..f5a2624081dc2289509a56b1d2965b1401bd52b8 100644 (file)
@@ -153,16 +153,16 @@ static void *chcr_uld_add(const struct cxgb4_lld_info *lld)
 {
        struct uld_ctx *u_ctx;
 
+       /* Create the device and add it in the device list */
+       if (!(lld->ulp_crypto & ULP_CRYPTO_LOOKASIDE))
+               return ERR_PTR(-EOPNOTSUPP);
+
        /* Create the device and add it in the device list */
        u_ctx = kzalloc(sizeof(*u_ctx), GFP_KERNEL);
        if (!u_ctx) {
                u_ctx = ERR_PTR(-ENOMEM);
                goto out;
        }
-       if (!(lld->ulp_crypto & ULP_CRYPTO_LOOKASIDE)) {
-               u_ctx = ERR_PTR(-ENOMEM);
-               goto out;
-       }
        u_ctx->lldi = *lld;
 out:
        return u_ctx;