Commit 436bf63b authored by Jingoo Han's avatar Jingoo Han Committed by Brian Norris

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: default avatarJingoo Han <jg1.han@samsung.com>
Acked-by: default avatarJohn Crispin <blogic@openwrt.org>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent 82402aeb
...@@ -123,24 +123,28 @@ ltq_mtd_probe(struct platform_device *pdev) ...@@ -123,24 +123,28 @@ ltq_mtd_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
ltq_mtd = kzalloc(sizeof(struct ltq_mtd), GFP_KERNEL); ltq_mtd = devm_kzalloc(&pdev->dev, sizeof(struct ltq_mtd), GFP_KERNEL);
if (!ltq_mtd)
return -ENOMEM;
platform_set_drvdata(pdev, ltq_mtd); platform_set_drvdata(pdev, ltq_mtd);
ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!ltq_mtd->res) { if (!ltq_mtd->res) {
dev_err(&pdev->dev, "failed to get memory resource\n"); dev_err(&pdev->dev, "failed to get memory resource\n");
err = -ENOENT; return -ENOENT;
goto err_out;
} }
ltq_mtd->map = kzalloc(sizeof(struct map_info), GFP_KERNEL); ltq_mtd->map = devm_kzalloc(&pdev->dev, sizeof(struct map_info),
GFP_KERNEL);
if (!ltq_mtd->map)
return -ENOMEM;
ltq_mtd->map->phys = ltq_mtd->res->start; ltq_mtd->map->phys = ltq_mtd->res->start;
ltq_mtd->map->size = resource_size(ltq_mtd->res); ltq_mtd->map->size = resource_size(ltq_mtd->res);
ltq_mtd->map->virt = devm_ioremap_resource(&pdev->dev, ltq_mtd->res); ltq_mtd->map->virt = devm_ioremap_resource(&pdev->dev, ltq_mtd->res);
if (IS_ERR(ltq_mtd->map->virt)) { if (IS_ERR(ltq_mtd->map->virt))
err = PTR_ERR(ltq_mtd->map->virt); return PTR_ERR(ltq_mtd->map->virt);
goto err_out;
}
ltq_mtd->map->name = ltq_map_name; ltq_mtd->map->name = ltq_map_name;
ltq_mtd->map->bankwidth = 2; ltq_mtd->map->bankwidth = 2;
...@@ -155,8 +159,7 @@ ltq_mtd_probe(struct platform_device *pdev) ...@@ -155,8 +159,7 @@ ltq_mtd_probe(struct platform_device *pdev)
if (!ltq_mtd->mtd) { if (!ltq_mtd->mtd) {
dev_err(&pdev->dev, "probing failed\n"); dev_err(&pdev->dev, "probing failed\n");
err = -ENXIO; return -ENXIO;
goto err_free;
} }
ltq_mtd->mtd->owner = THIS_MODULE; ltq_mtd->mtd->owner = THIS_MODULE;
...@@ -177,10 +180,6 @@ ltq_mtd_probe(struct platform_device *pdev) ...@@ -177,10 +180,6 @@ ltq_mtd_probe(struct platform_device *pdev)
err_destroy: err_destroy:
map_destroy(ltq_mtd->mtd); map_destroy(ltq_mtd->mtd);
err_free:
kfree(ltq_mtd->map);
err_out:
kfree(ltq_mtd);
return err; return err;
} }
...@@ -189,13 +188,9 @@ ltq_mtd_remove(struct platform_device *pdev) ...@@ -189,13 +188,9 @@ ltq_mtd_remove(struct platform_device *pdev)
{ {
struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev); struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev);
if (ltq_mtd) { if (ltq_mtd && ltq_mtd->mtd) {
if (ltq_mtd->mtd) { mtd_device_unregister(ltq_mtd->mtd);
mtd_device_unregister(ltq_mtd->mtd); map_destroy(ltq_mtd->mtd);
map_destroy(ltq_mtd->mtd);
}
kfree(ltq_mtd->map);
kfree(ltq_mtd);
} }
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment