diff options
author | Jingoo Han <jg1.han@samsung.com> | 2013-12-25 20:42:34 -0500 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2014-01-03 14:22:27 -0500 |
commit | 436bf63ba5792f2f7bb5e1a4e8d38df8f1a44edc (patch) | |
tree | 011f172c34cbf6b7540ec1fdff191787667a96e2 | |
parent | 82402aeb8c81edab9249b9e330b21e88723f539e (diff) |
mtd: lantiq-flash: Use devm_kzalloc()
Use devm_kzalloc() to make cleanup paths simpler. Also, checking
return value of devm_kzalloc() is added in order to check if the
allocation succeded.
Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Acked-by: John Crispin <blogic@openwrt.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
-rw-r--r-- | drivers/mtd/maps/lantiq-flash.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c index d7ac65d1d569..93c507a6f862 100644 --- a/drivers/mtd/maps/lantiq-flash.c +++ b/drivers/mtd/maps/lantiq-flash.c | |||
@@ -123,24 +123,28 @@ ltq_mtd_probe(struct platform_device *pdev) | |||
123 | return -ENODEV; | 123 | return -ENODEV; |
124 | } | 124 | } |
125 | 125 | ||
126 | ltq_mtd = kzalloc(sizeof(struct ltq_mtd), GFP_KERNEL); | 126 | ltq_mtd = devm_kzalloc(&pdev->dev, sizeof(struct ltq_mtd), GFP_KERNEL); |
127 | if (!ltq_mtd) | ||
128 | return -ENOMEM; | ||
129 | |||
127 | platform_set_drvdata(pdev, ltq_mtd); | 130 | platform_set_drvdata(pdev, ltq_mtd); |
128 | 131 | ||
129 | ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 132 | ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
130 | if (!ltq_mtd->res) { | 133 | if (!ltq_mtd->res) { |
131 | dev_err(&pdev->dev, "failed to get memory resource\n"); | 134 | dev_err(&pdev->dev, "failed to get memory resource\n"); |
132 | err = -ENOENT; | 135 | return -ENOENT; |
133 | goto err_out; | ||
134 | } | 136 | } |
135 | 137 | ||
136 | ltq_mtd->map = kzalloc(sizeof(struct map_info), GFP_KERNEL); | 138 | ltq_mtd->map = devm_kzalloc(&pdev->dev, sizeof(struct map_info), |
139 | GFP_KERNEL); | ||
140 | if (!ltq_mtd->map) | ||
141 | return -ENOMEM; | ||
142 | |||
137 | ltq_mtd->map->phys = ltq_mtd->res->start; | 143 | ltq_mtd->map->phys = ltq_mtd->res->start; |
138 | ltq_mtd->map->size = resource_size(ltq_mtd->res); | 144 | ltq_mtd->map->size = resource_size(ltq_mtd->res); |
139 | ltq_mtd->map->virt = devm_ioremap_resource(&pdev->dev, ltq_mtd->res); | 145 | ltq_mtd->map->virt = devm_ioremap_resource(&pdev->dev, ltq_mtd->res); |
140 | if (IS_ERR(ltq_mtd->map->virt)) { | 146 | if (IS_ERR(ltq_mtd->map->virt)) |
141 | err = PTR_ERR(ltq_mtd->map->virt); | 147 | return PTR_ERR(ltq_mtd->map->virt); |
142 | goto err_out; | ||
143 | } | ||
144 | 148 | ||
145 | ltq_mtd->map->name = ltq_map_name; | 149 | ltq_mtd->map->name = ltq_map_name; |
146 | ltq_mtd->map->bankwidth = 2; | 150 | ltq_mtd->map->bankwidth = 2; |
@@ -155,8 +159,7 @@ ltq_mtd_probe(struct platform_device *pdev) | |||
155 | 159 | ||
156 | if (!ltq_mtd->mtd) { | 160 | if (!ltq_mtd->mtd) { |
157 | dev_err(&pdev->dev, "probing failed\n"); | 161 | dev_err(&pdev->dev, "probing failed\n"); |
158 | err = -ENXIO; | 162 | return -ENXIO; |
159 | goto err_free; | ||
160 | } | 163 | } |
161 | 164 | ||
162 | ltq_mtd->mtd->owner = THIS_MODULE; | 165 | ltq_mtd->mtd->owner = THIS_MODULE; |
@@ -177,10 +180,6 @@ ltq_mtd_probe(struct platform_device *pdev) | |||
177 | 180 | ||
178 | err_destroy: | 181 | err_destroy: |
179 | map_destroy(ltq_mtd->mtd); | 182 | map_destroy(ltq_mtd->mtd); |
180 | err_free: | ||
181 | kfree(ltq_mtd->map); | ||
182 | err_out: | ||
183 | kfree(ltq_mtd); | ||
184 | return err; | 183 | return err; |
185 | } | 184 | } |
186 | 185 | ||
@@ -189,13 +188,9 @@ ltq_mtd_remove(struct platform_device *pdev) | |||
189 | { | 188 | { |
190 | struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev); | 189 | struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev); |
191 | 190 | ||
192 | if (ltq_mtd) { | 191 | if (ltq_mtd && ltq_mtd->mtd) { |
193 | if (ltq_mtd->mtd) { | 192 | mtd_device_unregister(ltq_mtd->mtd); |
194 | mtd_device_unregister(ltq_mtd->mtd); | 193 | map_destroy(ltq_mtd->mtd); |
195 | map_destroy(ltq_mtd->mtd); | ||
196 | } | ||
197 | kfree(ltq_mtd->map); | ||
198 | kfree(ltq_mtd); | ||
199 | } | 194 | } |
200 | return 0; | 195 | return 0; |
201 | } | 196 | } |