NFC: nfcmrvl: Fix possible memory leak issue
authorAmitkumar Karwar <akarwar@marvell.com>
Wed, 8 Jan 2014 18:52:27 +0000 (10:52 -0800)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 9 Jan 2014 00:27:20 +0000 (01:27 +0100)
This patch fixes memory leaks in the error paths of
nfcmrvl_nci_register_dev() routine.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/nfc/nfcmrvl/main.c

index 5f91d45714299848f2f11c9891884c02947b2256..85e8bcf986936123bdab959e5b01fb8738d80e79 100644 (file)
@@ -112,7 +112,8 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
        priv->ndev = nci_allocate_device(&nfcmrvl_nci_ops, protocols, 0, 0);
        if (!priv->ndev) {
                nfc_err(dev, "nci_allocate_device failed");
-               return ERR_PTR(-ENOMEM);
+               rc = -ENOMEM;
+               goto error;
        }
 
        nci_set_drvdata(priv->ndev, priv);
@@ -121,11 +122,15 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
        if (rc) {
                nfc_err(dev, "nci_register_device failed %d", rc);
                nci_free_device(priv->ndev);
-               return ERR_PTR(rc);
+               goto error;
        }
 
        nfc_info(dev, "registered with nci successfully\n");
        return priv;
+
+error:
+       kfree(priv);
+       return ERR_PTR(rc);
 }
 EXPORT_SYMBOL_GPL(nfcmrvl_nci_register_dev);