brcm47xx: 3.10: backport MIPS patches for early HIGHMEM support
[15.05/openwrt.git] / target / linux / brcm47xx / patches-3.10 / 054-mtd_bcm47xxsflash_convert_kzalloc_to_avoid_invalid_access.patch
1 Date: Thu, 30 May 2013 10:22:12 +0800
2 From: Libo Chen <clbchenlibo.chen@huawei.com>
3 Subject: [PATCH RESEND 1/2] mtd: bcm47: convert kzalloc to avoid invalid access
4
5
6 mtd is just member of bcm47xxsflash, so we should free bcm47xxsflash not its member.
7 So I use devm_kazlloc instead of kazlloc to avoid it.
8
9 * Changelog:
10    convert to devm_kzalloc
11
12 Signed-off-by: Libo chen <libo.chen@huawei.com>
13 Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
14 ---
15  drivers/mtd/devices/bcm47xxsflash.c |   16 ++++------------
16  1 files changed, 4 insertions(+), 12 deletions(-)
17
18 --- a/drivers/mtd/devices/bcm47xxsflash.c
19 +++ b/drivers/mtd/devices/bcm47xxsflash.c
20 @@ -278,11 +278,9 @@ static int bcm47xxsflash_bcma_probe(stru
21         struct bcm47xxsflash *b47s;
22         int err;
23  
24 -       b47s = kzalloc(sizeof(*b47s), GFP_KERNEL);
25 -       if (!b47s) {
26 -               err = -ENOMEM;
27 -               goto out;
28 -       }
29 +       b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
30 +       if (!b47s)
31 +               return -ENOMEM;
32         sflash->priv = b47s;
33  
34         b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
35 @@ -307,18 +305,13 @@ static int bcm47xxsflash_bcma_probe(stru
36         err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
37         if (err) {
38                 pr_err("Failed to register MTD device: %d\n", err);
39 -               goto err_dev_reg;
40 +               return err;
41         }
42  
43         if (bcm47xxsflash_poll(b47s, HZ / 10))
44                 pr_warn("Serial flash busy\n");
45  
46         return 0;
47 -
48 -err_dev_reg:
49 -       kfree(&b47s->mtd);
50 -out:
51 -       return err;
52  }
53  
54  static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
55 @@ -327,7 +320,6 @@ static int bcm47xxsflash_bcma_remove(str
56         struct bcm47xxsflash *b47s = sflash->priv;
57  
58         mtd_device_unregister(&b47s->mtd);
59 -       kfree(b47s);
60  
61         return 0;
62  }