Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Stephen Boyd and committed by
Samuel Ortiz
e5784388 6378c1e5

+11 -58
+11 -58
drivers/mfd/ssbi.c
··· 268 268 struct device_node *np = pdev->dev.of_node; 269 269 struct resource *mem_res; 270 270 struct ssbi *ssbi; 271 - int ret = 0; 272 271 const char *type; 273 272 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) 277 275 return -ENOMEM; 278 - } 279 276 280 277 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); 286 281 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 - } 293 282 platform_set_drvdata(pdev, ssbi); 294 283 295 284 type = of_get_property(np, "qcom,controller-type", NULL); 296 285 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; 300 288 } 301 289 dev_info(&pdev->dev, "SSBI controller type: '%s'\n", type); 302 290 if (strcmp(type, "ssbi") == 0) ··· 294 306 else if (strcmp(type, "pmic-arbiter") == 0) 295 307 ssbi->controller_type = MSM_SBI_CTRL_PMIC_ARBITER; 296 308 else { 297 - pr_err("Unknown qcom,controller-type\n"); 298 - ret = -EINVAL; 299 - goto err_ssbi_controller; 309 + dev_err(&pdev->dev, "Unknown qcom,controller-type\n"); 310 + return -EINVAL; 300 311 } 301 312 302 313 if (ssbi->controller_type == MSM_SBI_CTRL_PMIC_ARBITER) { ··· 308 321 309 322 spin_lock_init(&ssbi->lock); 310 323 311 - ret = of_platform_populate(np, NULL, NULL, &pdev->dev); 312 - if (ret) 313 - goto err_ssbi_controller; 314 - 315 - return 0; 316 - 317 - err_ssbi_controller: 318 - platform_set_drvdata(pdev, NULL); 319 - iounmap(ssbi->base); 320 - err_ioremap: 321 - err_get_mem_res: 322 - kfree(ssbi); 323 - return ret; 324 - } 325 - 326 - static int ssbi_remove(struct platform_device *pdev) 327 - { 328 - struct ssbi *ssbi = platform_get_drvdata(pdev); 329 - 330 - platform_set_drvdata(pdev, NULL); 331 - iounmap(ssbi->base); 332 - kfree(ssbi); 333 - return 0; 324 + return of_platform_populate(np, NULL, NULL, &pdev->dev); 334 325 } 335 326 336 327 static struct of_device_id ssbi_match_table[] = { ··· 319 354 320 355 static struct platform_driver ssbi_driver = { 321 356 .probe = ssbi_probe, 322 - .remove = ssbi_remove, 323 357 .driver = { 324 358 .name = "ssbi", 325 359 .owner = THIS_MODULE, 326 360 .of_match_table = ssbi_match_table, 327 361 }, 328 362 }; 329 - 330 - static int __init ssbi_init(void) 331 - { 332 - return platform_driver_register(&ssbi_driver); 333 - } 334 - module_init(ssbi_init); 335 - 336 - static void __exit ssbi_exit(void) 337 - { 338 - platform_driver_unregister(&ssbi_driver); 339 - } 340 - module_exit(ssbi_exit) 363 + module_platform_driver(ssbi_driver); 341 364 342 365 MODULE_LICENSE("GPL v2"); 343 366 MODULE_VERSION("1.0");