Return-path: Received: from mail-pd0-f182.google.com ([209.85.192.182]:36098 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751134AbaHJUBN (ORCPT ); Sun, 10 Aug 2014 16:01:13 -0400 Date: Mon, 11 Aug 2014 01:31:08 +0530 From: Himangi Saraogi To: Lauro Ramos Venancio , Aloisio Almeida Jr , Samuel Ortiz , linux-wireless@vger.kernel.org, linux-nfc@lists.01.org, linux-kernel@vger.kernel.org Cc: Julia Lawall Subject: [PATCH] NFC: st21nfcb: drop kfree of devm_kzalloc's data Message-ID: <20140810200107.GA4170@himangi-Dell> (sfid-20140810_220130_892560_2B286310) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-wireless-owner@vger.kernel.org List-ID: Using kfree to free data allocated with devm_kzalloc causes double frees. The Coccinelle semantic patch that fixes this problem is as follows: // @@ expression x; @@ x = devm_kzalloc(...) ... ?-kfree(x); // Signed-off-by: Himangi Saraogi Acked-by: Julia Lawall --- drivers/nfc/st21nfcb/st21nfcb.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/nfc/st21nfcb/st21nfcb.c b/drivers/nfc/st21nfcb/st21nfcb.c index 4d95863..b0c4a0f9 100644 --- a/drivers/nfc/st21nfcb/st21nfcb.c +++ b/drivers/nfc/st21nfcb/st21nfcb.c @@ -94,8 +94,7 @@ int st21nfcb_nci_probe(struct llt_ndlc *ndlc, int phy_headroom, phy_headroom, phy_tailroom); if (!ndlc->ndev) { pr_err("Cannot allocate nfc ndev\n"); - r = -ENOMEM; - goto err_alloc_ndev; + return -ENOMEM; } info->ndlc = ndlc; @@ -109,19 +108,14 @@ int st21nfcb_nci_probe(struct llt_ndlc *ndlc, int phy_headroom, err_regdev: nci_free_device(ndlc->ndev); -err_alloc_ndev: - kfree(info); return r; } EXPORT_SYMBOL_GPL(st21nfcb_nci_probe); void st21nfcb_nci_remove(struct nci_dev *ndev) { - struct st21nfcb_nci_info *info = nci_get_drvdata(ndev); - nci_unregister_device(ndev); nci_free_device(ndev); - kfree(info); } EXPORT_SYMBOL_GPL(st21nfcb_nci_remove); -- 1.9.1