aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJingoo Han <jg1.han@samsung.com>2014-01-02 21:16:28 -0500
committerBrian Norris <computersforpeace@gmail.com>2014-01-07 13:07:33 -0500
commitffdac7cd31d04f81a09f517f37c371c5f978efec (patch)
tree8b39c1e2b42d7e767b493b918974824d3a9b9482
parented0b272ed25fb947af1cc71973b986be6dd19d04 (diff)
mtd: plat_nand: Use devm_*() functions
Use devm_*() functions to make cleanup paths simpler. Signed-off-by: Jingoo Han <jg1.han@samsung.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
-rw-r--r--drivers/mtd/nand/plat_nand.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index cad4cdc9df39..d00e3a7c6bd8 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -9,6 +9,7 @@
9 * 9 *
10 */ 10 */
11 11
12#include <linux/err.h>
12#include <linux/io.h> 13#include <linux/io.h>
13#include <linux/module.h> 14#include <linux/module.h>
14#include <linux/platform_device.h> 15#include <linux/platform_device.h>
@@ -52,25 +53,16 @@ static int plat_nand_probe(struct platform_device *pdev)
52 return -ENXIO; 53 return -ENXIO;
53 54
54 /* Allocate memory for the device structure (and zero it) */ 55 /* Allocate memory for the device structure (and zero it) */
55 data = kzalloc(sizeof(struct plat_nand_data), GFP_KERNEL); 56 data = devm_kzalloc(&pdev->dev, sizeof(struct plat_nand_data),
57 GFP_KERNEL);
56 if (!data) { 58 if (!data) {
57 dev_err(&pdev->dev, "failed to allocate device structure.\n"); 59 dev_err(&pdev->dev, "failed to allocate device structure.\n");
58 return -ENOMEM; 60 return -ENOMEM;
59 } 61 }
60 62
61 if (!request_mem_region(res->start, resource_size(res), 63 data->io_base = devm_ioremap_resource(&pdev->dev, res);
62 dev_name(&pdev->dev))) { 64 if (IS_ERR(data->io_base))
63 dev_err(&pdev->dev, "request_mem_region failed\n"); 65 return PTR_ERR(data->io_base);
64 err = -EBUSY;
65 goto out_free;
66 }
67
68 data->io_base = ioremap(res->start, resource_size(res));
69 if (data->io_base == NULL) {
70 dev_err(&pdev->dev, "ioremap failed\n");
71 err = -EIO;
72 goto out_release_io;
73 }
74 66
75 data->chip.priv = &data; 67 data->chip.priv = &data;
76 data->mtd.priv = &data->chip; 68 data->mtd.priv = &data->chip;
@@ -122,11 +114,6 @@ static int plat_nand_probe(struct platform_device *pdev)
122out: 114out:
123 if (pdata->ctrl.remove) 115 if (pdata->ctrl.remove)
124 pdata->ctrl.remove(pdev); 116 pdata->ctrl.remove(pdev);
125 iounmap(data->io_base);
126out_release_io:
127 release_mem_region(res->start, resource_size(res));
128out_free:
129 kfree(data);
130 return err; 117 return err;
131} 118}
132 119
@@ -137,16 +124,10 @@ static int plat_nand_remove(struct platform_device *pdev)
137{ 124{
138 struct plat_nand_data *data = platform_get_drvdata(pdev); 125 struct plat_nand_data *data = platform_get_drvdata(pdev);
139 struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev); 126 struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
140 struct resource *res;
141
142 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
143 127
144 nand_release(&data->mtd); 128 nand_release(&data->mtd);
145 if (pdata->ctrl.remove) 129 if (pdata->ctrl.remove)
146 pdata->ctrl.remove(pdev); 130 pdata->ctrl.remove(pdev);
147 iounmap(data->io_base);
148 release_mem_region(res->start, resource_size(res));
149 kfree(data);
150 131
151 return 0; 132 return 0;
152} 133}