aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNishanth Menon <nm@ti.com>2016-05-05 20:29:51 -0400
committerMark Brown <broonie@kernel.org>2016-05-06 13:15:18 -0400
commit7f091e53c9efc52b2b3a03a8a1d479a47956fecd (patch)
tree54827945addf98d7688d14e09ca1ddcd0762cba7
parent1b42443db670dde5e3cb4261f77b29010b163fc6 (diff)
regulator: tps65917/palmas: Handle possible memory allocation failure
Stop the palmas regulator driver from imagining that the allocations will always succeed. Since regulator dt nodes are optional in nature and can be described in downstream drivers via platform data, continue to maintain code flow as prior when of node is not found. Signed-off-by: Nishanth Menon <nm@ti.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/regulator/palmas-regulator.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 3b9206224cd1..faa389be7ca3 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -1467,10 +1467,10 @@ static struct palmas_pmic_driver_data tps65917_ddata = {
1467 .ldo_register = tps65917_ldo_registration, 1467 .ldo_register = tps65917_ldo_registration,
1468}; 1468};
1469 1469
1470static void palmas_dt_to_pdata(struct device *dev, 1470static int palmas_dt_to_pdata(struct device *dev,
1471 struct device_node *node, 1471 struct device_node *node,
1472 struct palmas_pmic_platform_data *pdata, 1472 struct palmas_pmic_platform_data *pdata,
1473 struct palmas_pmic_driver_data *ddata) 1473 struct palmas_pmic_driver_data *ddata)
1474{ 1474{
1475 struct device_node *regulators; 1475 struct device_node *regulators;
1476 u32 prop; 1476 u32 prop;
@@ -1479,7 +1479,7 @@ static void palmas_dt_to_pdata(struct device *dev,
1479 regulators = of_get_child_by_name(node, "regulators"); 1479 regulators = of_get_child_by_name(node, "regulators");
1480 if (!regulators) { 1480 if (!regulators) {
1481 dev_info(dev, "regulator node not found\n"); 1481 dev_info(dev, "regulator node not found\n");
1482 return; 1482 return 0;
1483 } 1483 }
1484 1484
1485 ret = of_regulator_match(dev, regulators, ddata->palmas_matches, 1485 ret = of_regulator_match(dev, regulators, ddata->palmas_matches,
@@ -1487,7 +1487,7 @@ static void palmas_dt_to_pdata(struct device *dev,
1487 of_node_put(regulators); 1487 of_node_put(regulators);
1488 if (ret < 0) { 1488 if (ret < 0) {
1489 dev_err(dev, "Error parsing regulator init data: %d\n", ret); 1489 dev_err(dev, "Error parsing regulator init data: %d\n", ret);
1490 return; 1490 return 0;
1491 } 1491 }
1492 1492
1493 for (idx = 0; idx < ddata->max_reg; idx++) { 1493 for (idx = 0; idx < ddata->max_reg; idx++) {
@@ -1500,6 +1500,9 @@ static void palmas_dt_to_pdata(struct device *dev,
1500 continue; 1500 continue;
1501 1501
1502 rinit = devm_kzalloc(dev, sizeof(*rinit), GFP_KERNEL); 1502 rinit = devm_kzalloc(dev, sizeof(*rinit), GFP_KERNEL);
1503 if (!rinit)
1504 return -ENOMEM;
1505
1503 pdata->reg_data[idx] = match->init_data; 1506 pdata->reg_data[idx] = match->init_data;
1504 pdata->reg_init[idx] = rinit; 1507 pdata->reg_init[idx] = rinit;
1505 1508
@@ -1552,6 +1555,8 @@ static void palmas_dt_to_pdata(struct device *dev,
1552 } 1555 }
1553 1556
1554 pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator"); 1557 pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator");
1558
1559 return 0;
1555} 1560}
1556 1561
1557static const struct of_device_id of_palmas_match_tbl[] = { 1562static const struct of_device_id of_palmas_match_tbl[] = {
@@ -1633,7 +1638,9 @@ static int palmas_regulators_probe(struct platform_device *pdev)
1633 platform_set_drvdata(pdev, pmic); 1638 platform_set_drvdata(pdev, pmic);
1634 pmic->palmas->pmic_ddata = driver_data; 1639 pmic->palmas->pmic_ddata = driver_data;
1635 1640
1636 palmas_dt_to_pdata(&pdev->dev, node, pdata, driver_data); 1641 ret = palmas_dt_to_pdata(&pdev->dev, node, pdata, driver_data);
1642 if (ret)
1643 return ret;
1637 1644
1638 ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg); 1645 ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg);
1639 if (ret) 1646 if (ret)