aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorJonghwa Lee <jonghwa3.lee@samsung.com>2013-10-24 22:47:31 -0400
committerAnton Vorontsov <anton@enomsg.org>2013-10-25 19:28:54 -0400
commit883c10a9dd8099e7519cdc43b75ac4066a6ae98d (patch)
tree13263bc1f91872c2df7e40574ea72d4001c184c5 /drivers/power
parent3ed5cd79b82e9a055e0df3275eeb471ea0f1e2d7 (diff)
charger-manager : Replace kzalloc to devm_kzalloc and remove uneccessary code
Use devm function for dynamic memory allocation. Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com> Signed-off-by: Myungjoo Ham <myungjoo.ham@samsung.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/charger-manager.c85
1 files changed, 27 insertions, 58 deletions
diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index e30e847600bb..7287c0efd6bf 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -1378,7 +1378,8 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
1378 charger = &desc->charger_regulators[i]; 1378 charger = &desc->charger_regulators[i];
1379 1379
1380 snprintf(buf, 10, "charger.%d", i); 1380 snprintf(buf, 10, "charger.%d", i);
1381 str = kzalloc(sizeof(char) * (strlen(buf) + 1), GFP_KERNEL); 1381 str = devm_kzalloc(cm->dev,
1382 sizeof(char) * (strlen(buf) + 1), GFP_KERNEL);
1382 if (!str) { 1383 if (!str) {
1383 ret = -ENOMEM; 1384 ret = -ENOMEM;
1384 goto err; 1385 goto err;
@@ -1452,30 +1453,23 @@ static int charger_manager_probe(struct platform_device *pdev)
1452 rtc_dev = NULL; 1453 rtc_dev = NULL;
1453 dev_err(&pdev->dev, "Cannot get RTC %s\n", 1454 dev_err(&pdev->dev, "Cannot get RTC %s\n",
1454 g_desc->rtc_name); 1455 g_desc->rtc_name);
1455 ret = -ENODEV; 1456 return -ENODEV;
1456 goto err_alloc;
1457 } 1457 }
1458 } 1458 }
1459 1459
1460 if (!desc) { 1460 if (!desc) {
1461 dev_err(&pdev->dev, "No platform data (desc) found\n"); 1461 dev_err(&pdev->dev, "No platform data (desc) found\n");
1462 ret = -ENODEV; 1462 return -ENODEV;
1463 goto err_alloc;
1464 } 1463 }
1465 1464
1466 cm = kzalloc(sizeof(struct charger_manager), GFP_KERNEL); 1465 cm = devm_kzalloc(&pdev->dev,
1467 if (!cm) { 1466 sizeof(struct charger_manager), GFP_KERNEL);
1468 ret = -ENOMEM; 1467 if (!cm)
1469 goto err_alloc; 1468 return -ENOMEM;
1470 }
1471 1469
1472 /* Basic Values. Unspecified are Null or 0 */ 1470 /* Basic Values. Unspecified are Null or 0 */
1473 cm->dev = &pdev->dev; 1471 cm->dev = &pdev->dev;
1474 cm->desc = kmemdup(desc, sizeof(struct charger_desc), GFP_KERNEL); 1472 cm->desc = desc;
1475 if (!cm->desc) {
1476 ret = -ENOMEM;
1477 goto err_alloc_desc;
1478 }
1479 cm->last_temp_mC = INT_MIN; /* denotes "unmeasured, yet" */ 1473 cm->last_temp_mC = INT_MIN; /* denotes "unmeasured, yet" */
1480 1474
1481 /* 1475 /*
@@ -1498,27 +1492,23 @@ static int charger_manager_probe(struct platform_device *pdev)
1498 } 1492 }
1499 1493
1500 if (!desc->charger_regulators || desc->num_charger_regulators < 1) { 1494 if (!desc->charger_regulators || desc->num_charger_regulators < 1) {
1501 ret = -EINVAL;
1502 dev_err(&pdev->dev, "charger_regulators undefined\n"); 1495 dev_err(&pdev->dev, "charger_regulators undefined\n");
1503 goto err_no_charger; 1496 return -EINVAL;
1504 } 1497 }
1505 1498
1506 if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) { 1499 if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) {
1507 dev_err(&pdev->dev, "No power supply defined\n"); 1500 dev_err(&pdev->dev, "No power supply defined\n");
1508 ret = -EINVAL; 1501 return -EINVAL;
1509 goto err_no_charger_stat;
1510 } 1502 }
1511 1503
1512 /* Counting index only */ 1504 /* Counting index only */
1513 while (desc->psy_charger_stat[i]) 1505 while (desc->psy_charger_stat[i])
1514 i++; 1506 i++;
1515 1507
1516 cm->charger_stat = kzalloc(sizeof(struct power_supply *) * (i + 1), 1508 cm->charger_stat = devm_kzalloc(&pdev->dev,
1517 GFP_KERNEL); 1509 sizeof(struct power_supply *) * i, GFP_KERNEL);
1518 if (!cm->charger_stat) { 1510 if (!cm->charger_stat)
1519 ret = -ENOMEM; 1511 return -ENOMEM;
1520 goto err_no_charger_stat;
1521 }
1522 1512
1523 for (i = 0; desc->psy_charger_stat[i]; i++) { 1513 for (i = 0; desc->psy_charger_stat[i]; i++) {
1524 cm->charger_stat[i] = power_supply_get_by_name( 1514 cm->charger_stat[i] = power_supply_get_by_name(
@@ -1526,8 +1516,7 @@ static int charger_manager_probe(struct platform_device *pdev)
1526 if (!cm->charger_stat[i]) { 1516 if (!cm->charger_stat[i]) {
1527 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", 1517 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
1528 desc->psy_charger_stat[i]); 1518 desc->psy_charger_stat[i]);
1529 ret = -ENODEV; 1519 return -ENODEV;
1530 goto err_chg_stat;
1531 } 1520 }
1532 } 1521 }
1533 1522
@@ -1535,21 +1524,18 @@ static int charger_manager_probe(struct platform_device *pdev)
1535 if (!cm->fuel_gauge) { 1524 if (!cm->fuel_gauge) {
1536 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", 1525 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
1537 desc->psy_fuel_gauge); 1526 desc->psy_fuel_gauge);
1538 ret = -ENODEV; 1527 return -ENODEV;
1539 goto err_chg_stat;
1540 } 1528 }
1541 1529
1542 if (desc->polling_interval_ms == 0 || 1530 if (desc->polling_interval_ms == 0 ||
1543 msecs_to_jiffies(desc->polling_interval_ms) <= CM_JIFFIES_SMALL) { 1531 msecs_to_jiffies(desc->polling_interval_ms) <= CM_JIFFIES_SMALL) {
1544 dev_err(&pdev->dev, "polling_interval_ms is too small\n"); 1532 dev_err(&pdev->dev, "polling_interval_ms is too small\n");
1545 ret = -EINVAL; 1533 return -EINVAL;
1546 goto err_chg_stat;
1547 } 1534 }
1548 1535
1549 if (!desc->temperature_out_of_range) { 1536 if (!desc->temperature_out_of_range) {
1550 dev_err(&pdev->dev, "there is no temperature_out_of_range\n"); 1537 dev_err(&pdev->dev, "there is no temperature_out_of_range\n");
1551 ret = -EINVAL; 1538 return -EINVAL;
1552 goto err_chg_stat;
1553 } 1539 }
1554 1540
1555 if (!desc->charging_max_duration_ms || 1541 if (!desc->charging_max_duration_ms ||
@@ -1570,14 +1556,13 @@ static int charger_manager_probe(struct platform_device *pdev)
1570 cm->charger_psy.name = cm->psy_name_buf; 1556 cm->charger_psy.name = cm->psy_name_buf;
1571 1557
1572 /* Allocate for psy properties because they may vary */ 1558 /* Allocate for psy properties because they may vary */
1573 cm->charger_psy.properties = kzalloc(sizeof(enum power_supply_property) 1559 cm->charger_psy.properties = devm_kzalloc(&pdev->dev,
1560 sizeof(enum power_supply_property)
1574 * (ARRAY_SIZE(default_charger_props) + 1561 * (ARRAY_SIZE(default_charger_props) +
1575 NUM_CHARGER_PSY_OPTIONAL), 1562 NUM_CHARGER_PSY_OPTIONAL), GFP_KERNEL);
1576 GFP_KERNEL); 1563 if (!cm->charger_psy.properties)
1577 if (!cm->charger_psy.properties) { 1564 return -ENOMEM;
1578 ret = -ENOMEM; 1565
1579 goto err_chg_stat;
1580 }
1581 memcpy(cm->charger_psy.properties, default_charger_props, 1566 memcpy(cm->charger_psy.properties, default_charger_props,
1582 sizeof(enum power_supply_property) * 1567 sizeof(enum power_supply_property) *
1583 ARRAY_SIZE(default_charger_props)); 1568 ARRAY_SIZE(default_charger_props));
@@ -1614,7 +1599,7 @@ static int charger_manager_probe(struct platform_device *pdev)
1614 if (ret) { 1599 if (ret) {
1615 dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n", 1600 dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
1616 cm->charger_psy.name); 1601 cm->charger_psy.name);
1617 goto err_register; 1602 return ret;
1618 } 1603 }
1619 1604
1620 /* Register extcon device for charger cable */ 1605 /* Register extcon device for charger cable */
@@ -1655,8 +1640,6 @@ err_reg_sysfs:
1655 charger = &desc->charger_regulators[i]; 1640 charger = &desc->charger_regulators[i];
1656 sysfs_remove_group(&cm->charger_psy.dev->kobj, 1641 sysfs_remove_group(&cm->charger_psy.dev->kobj,
1657 &charger->attr_g); 1642 &charger->attr_g);
1658
1659 kfree(charger->attr_g.name);
1660 } 1643 }
1661err_reg_extcon: 1644err_reg_extcon:
1662 for (i = 0; i < desc->num_charger_regulators; i++) { 1645 for (i = 0; i < desc->num_charger_regulators; i++) {
@@ -1674,16 +1657,7 @@ err_reg_extcon:
1674 } 1657 }
1675 1658
1676 power_supply_unregister(&cm->charger_psy); 1659 power_supply_unregister(&cm->charger_psy);
1677err_register: 1660
1678 kfree(cm->charger_psy.properties);
1679err_chg_stat:
1680 kfree(cm->charger_stat);
1681err_no_charger_stat:
1682err_no_charger:
1683 kfree(cm->desc);
1684err_alloc_desc:
1685 kfree(cm);
1686err_alloc:
1687 return ret; 1661 return ret;
1688} 1662}
1689 1663
@@ -1718,11 +1692,6 @@ static int charger_manager_remove(struct platform_device *pdev)
1718 1692
1719 try_charger_enable(cm, false); 1693 try_charger_enable(cm, false);
1720 1694
1721 kfree(cm->charger_psy.properties);
1722 kfree(cm->charger_stat);
1723 kfree(cm->desc);
1724 kfree(cm);
1725
1726 return 0; 1695 return 0;
1727} 1696}
1728 1697