aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2012-11-05 10:10:35 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2012-11-11 17:35:04 -0500
commit8c4203cb5814f53169dc4ff084a65dcf509b6f60 (patch)
treeaea94f5c585274a4a5aa8813c39f7a770e35cd9c
parent84e6de813b2d1bdb127943d3c8edf1c1afaa90da (diff)
mfd: ab8500-core: Use devm_* memory/IRQ and allocation/free routines
It is better to use devm_* calls, as they allow for easier and more automatic clean-up. Resources are device allocated, so when a device is freed, so are all associated resources. Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
-rw-r--r--drivers/mfd/ab8500-core.c62
1 files changed, 24 insertions, 38 deletions
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index e7197fe7059a..2a69dc2c1f84 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -1233,7 +1233,7 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1233 int i; 1233 int i;
1234 u8 value; 1234 u8 value;
1235 1235
1236 ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL); 1236 ab8500 = devm_kzalloc(&pdev->dev, sizeof *ab8500, GFP_KERNEL);
1237 if (!ab8500) 1237 if (!ab8500)
1238 return -ENOMEM; 1238 return -ENOMEM;
1239 1239
@@ -1243,10 +1243,8 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1243 ab8500->dev = &pdev->dev; 1243 ab8500->dev = &pdev->dev;
1244 1244
1245 resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1245 resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1246 if (!resource) { 1246 if (!resource)
1247 ret = -ENODEV; 1247 return -ENODEV;
1248 goto out_free_ab8500;
1249 }
1250 1248
1251 ab8500->irq = resource->start; 1249 ab8500->irq = resource->start;
1252 1250
@@ -1269,7 +1267,7 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1269 ret = get_register_interruptible(ab8500, AB8500_MISC, 1267 ret = get_register_interruptible(ab8500, AB8500_MISC,
1270 AB8500_IC_NAME_REG, &value); 1268 AB8500_IC_NAME_REG, &value);
1271 if (ret < 0) 1269 if (ret < 0)
1272 goto out_free_ab8500; 1270 return ret;
1273 1271
1274 ab8500->version = value; 1272 ab8500->version = value;
1275 } 1273 }
@@ -1277,7 +1275,7 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1277 ret = get_register_interruptible(ab8500, AB8500_MISC, 1275 ret = get_register_interruptible(ab8500, AB8500_MISC,
1278 AB8500_REV_REG, &value); 1276 AB8500_REV_REG, &value);
1279 if (ret < 0) 1277 if (ret < 0)
1280 goto out_free_ab8500; 1278 return ret;
1281 1279
1282 ab8500->chip_id = value; 1280 ab8500->chip_id = value;
1283 1281
@@ -1294,14 +1292,13 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1294 ab8500->mask_size = AB8500_NUM_IRQ_REGS; 1292 ab8500->mask_size = AB8500_NUM_IRQ_REGS;
1295 ab8500->irq_reg_offset = ab8500_irq_regoffset; 1293 ab8500->irq_reg_offset = ab8500_irq_regoffset;
1296 } 1294 }
1297 ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL); 1295 ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL);
1298 if (!ab8500->mask) 1296 if (!ab8500->mask)
1299 return -ENOMEM; 1297 return -ENOMEM;
1300 ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL); 1298 ab8500->oldmask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL);
1301 if (!ab8500->oldmask) { 1299 if (!ab8500->oldmask)
1302 ret = -ENOMEM; 1300 return -ENOMEM;
1303 goto out_freemask; 1301
1304 }
1305 /* 1302 /*
1306 * ab8500 has switched off due to (SWITCH_OFF_STATUS): 1303 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
1307 * 0x01 Swoff bit programming 1304 * 0x01 Swoff bit programming
@@ -1355,37 +1352,37 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1355 1352
1356 ret = abx500_register_ops(ab8500->dev, &ab8500_ops); 1353 ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
1357 if (ret) 1354 if (ret)
1358 goto out_freeoldmask; 1355 return ret;
1359 1356
1360 for (i = 0; i < ab8500->mask_size; i++) 1357 for (i = 0; i < ab8500->mask_size; i++)
1361 ab8500->mask[i] = ab8500->oldmask[i] = 0xff; 1358 ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
1362 1359
1363 ret = ab8500_irq_init(ab8500, np); 1360 ret = ab8500_irq_init(ab8500, np);
1364 if (ret) 1361 if (ret)
1365 goto out_freeoldmask; 1362 return ret;
1366 1363
1367 /* Activate this feature only in ab9540 */ 1364 /* Activate this feature only in ab9540 */
1368 /* till tests are done on ab8500 1p2 or later*/ 1365 /* till tests are done on ab8500 1p2 or later*/
1369 if (is_ab9540(ab8500)) { 1366 if (is_ab9540(ab8500)) {
1370 ret = request_threaded_irq(ab8500->irq, NULL, 1367 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL,
1371 ab8500_hierarchical_irq, 1368 ab8500_hierarchical_irq,
1372 IRQF_ONESHOT | IRQF_NO_SUSPEND, 1369 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1373 "ab8500", ab8500); 1370 "ab8500", ab8500);
1374 } 1371 }
1375 else { 1372 else {
1376 ret = request_threaded_irq(ab8500->irq, NULL, 1373 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL,
1377 ab8500_irq, 1374 ab8500_irq,
1378 IRQF_ONESHOT | IRQF_NO_SUSPEND, 1375 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1379 "ab8500", ab8500); 1376 "ab8500", ab8500);
1380 if (ret) 1377 if (ret)
1381 goto out_freeoldmask; 1378 return ret;
1382 } 1379 }
1383 1380
1384 ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs, 1381 ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs,
1385 ARRAY_SIZE(abx500_common_devs), NULL, 1382 ARRAY_SIZE(abx500_common_devs), NULL,
1386 ab8500->irq_base, ab8500->domain); 1383 ab8500->irq_base, ab8500->domain);
1387 if (ret) 1384 if (ret)
1388 goto out_freeirq; 1385 return ret;
1389 1386
1390 if (is_ab9540(ab8500)) 1387 if (is_ab9540(ab8500))
1391 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, 1388 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
@@ -1396,14 +1393,14 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1396 ARRAY_SIZE(ab8500_devs), NULL, 1393 ARRAY_SIZE(ab8500_devs), NULL,
1397 ab8500->irq_base, ab8500->domain); 1394 ab8500->irq_base, ab8500->domain);
1398 if (ret) 1395 if (ret)
1399 goto out_freeirq; 1396 return ret;
1400 1397
1401 if (is_ab9540(ab8500) || is_ab8505(ab8500)) 1398 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1402 ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs, 1399 ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs,
1403 ARRAY_SIZE(ab9540_ab8505_devs), NULL, 1400 ARRAY_SIZE(ab9540_ab8505_devs), NULL,
1404 ab8500->irq_base, ab8500->domain); 1401 ab8500->irq_base, ab8500->domain);
1405 if (ret) 1402 if (ret)
1406 goto out_freeirq; 1403 return ret;
1407 1404
1408 if (!no_bm) { 1405 if (!no_bm) {
1409 /* Add battery management devices */ 1406 /* Add battery management devices */
@@ -1424,17 +1421,6 @@ static int __devinit ab8500_probe(struct platform_device *pdev)
1424 dev_err(ab8500->dev, "error creating sysfs entries\n"); 1421 dev_err(ab8500->dev, "error creating sysfs entries\n");
1425 1422
1426 return ret; 1423 return ret;
1427
1428out_freeirq:
1429 free_irq(ab8500->irq, ab8500);
1430out_freeoldmask:
1431 kfree(ab8500->oldmask);
1432out_freemask:
1433 kfree(ab8500->mask);
1434out_free_ab8500:
1435 kfree(ab8500);
1436
1437 return ret;
1438} 1424}
1439 1425
1440static int __devexit ab8500_remove(struct platform_device *pdev) 1426static int __devexit ab8500_remove(struct platform_device *pdev)