Skip to content

Commit d2b1bd1

Browse files
Libo ChenDavid Woodhouse
authored andcommitted
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>
1 parent ebc6e4b commit d2b1bd1

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

drivers/mtd/devices/bcm47xxsflash.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,9 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
117117
struct bcm47xxsflash *b47s;
118118
int err;
119119

120-
b47s = kzalloc(sizeof(*b47s), GFP_KERNEL);
121-
if (!b47s) {
122-
err = -ENOMEM;
123-
goto out;
124-
}
120+
b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
121+
if (!b47s)
122+
return -ENOMEM;
125123
sflash->priv = b47s;
126124

127125
b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
@@ -146,18 +144,13 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
146144
err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
147145
if (err) {
148146
pr_err("Failed to register MTD device: %d\n", err);
149-
goto err_dev_reg;
147+
return err;
150148
}
151149

152150
if (bcm47xxsflash_poll(b47s, HZ / 10))
153151
pr_warn("Serial flash busy\n");
154152

155153
return 0;
156-
157-
err_dev_reg:
158-
kfree(&b47s->mtd);
159-
out:
160-
return err;
161154
}
162155

163156
static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
@@ -166,7 +159,6 @@ static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
166159
struct bcm47xxsflash *b47s = sflash->priv;
167160

168161
mtd_device_unregister(&b47s->mtd);
169-
kfree(b47s);
170162

171163
return 0;
172164
}

0 commit comments

Comments
 (0)