mtd: bcm47xxsflash: convert kzalloc to avoid invalid access

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Fri Aug 30 16:59:05 EDT 2013


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=d2b1bd1422d9385cc5f463e3cc6ea0cbe7e98b70
Commit:     d2b1bd1422d9385cc5f463e3cc6ea0cbe7e98b70
Parent:     ebc6e4b6525872498fb01f5ad9c29a81b9d49831
Author:     Libo Chen <clbchenlibo.chen at huawei.com>
AuthorDate: Thu May 30 10:22:12 2013 +0800
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Fri Aug 30 21:52:10 2013 +0100

    mtd: bcm47xxsflash: convert kzalloc to avoid invalid access
    
    mtd is just member of bcm47xxsflash, so we should free bcm47xxsflash not
    its member. So I use devm_kazlloc instead of kazlloc to avoid it.
    
    * Changelog:
       convert to devm_kzalloc
    
    Signed-off-by: Libo chen <libo.chen at huawei.com>
    Suggested-by: Andy Shevchenko <andy.shevchenko at gmail.com>
    Reviewed-by: Andy Shevchenko <andy.shevchenko at gmail.com>
    [Brian: fixed conflicts]
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
    
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/devices/bcm47xxsflash.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/devices/bcm47xxsflash.c b/drivers/mtd/devices/bcm47xxsflash.c
index 2060856..fa56a47 100644
--- a/drivers/mtd/devices/bcm47xxsflash.c
+++ b/drivers/mtd/devices/bcm47xxsflash.c
@@ -117,11 +117,9 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
 	struct bcm47xxsflash *b47s;
 	int err;
 
-	b47s = kzalloc(sizeof(*b47s), GFP_KERNEL);
-	if (!b47s) {
-		err = -ENOMEM;
-		goto out;
-	}
+	b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
+	if (!b47s)
+		return -ENOMEM;
 	sflash->priv = b47s;
 
 	b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
@@ -146,18 +144,13 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
 	err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
 	if (err) {
 		pr_err("Failed to register MTD device: %d\n", err);
-		goto err_dev_reg;
+		return err;
 	}
 
 	if (bcm47xxsflash_poll(b47s, HZ / 10))
 		pr_warn("Serial flash busy\n");
 
 	return 0;
-
-err_dev_reg:
-	kfree(&b47s->mtd);
-out:
-	return err;
 }
 
 static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
@@ -166,7 +159,6 @@ static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
 	struct bcm47xxsflash *b47s = sflash->priv;
 
 	mtd_device_unregister(&b47s->mtd);
-	kfree(b47s);
 
 	return 0;
 }



More information about the linux-mtd-cvs mailing list