Skip to content

Commit e578438

Browse files
bebarinoSamuel Ortiz
authored andcommitted
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: Stephen Boyd <sboyd@codeaurora.org> Acked-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 6378c1e commit e578438

1 file changed

Lines changed: 11 additions & 58 deletions

File tree

‎drivers/mfd/ssbi.c‎

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -268,35 +268,23 @@ static int ssbi_probe(struct platform_device *pdev)
268268
struct device_node *np = pdev->dev.of_node;
269269
struct resource *mem_res;
270270
struct ssbi *ssbi;
271-
int ret = 0;
272271
const char *type;
273272

274-
ssbi = kzalloc(sizeof(struct ssbi), GFP_KERNEL);
275-
if (!ssbi) {
276-
pr_err("can not allocate ssbi_data\n");
273+
ssbi = devm_kzalloc(&pdev->dev, sizeof(*ssbi), GFP_KERNEL);
274+
if (!ssbi)
277275
return -ENOMEM;
278-
}
279276

280277
mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
281-
if (!mem_res) {
282-
pr_err("missing mem resource\n");
283-
ret = -EINVAL;
284-
goto err_get_mem_res;
285-
}
278+
ssbi->base = devm_ioremap_resource(&pdev->dev, mem_res);
279+
if (IS_ERR(ssbi->base))
280+
return PTR_ERR(ssbi->base);
286281

287-
ssbi->base = ioremap(mem_res->start, resource_size(mem_res));
288-
if (!ssbi->base) {
289-
pr_err("ioremap of 0x%p failed\n", (void *)mem_res->start);
290-
ret = -EINVAL;
291-
goto err_ioremap;
292-
}
293282
platform_set_drvdata(pdev, ssbi);
294283

295284
type = of_get_property(np, "qcom,controller-type", NULL);
296285
if (type == NULL) {
297-
pr_err("Missing qcom,controller-type property\n");
298-
ret = -EINVAL;
299-
goto err_ssbi_controller;
286+
dev_err(&pdev->dev, "Missing qcom,controller-type property\n");
287+
return -EINVAL;
300288
}
301289
dev_info(&pdev->dev, "SSBI controller type: '%s'\n", type);
302290
if (strcmp(type, "ssbi") == 0)
@@ -306,9 +294,8 @@ static int ssbi_probe(struct platform_device *pdev)
306294
else if (strcmp(type, "pmic-arbiter") == 0)
307295
ssbi->controller_type = MSM_SBI_CTRL_PMIC_ARBITER;
308296
else {
309-
pr_err("Unknown qcom,controller-type\n");
310-
ret = -EINVAL;
311-
goto err_ssbi_controller;
297+
dev_err(&pdev->dev, "Unknown qcom,controller-type\n");
298+
return -EINVAL;
312299
}
313300

314301
if (ssbi->controller_type == MSM_SBI_CTRL_PMIC_ARBITER) {
@@ -321,29 +308,7 @@ static int ssbi_probe(struct platform_device *pdev)
321308

322309
spin_lock_init(&ssbi->lock);
323310

324-
ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
325-
if (ret)
326-
goto err_ssbi_controller;
327-
328-
return 0;
329-
330-
err_ssbi_controller:
331-
platform_set_drvdata(pdev, NULL);
332-
iounmap(ssbi->base);
333-
err_ioremap:
334-
err_get_mem_res:
335-
kfree(ssbi);
336-
return ret;
337-
}
338-
339-
static int ssbi_remove(struct platform_device *pdev)
340-
{
341-
struct ssbi *ssbi = platform_get_drvdata(pdev);
342-
343-
platform_set_drvdata(pdev, NULL);
344-
iounmap(ssbi->base);
345-
kfree(ssbi);
346-
return 0;
311+
return of_platform_populate(np, NULL, NULL, &pdev->dev);
347312
}
348313

349314
static struct of_device_id ssbi_match_table[] = {
@@ -354,25 +319,13 @@ MODULE_DEVICE_TABLE(of, ssbi_match_table);
354319

355320
static struct platform_driver ssbi_driver = {
356321
.probe = ssbi_probe,
357-
.remove = ssbi_remove,
358322
.driver = {
359323
.name = "ssbi",
360324
.owner = THIS_MODULE,
361325
.of_match_table = ssbi_match_table,
362326
},
363327
};
364-
365-
static int __init ssbi_init(void)
366-
{
367-
return platform_driver_register(&ssbi_driver);
368-
}
369-
module_init(ssbi_init);
370-
371-
static void __exit ssbi_exit(void)
372-
{
373-
platform_driver_unregister(&ssbi_driver);
374-
}
375-
module_exit(ssbi_exit)
328+
module_platform_driver(ssbi_driver);
376329

377330
MODULE_LICENSE("GPL v2");
378331
MODULE_VERSION("1.0");

0 commit comments

Comments
 (0)