Commit 1aa3d1a3 authored by Stephen Boyd's avatar Stephen Boyd Committed by David Brown

mfd: ssbi: Use devm_* and simplify code

Use devm_ioremap_resource and devm_kzalloc to simplify error
paths and reduce lines of code. Also use dev_err() to keep
consistency and drop the .remove function because the devm
functions take care of what it's doing besides the now obsolete
platform_set_drvdata() which we can just drop. Finally, use
module_platform_driver() to save some more lines.

Cc: David Brown <davidb@codeaurora.org>
Signed-off-by: default avatarStephen Boyd <sboyd@codeaurora.org>
Signed-off-by: default avatarDavid Brown <davidb@codeaurora.org>
parent 43f68444
...@@ -268,35 +268,23 @@ static int ssbi_probe(struct platform_device *pdev) ...@@ -268,35 +268,23 @@ static int ssbi_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct resource *mem_res; struct resource *mem_res;
struct ssbi *ssbi; struct ssbi *ssbi;
int ret = 0;
const char *type; const char *type;
ssbi = kzalloc(sizeof(struct ssbi), GFP_KERNEL); ssbi = devm_kzalloc(&pdev->dev, sizeof(*ssbi), GFP_KERNEL);
if (!ssbi) { if (!ssbi)
pr_err("can not allocate ssbi_data\n");
return -ENOMEM; return -ENOMEM;
}
mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!mem_res) { ssbi->base = devm_ioremap_resource(&pdev->dev, mem_res);
pr_err("missing mem resource\n"); if (IS_ERR(ssbi->base))
ret = -EINVAL; return PTR_ERR(ssbi->base);
goto err_get_mem_res;
}
ssbi->base = ioremap(mem_res->start, resource_size(mem_res));
if (!ssbi->base) {
pr_err("ioremap of 0x%p failed\n", (void *)mem_res->start);
ret = -EINVAL;
goto err_ioremap;
}
platform_set_drvdata(pdev, ssbi); platform_set_drvdata(pdev, ssbi);
type = of_get_property(np, "qcom,controller-type", NULL); type = of_get_property(np, "qcom,controller-type", NULL);
if (type == NULL) { if (type == NULL) {
pr_err("Missing qcom,controller-type property\n"); dev_err(&pdev->dev, "Missing qcom,controller-type property\n");
ret = -EINVAL; return -EINVAL;
goto err_ssbi_controller;
} }
dev_info(&pdev->dev, "SSBI controller type: '%s'\n", type); dev_info(&pdev->dev, "SSBI controller type: '%s'\n", type);
if (strcmp(type, "ssbi") == 0) if (strcmp(type, "ssbi") == 0)
...@@ -306,9 +294,8 @@ static int ssbi_probe(struct platform_device *pdev) ...@@ -306,9 +294,8 @@ static int ssbi_probe(struct platform_device *pdev)
else if (strcmp(type, "pmic-arbiter") == 0) else if (strcmp(type, "pmic-arbiter") == 0)
ssbi->controller_type = MSM_SBI_CTRL_PMIC_ARBITER; ssbi->controller_type = MSM_SBI_CTRL_PMIC_ARBITER;
else { else {
pr_err("Unknown qcom,controller-type\n"); dev_err(&pdev->dev, "Unknown qcom,controller-type\n");
ret = -EINVAL; return -EINVAL;
goto err_ssbi_controller;
} }
if (ssbi->controller_type == MSM_SBI_CTRL_PMIC_ARBITER) { if (ssbi->controller_type == MSM_SBI_CTRL_PMIC_ARBITER) {
...@@ -321,29 +308,7 @@ static int ssbi_probe(struct platform_device *pdev) ...@@ -321,29 +308,7 @@ static int ssbi_probe(struct platform_device *pdev)
spin_lock_init(&ssbi->lock); spin_lock_init(&ssbi->lock);
ret = of_platform_populate(np, NULL, NULL, &pdev->dev); return of_platform_populate(np, NULL, NULL, &pdev->dev);
if (ret)
goto err_ssbi_controller;
return 0;
err_ssbi_controller:
platform_set_drvdata(pdev, NULL);
iounmap(ssbi->base);
err_ioremap:
err_get_mem_res:
kfree(ssbi);
return ret;
}
static int ssbi_remove(struct platform_device *pdev)
{
struct ssbi *ssbi = platform_get_drvdata(pdev);
platform_set_drvdata(pdev, NULL);
iounmap(ssbi->base);
kfree(ssbi);
return 0;
} }
static struct of_device_id ssbi_match_table[] = { static struct of_device_id ssbi_match_table[] = {
...@@ -353,25 +318,13 @@ static struct of_device_id ssbi_match_table[] = { ...@@ -353,25 +318,13 @@ static struct of_device_id ssbi_match_table[] = {
static struct platform_driver ssbi_driver = { static struct platform_driver ssbi_driver = {
.probe = ssbi_probe, .probe = ssbi_probe,
.remove = ssbi_remove,
.driver = { .driver = {
.name = "ssbi", .name = "ssbi",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = ssbi_match_table, .of_match_table = ssbi_match_table,
}, },
}; };
module_platform_driver(ssbi_driver);
static int __init ssbi_init(void)
{
return platform_driver_register(&ssbi_driver);
}
module_init(ssbi_init);
static void __exit ssbi_exit(void)
{
platform_driver_unregister(&ssbi_driver);
}
module_exit(ssbi_exit)
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
MODULE_VERSION("1.0"); MODULE_VERSION("1.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