Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NFC: nfcmrvl: Fix possible memory leak issue

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>

authored by

Amitkumar Karwar and committed by
Samuel Ortiz
bb55dc2a b711ad52

+7 -2
+7 -2
drivers/nfc/nfcmrvl/main.c
··· 112 112 priv->ndev = nci_allocate_device(&nfcmrvl_nci_ops, protocols, 0, 0); 113 113 if (!priv->ndev) { 114 114 nfc_err(dev, "nci_allocate_device failed"); 115 - return ERR_PTR(-ENOMEM); 115 + rc = -ENOMEM; 116 + goto error; 116 117 } 117 118 118 119 nci_set_drvdata(priv->ndev, priv); ··· 122 121 if (rc) { 123 122 nfc_err(dev, "nci_register_device failed %d", rc); 124 123 nci_free_device(priv->ndev); 125 - return ERR_PTR(rc); 124 + goto error; 126 125 } 127 126 128 127 nfc_info(dev, "registered with nci successfully\n"); 129 128 return priv; 129 + 130 + error: 131 + kfree(priv); 132 + return ERR_PTR(rc); 130 133 } 131 134 EXPORT_SYMBOL_GPL(nfcmrvl_nci_register_dev); 132 135