aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibo Chen <clbchenlibo.chen@huawei.com>2013-05-29 22:22:12 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2013-08-30 16:52:10 -0400
commitd2b1bd1422d9385cc5f463e3cc6ea0cbe7e98b70 (patch)
tree360348d1739af5da7b88c475545627bad7bfc52c
parentebc6e4b6525872498fb01f5ad9c29a81b9d49831 (diff)
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@huawei.com> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> [Brian: fixed conflicts] Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r--drivers/mtd/devices/bcm47xxsflash.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/drivers/mtd/devices/bcm47xxsflash.c b/drivers/mtd/devices/bcm47xxsflash.c
index 2060856dbf97..fa56a47a598d 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)
117 struct bcm47xxsflash *b47s; 117 struct bcm47xxsflash *b47s;
118 int err; 118 int err;
119 119
120 b47s = kzalloc(sizeof(*b47s), GFP_KERNEL); 120 b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
121 if (!b47s) { 121 if (!b47s)
122 err = -ENOMEM; 122 return -ENOMEM;
123 goto out;
124 }
125 sflash->priv = b47s; 123 sflash->priv = b47s;
126 124
127 b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash); 125 b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
@@ -146,18 +144,13 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
146 err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0); 144 err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
147 if (err) { 145 if (err) {
148 pr_err("Failed to register MTD device: %d\n", err); 146 pr_err("Failed to register MTD device: %d\n", err);
149 goto err_dev_reg; 147 return err;
150 } 148 }
151 149
152 if (bcm47xxsflash_poll(b47s, HZ / 10)) 150 if (bcm47xxsflash_poll(b47s, HZ / 10))
153 pr_warn("Serial flash busy\n"); 151 pr_warn("Serial flash busy\n");
154 152
155 return 0; 153 return 0;
156
157err_dev_reg:
158 kfree(&b47s->mtd);
159out:
160 return err;
161} 154}
162 155
163static int bcm47xxsflash_bcma_remove(struct platform_device *pdev) 156static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
@@ -166,7 +159,6 @@ static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
166 struct bcm47xxsflash *b47s = sflash->priv; 159 struct bcm47xxsflash *b47s = sflash->priv;
167 160
168 mtd_device_unregister(&b47s->mtd); 161 mtd_device_unregister(&b47s->mtd);
169 kfree(b47s);
170 162
171 return 0; 163 return 0;
172} 164}