Commit 883c10a9 authored by Jonghwa Lee's avatar Jonghwa Lee Committed by Anton Vorontsov

charger-manager : Replace kzalloc to devm_kzalloc and remove uneccessary code

Use devm function for dynamic memory allocation.
Signed-off-by: default avatarJonghwa Lee <jonghwa3.lee@samsung.com>
Signed-off-by: default avatarMyungjoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: default avatarAnton Vorontsov <anton@enomsg.org>
parent 3ed5cd79
...@@ -1378,7 +1378,8 @@ static int charger_manager_register_sysfs(struct charger_manager *cm) ...@@ -1378,7 +1378,8 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
charger = &desc->charger_regulators[i]; charger = &desc->charger_regulators[i];
snprintf(buf, 10, "charger.%d", i); snprintf(buf, 10, "charger.%d", i);
str = kzalloc(sizeof(char) * (strlen(buf) + 1), GFP_KERNEL); str = devm_kzalloc(cm->dev,
sizeof(char) * (strlen(buf) + 1), GFP_KERNEL);
if (!str) { if (!str) {
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
...@@ -1452,30 +1453,23 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1452,30 +1453,23 @@ static int charger_manager_probe(struct platform_device *pdev)
rtc_dev = NULL; rtc_dev = NULL;
dev_err(&pdev->dev, "Cannot get RTC %s\n", dev_err(&pdev->dev, "Cannot get RTC %s\n",
g_desc->rtc_name); g_desc->rtc_name);
ret = -ENODEV; return -ENODEV;
goto err_alloc;
} }
} }
if (!desc) { if (!desc) {
dev_err(&pdev->dev, "No platform data (desc) found\n"); dev_err(&pdev->dev, "No platform data (desc) found\n");
ret = -ENODEV; return -ENODEV;
goto err_alloc;
} }
cm = kzalloc(sizeof(struct charger_manager), GFP_KERNEL); cm = devm_kzalloc(&pdev->dev,
if (!cm) { sizeof(struct charger_manager), GFP_KERNEL);
ret = -ENOMEM; if (!cm)
goto err_alloc; return -ENOMEM;
}
/* Basic Values. Unspecified are Null or 0 */ /* Basic Values. Unspecified are Null or 0 */
cm->dev = &pdev->dev; cm->dev = &pdev->dev;
cm->desc = kmemdup(desc, sizeof(struct charger_desc), GFP_KERNEL); cm->desc = desc;
if (!cm->desc) {
ret = -ENOMEM;
goto err_alloc_desc;
}
cm->last_temp_mC = INT_MIN; /* denotes "unmeasured, yet" */ cm->last_temp_mC = INT_MIN; /* denotes "unmeasured, yet" */
/* /*
...@@ -1498,27 +1492,23 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1498,27 +1492,23 @@ static int charger_manager_probe(struct platform_device *pdev)
} }
if (!desc->charger_regulators || desc->num_charger_regulators < 1) { if (!desc->charger_regulators || desc->num_charger_regulators < 1) {
ret = -EINVAL;
dev_err(&pdev->dev, "charger_regulators undefined\n"); dev_err(&pdev->dev, "charger_regulators undefined\n");
goto err_no_charger; return -EINVAL;
} }
if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) { if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) {
dev_err(&pdev->dev, "No power supply defined\n"); dev_err(&pdev->dev, "No power supply defined\n");
ret = -EINVAL; return -EINVAL;
goto err_no_charger_stat;
} }
/* Counting index only */ /* Counting index only */
while (desc->psy_charger_stat[i]) while (desc->psy_charger_stat[i])
i++; i++;
cm->charger_stat = kzalloc(sizeof(struct power_supply *) * (i + 1), cm->charger_stat = devm_kzalloc(&pdev->dev,
GFP_KERNEL); sizeof(struct power_supply *) * i, GFP_KERNEL);
if (!cm->charger_stat) { if (!cm->charger_stat)
ret = -ENOMEM; return -ENOMEM;
goto err_no_charger_stat;
}
for (i = 0; desc->psy_charger_stat[i]; i++) { for (i = 0; desc->psy_charger_stat[i]; i++) {
cm->charger_stat[i] = power_supply_get_by_name( cm->charger_stat[i] = power_supply_get_by_name(
...@@ -1526,8 +1516,7 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1526,8 +1516,7 @@ static int charger_manager_probe(struct platform_device *pdev)
if (!cm->charger_stat[i]) { if (!cm->charger_stat[i]) {
dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
desc->psy_charger_stat[i]); desc->psy_charger_stat[i]);
ret = -ENODEV; return -ENODEV;
goto err_chg_stat;
} }
} }
...@@ -1535,21 +1524,18 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1535,21 +1524,18 @@ static int charger_manager_probe(struct platform_device *pdev)
if (!cm->fuel_gauge) { if (!cm->fuel_gauge) {
dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
desc->psy_fuel_gauge); desc->psy_fuel_gauge);
ret = -ENODEV; return -ENODEV;
goto err_chg_stat;
} }
if (desc->polling_interval_ms == 0 || if (desc->polling_interval_ms == 0 ||
msecs_to_jiffies(desc->polling_interval_ms) <= CM_JIFFIES_SMALL) { msecs_to_jiffies(desc->polling_interval_ms) <= CM_JIFFIES_SMALL) {
dev_err(&pdev->dev, "polling_interval_ms is too small\n"); dev_err(&pdev->dev, "polling_interval_ms is too small\n");
ret = -EINVAL; return -EINVAL;
goto err_chg_stat;
} }
if (!desc->temperature_out_of_range) { if (!desc->temperature_out_of_range) {
dev_err(&pdev->dev, "there is no temperature_out_of_range\n"); dev_err(&pdev->dev, "there is no temperature_out_of_range\n");
ret = -EINVAL; return -EINVAL;
goto err_chg_stat;
} }
if (!desc->charging_max_duration_ms || if (!desc->charging_max_duration_ms ||
...@@ -1570,14 +1556,13 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1570,14 +1556,13 @@ static int charger_manager_probe(struct platform_device *pdev)
cm->charger_psy.name = cm->psy_name_buf; cm->charger_psy.name = cm->psy_name_buf;
/* Allocate for psy properties because they may vary */ /* Allocate for psy properties because they may vary */
cm->charger_psy.properties = kzalloc(sizeof(enum power_supply_property) cm->charger_psy.properties = devm_kzalloc(&pdev->dev,
sizeof(enum power_supply_property)
* (ARRAY_SIZE(default_charger_props) + * (ARRAY_SIZE(default_charger_props) +
NUM_CHARGER_PSY_OPTIONAL), NUM_CHARGER_PSY_OPTIONAL), GFP_KERNEL);
GFP_KERNEL); if (!cm->charger_psy.properties)
if (!cm->charger_psy.properties) { return -ENOMEM;
ret = -ENOMEM;
goto err_chg_stat;
}
memcpy(cm->charger_psy.properties, default_charger_props, memcpy(cm->charger_psy.properties, default_charger_props,
sizeof(enum power_supply_property) * sizeof(enum power_supply_property) *
ARRAY_SIZE(default_charger_props)); ARRAY_SIZE(default_charger_props));
...@@ -1614,7 +1599,7 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1614,7 +1599,7 @@ static int charger_manager_probe(struct platform_device *pdev)
if (ret) { if (ret) {
dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n", dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
cm->charger_psy.name); cm->charger_psy.name);
goto err_register; return ret;
} }
/* Register extcon device for charger cable */ /* Register extcon device for charger cable */
...@@ -1655,8 +1640,6 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1655,8 +1640,6 @@ static int charger_manager_probe(struct platform_device *pdev)
charger = &desc->charger_regulators[i]; charger = &desc->charger_regulators[i];
sysfs_remove_group(&cm->charger_psy.dev->kobj, sysfs_remove_group(&cm->charger_psy.dev->kobj,
&charger->attr_g); &charger->attr_g);
kfree(charger->attr_g.name);
} }
err_reg_extcon: err_reg_extcon:
for (i = 0; i < desc->num_charger_regulators; i++) { for (i = 0; i < desc->num_charger_regulators; i++) {
...@@ -1674,16 +1657,7 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1674,16 +1657,7 @@ static int charger_manager_probe(struct platform_device *pdev)
} }
power_supply_unregister(&cm->charger_psy); power_supply_unregister(&cm->charger_psy);
err_register:
kfree(cm->charger_psy.properties);
err_chg_stat:
kfree(cm->charger_stat);
err_no_charger_stat:
err_no_charger:
kfree(cm->desc);
err_alloc_desc:
kfree(cm);
err_alloc:
return ret; return ret;
} }
...@@ -1718,11 +1692,6 @@ static int charger_manager_remove(struct platform_device *pdev) ...@@ -1718,11 +1692,6 @@ static int charger_manager_remove(struct platform_device *pdev)
try_charger_enable(cm, false); try_charger_enable(cm, false);
kfree(cm->charger_psy.properties);
kfree(cm->charger_stat);
kfree(cm->desc);
kfree(cm);
return 0; return 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