aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2017-01-22 23:41:43 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-01-30 03:22:21 -0500
commitfa30184d192ec78d443cf6d3abc37d9eb3b9253e (patch)
tree1f336b6e9ec46282ea3967775ced17b3533fa55f
parentf067a982cefa8df5642212bb0c7e25974831f781 (diff)
PM / OPP: Return opp_table from dev_pm_opp_set_*() routines
Now that we have proper kernel reference infrastructure in place for OPP tables, use it to guarantee that the OPP table isn't freed while being used by the callers of dev_pm_opp_set_*() APIs. Make them all return the pointer to the OPP table after taking its reference and put the reference back with dev_pm_opp_put_*() APIs. Now that the OPP table wouldn't get freed while these routines are executing after dev_pm_opp_get_opp_table() is called, there is no need to take opp_table_lock. Drop them as well. Remove the rcu specific comments from these routines as they aren't relevant anymore. Note that prototypes of dev_pm_opp_{set|put}_regulators() were already updated by another patch. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/base/power/opp/core.c243
-rw-r--r--drivers/cpufreq/sti-cpufreq.c13
-rw-r--r--include/linux/pm_opp.h35
3 files changed, 74 insertions, 217 deletions
diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index ccc0d8913fd0..1af349ab630e 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -974,18 +974,6 @@ static void _remove_opp_table(struct opp_table *opp_table)
974 if (!list_empty(&opp_table->opp_list)) 974 if (!list_empty(&opp_table->opp_list))
975 return; 975 return;
976 976
977 if (opp_table->supported_hw)
978 return;
979
980 if (opp_table->prop_name)
981 return;
982
983 if (opp_table->regulators)
984 return;
985
986 if (opp_table->set_opp)
987 return;
988
989 dev_pm_opp_put_opp_table_unlocked(opp_table); 977 dev_pm_opp_put_opp_table_unlocked(opp_table);
990} 978}
991 979
@@ -1277,27 +1265,16 @@ free_opp:
1277 * specify the hierarchy of versions it supports. OPP layer will then enable 1265 * specify the hierarchy of versions it supports. OPP layer will then enable
1278 * OPPs, which are available for those versions, based on its 'opp-supported-hw' 1266 * OPPs, which are available for those versions, based on its 'opp-supported-hw'
1279 * property. 1267 * property.
1280 *
1281 * Locking: The internal opp_table and opp structures are RCU protected.
1282 * Hence this function internally uses RCU updater strategy with mutex locks
1283 * to keep the integrity of the internal data structures. Callers should ensure
1284 * that this function is *NOT* called under RCU protection or in contexts where
1285 * mutex cannot be locked.
1286 */ 1268 */
1287int dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, 1269struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
1288 unsigned int count) 1270 const u32 *versions, unsigned int count)
1289{ 1271{
1290 struct opp_table *opp_table; 1272 struct opp_table *opp_table;
1291 int ret = 0; 1273 int ret;
1292
1293 /* Hold our table modification lock here */
1294 mutex_lock(&opp_table_lock);
1295 1274
1296 opp_table = _add_opp_table(dev); 1275 opp_table = dev_pm_opp_get_opp_table(dev);
1297 if (!opp_table) { 1276 if (!opp_table)
1298 ret = -ENOMEM; 1277 return ERR_PTR(-ENOMEM);
1299 goto unlock;
1300 }
1301 1278
1302 /* Make sure there are no concurrent readers while updating opp_table */ 1279 /* Make sure there are no concurrent readers while updating opp_table */
1303 WARN_ON(!list_empty(&opp_table->opp_list)); 1280 WARN_ON(!list_empty(&opp_table->opp_list));
@@ -1318,65 +1295,40 @@ int dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions,
1318 } 1295 }
1319 1296
1320 opp_table->supported_hw_count = count; 1297 opp_table->supported_hw_count = count;
1321 mutex_unlock(&opp_table_lock); 1298
1322 return 0; 1299 return opp_table;
1323 1300
1324err: 1301err:
1325 _remove_opp_table(opp_table); 1302 dev_pm_opp_put_opp_table(opp_table);
1326unlock:
1327 mutex_unlock(&opp_table_lock);
1328 1303
1329 return ret; 1304 return ERR_PTR(ret);
1330} 1305}
1331EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw); 1306EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw);
1332 1307
1333/** 1308/**
1334 * dev_pm_opp_put_supported_hw() - Releases resources blocked for supported hw 1309 * dev_pm_opp_put_supported_hw() - Releases resources blocked for supported hw
1335 * @dev: Device for which supported-hw has to be put. 1310 * @opp_table: OPP table returned by dev_pm_opp_set_supported_hw().
1336 * 1311 *
1337 * This is required only for the V2 bindings, and is called for a matching 1312 * This is required only for the V2 bindings, and is called for a matching
1338 * dev_pm_opp_set_supported_hw(). Until this is called, the opp_table structure 1313 * dev_pm_opp_set_supported_hw(). Until this is called, the opp_table structure
1339 * will not be freed. 1314 * will not be freed.
1340 *
1341 * Locking: The internal opp_table and opp structures are RCU protected.
1342 * Hence this function internally uses RCU updater strategy with mutex locks
1343 * to keep the integrity of the internal data structures. Callers should ensure
1344 * that this function is *NOT* called under RCU protection or in contexts where
1345 * mutex cannot be locked.
1346 */ 1315 */
1347void dev_pm_opp_put_supported_hw(struct device *dev) 1316void dev_pm_opp_put_supported_hw(struct opp_table *opp_table)
1348{ 1317{
1349 struct opp_table *opp_table;
1350
1351 /* Hold our table modification lock here */
1352 mutex_lock(&opp_table_lock);
1353
1354 /* Check for existing table for 'dev' first */
1355 opp_table = _find_opp_table(dev);
1356 if (IS_ERR(opp_table)) {
1357 dev_err(dev, "Failed to find opp_table: %ld\n",
1358 PTR_ERR(opp_table));
1359 goto unlock;
1360 }
1361
1362 /* Make sure there are no concurrent readers while updating opp_table */ 1318 /* Make sure there are no concurrent readers while updating opp_table */
1363 WARN_ON(!list_empty(&opp_table->opp_list)); 1319 WARN_ON(!list_empty(&opp_table->opp_list));
1364 1320
1365 if (!opp_table->supported_hw) { 1321 if (!opp_table->supported_hw) {
1366 dev_err(dev, "%s: Doesn't have supported hardware list\n", 1322 pr_err("%s: Doesn't have supported hardware list\n",
1367 __func__); 1323 __func__);
1368 goto unlock; 1324 return;
1369 } 1325 }
1370 1326
1371 kfree(opp_table->supported_hw); 1327 kfree(opp_table->supported_hw);
1372 opp_table->supported_hw = NULL; 1328 opp_table->supported_hw = NULL;
1373 opp_table->supported_hw_count = 0; 1329 opp_table->supported_hw_count = 0;
1374 1330
1375 /* Try freeing opp_table if this was the last blocking resource */ 1331 dev_pm_opp_put_opp_table(opp_table);
1376 _remove_opp_table(opp_table);
1377
1378unlock:
1379 mutex_unlock(&opp_table_lock);
1380} 1332}
1381EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw); 1333EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw);
1382 1334
@@ -1389,26 +1341,15 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw);
1389 * specify the extn to be used for certain property names. The properties to 1341 * specify the extn to be used for certain property names. The properties to
1390 * which the extension will apply are opp-microvolt and opp-microamp. OPP core 1342 * which the extension will apply are opp-microvolt and opp-microamp. OPP core
1391 * should postfix the property name with -<name> while looking for them. 1343 * should postfix the property name with -<name> while looking for them.
1392 *
1393 * Locking: The internal opp_table and opp structures are RCU protected.
1394 * Hence this function internally uses RCU updater strategy with mutex locks
1395 * to keep the integrity of the internal data structures. Callers should ensure
1396 * that this function is *NOT* called under RCU protection or in contexts where
1397 * mutex cannot be locked.
1398 */ 1344 */
1399int dev_pm_opp_set_prop_name(struct device *dev, const char *name) 1345struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
1400{ 1346{
1401 struct opp_table *opp_table; 1347 struct opp_table *opp_table;
1402 int ret = 0; 1348 int ret;
1403
1404 /* Hold our table modification lock here */
1405 mutex_lock(&opp_table_lock);
1406 1349
1407 opp_table = _add_opp_table(dev); 1350 opp_table = dev_pm_opp_get_opp_table(dev);
1408 if (!opp_table) { 1351 if (!opp_table)
1409 ret = -ENOMEM; 1352 return ERR_PTR(-ENOMEM);
1410 goto unlock;
1411 }
1412 1353
1413 /* Make sure there are no concurrent readers while updating opp_table */ 1354 /* Make sure there are no concurrent readers while updating opp_table */
1414 WARN_ON(!list_empty(&opp_table->opp_list)); 1355 WARN_ON(!list_empty(&opp_table->opp_list));
@@ -1427,63 +1368,37 @@ int dev_pm_opp_set_prop_name(struct device *dev, const char *name)
1427 goto err; 1368 goto err;
1428 } 1369 }
1429 1370
1430 mutex_unlock(&opp_table_lock); 1371 return opp_table;
1431 return 0;
1432 1372
1433err: 1373err:
1434 _remove_opp_table(opp_table); 1374 dev_pm_opp_put_opp_table(opp_table);
1435unlock:
1436 mutex_unlock(&opp_table_lock);
1437 1375
1438 return ret; 1376 return ERR_PTR(ret);
1439} 1377}
1440EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name); 1378EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name);
1441 1379
1442/** 1380/**
1443 * dev_pm_opp_put_prop_name() - Releases resources blocked for prop-name 1381 * dev_pm_opp_put_prop_name() - Releases resources blocked for prop-name
1444 * @dev: Device for which the prop-name has to be put. 1382 * @opp_table: OPP table returned by dev_pm_opp_set_prop_name().
1445 * 1383 *
1446 * This is required only for the V2 bindings, and is called for a matching 1384 * This is required only for the V2 bindings, and is called for a matching
1447 * dev_pm_opp_set_prop_name(). Until this is called, the opp_table structure 1385 * dev_pm_opp_set_prop_name(). Until this is called, the opp_table structure
1448 * will not be freed. 1386 * will not be freed.
1449 *
1450 * Locking: The internal opp_table and opp structures are RCU protected.
1451 * Hence this function internally uses RCU updater strategy with mutex locks
1452 * to keep the integrity of the internal data structures. Callers should ensure
1453 * that this function is *NOT* called under RCU protection or in contexts where
1454 * mutex cannot be locked.
1455 */ 1387 */
1456void dev_pm_opp_put_prop_name(struct device *dev) 1388void dev_pm_opp_put_prop_name(struct opp_table *opp_table)
1457{ 1389{
1458 struct opp_table *opp_table;
1459
1460 /* Hold our table modification lock here */
1461 mutex_lock(&opp_table_lock);
1462
1463 /* Check for existing table for 'dev' first */
1464 opp_table = _find_opp_table(dev);
1465 if (IS_ERR(opp_table)) {
1466 dev_err(dev, "Failed to find opp_table: %ld\n",
1467 PTR_ERR(opp_table));
1468 goto unlock;
1469 }
1470
1471 /* Make sure there are no concurrent readers while updating opp_table */ 1390 /* Make sure there are no concurrent readers while updating opp_table */
1472 WARN_ON(!list_empty(&opp_table->opp_list)); 1391 WARN_ON(!list_empty(&opp_table->opp_list));
1473 1392
1474 if (!opp_table->prop_name) { 1393 if (!opp_table->prop_name) {
1475 dev_err(dev, "%s: Doesn't have a prop-name\n", __func__); 1394 pr_err("%s: Doesn't have a prop-name\n", __func__);
1476 goto unlock; 1395 return;
1477 } 1396 }
1478 1397
1479 kfree(opp_table->prop_name); 1398 kfree(opp_table->prop_name);
1480 opp_table->prop_name = NULL; 1399 opp_table->prop_name = NULL;
1481 1400
1482 /* Try freeing opp_table if this was the last blocking resource */ 1401 dev_pm_opp_put_opp_table(opp_table);
1483 _remove_opp_table(opp_table);
1484
1485unlock:
1486 mutex_unlock(&opp_table_lock);
1487} 1402}
1488EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name); 1403EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name);
1489 1404
@@ -1530,12 +1445,6 @@ static void _free_set_opp_data(struct opp_table *opp_table)
1530 * well. 1445 * well.
1531 * 1446 *
1532 * This must be called before any OPPs are initialized for the device. 1447 * This must be called before any OPPs are initialized for the device.
1533 *
1534 * Locking: The internal opp_table and opp structures are RCU protected.
1535 * Hence this function internally uses RCU updater strategy with mutex locks
1536 * to keep the integrity of the internal data structures. Callers should ensure
1537 * that this function is *NOT* called under RCU protection or in contexts where
1538 * mutex cannot be locked.
1539 */ 1448 */
1540struct opp_table *dev_pm_opp_set_regulators(struct device *dev, 1449struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
1541 const char * const names[], 1450 const char * const names[],
@@ -1545,13 +1454,9 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
1545 struct regulator *reg; 1454 struct regulator *reg;
1546 int ret, i; 1455 int ret, i;
1547 1456
1548 mutex_lock(&opp_table_lock); 1457 opp_table = dev_pm_opp_get_opp_table(dev);
1549 1458 if (!opp_table)
1550 opp_table = _add_opp_table(dev); 1459 return ERR_PTR(-ENOMEM);
1551 if (!opp_table) {
1552 ret = -ENOMEM;
1553 goto unlock;
1554 }
1555 1460
1556 /* This should be called before OPPs are initialized */ 1461 /* This should be called before OPPs are initialized */
1557 if (WARN_ON(!list_empty(&opp_table->opp_list))) { 1462 if (WARN_ON(!list_empty(&opp_table->opp_list))) {
@@ -1593,7 +1498,6 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
1593 if (ret) 1498 if (ret)
1594 goto free_regulators; 1499 goto free_regulators;
1595 1500
1596 mutex_unlock(&opp_table_lock);
1597 return opp_table; 1501 return opp_table;
1598 1502
1599free_regulators: 1503free_regulators:
@@ -1604,9 +1508,7 @@ free_regulators:
1604 opp_table->regulators = NULL; 1508 opp_table->regulators = NULL;
1605 opp_table->regulator_count = 0; 1509 opp_table->regulator_count = 0;
1606err: 1510err:
1607 _remove_opp_table(opp_table); 1511 dev_pm_opp_put_opp_table(opp_table);
1608unlock:
1609 mutex_unlock(&opp_table_lock);
1610 1512
1611 return ERR_PTR(ret); 1513 return ERR_PTR(ret);
1612} 1514}
@@ -1615,22 +1517,14 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_set_regulators);
1615/** 1517/**
1616 * dev_pm_opp_put_regulators() - Releases resources blocked for regulator 1518 * dev_pm_opp_put_regulators() - Releases resources blocked for regulator
1617 * @opp_table: OPP table returned from dev_pm_opp_set_regulators(). 1519 * @opp_table: OPP table returned from dev_pm_opp_set_regulators().
1618 *
1619 * Locking: The internal opp_table and opp structures are RCU protected.
1620 * Hence this function internally uses RCU updater strategy with mutex locks
1621 * to keep the integrity of the internal data structures. Callers should ensure
1622 * that this function is *NOT* called under RCU protection or in contexts where
1623 * mutex cannot be locked.
1624 */ 1520 */
1625void dev_pm_opp_put_regulators(struct opp_table *opp_table) 1521void dev_pm_opp_put_regulators(struct opp_table *opp_table)
1626{ 1522{
1627 int i; 1523 int i;
1628 1524
1629 mutex_lock(&opp_table_lock);
1630
1631 if (!opp_table->regulators) { 1525 if (!opp_table->regulators) {
1632 pr_err("%s: Doesn't have regulators set\n", __func__); 1526 pr_err("%s: Doesn't have regulators set\n", __func__);
1633 goto unlock; 1527 return;
1634 } 1528 }
1635 1529
1636 /* Make sure there are no concurrent readers while updating opp_table */ 1530 /* Make sure there are no concurrent readers while updating opp_table */
@@ -1645,11 +1539,7 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table)
1645 opp_table->regulators = NULL; 1539 opp_table->regulators = NULL;
1646 opp_table->regulator_count = 0; 1540 opp_table->regulator_count = 0;
1647 1541
1648 /* Try freeing opp_table if this was the last blocking resource */ 1542 dev_pm_opp_put_opp_table(opp_table);
1649 _remove_opp_table(opp_table);
1650
1651unlock:
1652 mutex_unlock(&opp_table_lock);
1653} 1543}
1654EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators); 1544EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators);
1655 1545
@@ -1662,29 +1552,19 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators);
1662 * regulators per device), instead of the generic OPP set rate helper. 1552 * regulators per device), instead of the generic OPP set rate helper.
1663 * 1553 *
1664 * This must be called before any OPPs are initialized for the device. 1554 * This must be called before any OPPs are initialized for the device.
1665 *
1666 * Locking: The internal opp_table and opp structures are RCU protected.
1667 * Hence this function internally uses RCU updater strategy with mutex locks
1668 * to keep the integrity of the internal data structures. Callers should ensure
1669 * that this function is *NOT* called under RCU protection or in contexts where
1670 * mutex cannot be locked.
1671 */ 1555 */
1672int dev_pm_opp_register_set_opp_helper(struct device *dev, 1556struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
1673 int (*set_opp)(struct dev_pm_set_opp_data *data)) 1557 int (*set_opp)(struct dev_pm_set_opp_data *data))
1674{ 1558{
1675 struct opp_table *opp_table; 1559 struct opp_table *opp_table;
1676 int ret; 1560 int ret;
1677 1561
1678 if (!set_opp) 1562 if (!set_opp)
1679 return -EINVAL; 1563 return ERR_PTR(-EINVAL);
1680
1681 mutex_lock(&opp_table_lock);
1682 1564
1683 opp_table = _add_opp_table(dev); 1565 opp_table = dev_pm_opp_get_opp_table(dev);
1684 if (!opp_table) { 1566 if (!opp_table)
1685 ret = -ENOMEM; 1567 return ERR_PTR(-ENOMEM);
1686 goto unlock;
1687 }
1688 1568
1689 /* This should be called before OPPs are initialized */ 1569 /* This should be called before OPPs are initialized */
1690 if (WARN_ON(!list_empty(&opp_table->opp_list))) { 1570 if (WARN_ON(!list_empty(&opp_table->opp_list))) {
@@ -1700,47 +1580,28 @@ int dev_pm_opp_register_set_opp_helper(struct device *dev,
1700 1580
1701 opp_table->set_opp = set_opp; 1581 opp_table->set_opp = set_opp;
1702 1582
1703 mutex_unlock(&opp_table_lock); 1583 return opp_table;
1704 return 0;
1705 1584
1706err: 1585err:
1707 _remove_opp_table(opp_table); 1586 dev_pm_opp_put_opp_table(opp_table);
1708unlock:
1709 mutex_unlock(&opp_table_lock);
1710 1587
1711 return ret; 1588 return ERR_PTR(ret);
1712} 1589}
1713EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper); 1590EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper);
1714 1591
1715/** 1592/**
1716 * dev_pm_opp_register_put_opp_helper() - Releases resources blocked for 1593 * dev_pm_opp_register_put_opp_helper() - Releases resources blocked for
1717 * set_opp helper 1594 * set_opp helper
1718 * @dev: Device for which custom set_opp helper has to be cleared. 1595 * @opp_table: OPP table returned from dev_pm_opp_register_set_opp_helper().
1719 * 1596 *
1720 * Locking: The internal opp_table and opp structures are RCU protected. 1597 * Release resources blocked for platform specific set_opp helper.
1721 * Hence this function internally uses RCU updater strategy with mutex locks
1722 * to keep the integrity of the internal data structures. Callers should ensure
1723 * that this function is *NOT* called under RCU protection or in contexts where
1724 * mutex cannot be locked.
1725 */ 1598 */
1726void dev_pm_opp_register_put_opp_helper(struct device *dev) 1599void dev_pm_opp_register_put_opp_helper(struct opp_table *opp_table)
1727{ 1600{
1728 struct opp_table *opp_table;
1729
1730 mutex_lock(&opp_table_lock);
1731
1732 /* Check for existing table for 'dev' first */
1733 opp_table = _find_opp_table(dev);
1734 if (IS_ERR(opp_table)) {
1735 dev_err(dev, "Failed to find opp_table: %ld\n",
1736 PTR_ERR(opp_table));
1737 goto unlock;
1738 }
1739
1740 if (!opp_table->set_opp) { 1601 if (!opp_table->set_opp) {
1741 dev_err(dev, "%s: Doesn't have custom set_opp helper set\n", 1602 pr_err("%s: Doesn't have custom set_opp helper set\n",
1742 __func__); 1603 __func__);
1743 goto unlock; 1604 return;
1744 } 1605 }
1745 1606
1746 /* Make sure there are no concurrent readers while updating opp_table */ 1607 /* Make sure there are no concurrent readers while updating opp_table */
@@ -1748,11 +1609,7 @@ void dev_pm_opp_register_put_opp_helper(struct device *dev)
1748 1609
1749 opp_table->set_opp = NULL; 1610 opp_table->set_opp = NULL;
1750 1611
1751 /* Try freeing opp_table if this was the last blocking resource */ 1612 dev_pm_opp_put_opp_table(opp_table);
1752 _remove_opp_table(opp_table);
1753
1754unlock:
1755 mutex_unlock(&opp_table_lock);
1756} 1613}
1757EXPORT_SYMBOL_GPL(dev_pm_opp_register_put_opp_helper); 1614EXPORT_SYMBOL_GPL(dev_pm_opp_register_put_opp_helper);
1758 1615
diff --git a/drivers/cpufreq/sti-cpufreq.c b/drivers/cpufreq/sti-cpufreq.c
index b366e6d830ea..a7db9011d5fe 100644
--- a/drivers/cpufreq/sti-cpufreq.c
+++ b/drivers/cpufreq/sti-cpufreq.c
@@ -160,6 +160,7 @@ static int sti_cpufreq_set_opp_info(void)
160 int pcode, substrate, major, minor; 160 int pcode, substrate, major, minor;
161 int ret; 161 int ret;
162 char name[MAX_PCODE_NAME_LEN]; 162 char name[MAX_PCODE_NAME_LEN];
163 struct opp_table *opp_table;
163 164
164 reg_fields = sti_cpufreq_match(); 165 reg_fields = sti_cpufreq_match();
165 if (!reg_fields) { 166 if (!reg_fields) {
@@ -211,20 +212,20 @@ use_defaults:
211 212
212 snprintf(name, MAX_PCODE_NAME_LEN, "pcode%d", pcode); 213 snprintf(name, MAX_PCODE_NAME_LEN, "pcode%d", pcode);
213 214
214 ret = dev_pm_opp_set_prop_name(dev, name); 215 opp_table = dev_pm_opp_set_prop_name(dev, name);
215 if (ret) { 216 if (IS_ERR(opp_table)) {
216 dev_err(dev, "Failed to set prop name\n"); 217 dev_err(dev, "Failed to set prop name\n");
217 return ret; 218 return PTR_ERR(opp_table);
218 } 219 }
219 220
220 version[0] = BIT(major); 221 version[0] = BIT(major);
221 version[1] = BIT(minor); 222 version[1] = BIT(minor);
222 version[2] = BIT(substrate); 223 version[2] = BIT(substrate);
223 224
224 ret = dev_pm_opp_set_supported_hw(dev, version, VERSION_ELEMENTS); 225 opp_table = dev_pm_opp_set_supported_hw(dev, version, VERSION_ELEMENTS);
225 if (ret) { 226 if (IS_ERR(opp_table)) {
226 dev_err(dev, "Failed to set supported hardware\n"); 227 dev_err(dev, "Failed to set supported hardware\n");
227 return ret; 228 return PTR_ERR(opp_table);
228 } 229 }
229 230
230 dev_dbg(dev, "pcode: %d major: %d minor: %d substrate: %d\n", 231 dev_dbg(dev, "pcode: %d major: %d minor: %d substrate: %d\n",
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index d867c6b25f9a..99787cbcaab2 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -114,15 +114,14 @@ int dev_pm_opp_disable(struct device *dev, unsigned long freq);
114int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb); 114int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
115int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb); 115int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
116 116
117int dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, 117struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
118 unsigned int count); 118void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
119void dev_pm_opp_put_supported_hw(struct device *dev); 119struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
120int dev_pm_opp_set_prop_name(struct device *dev, const char *name); 120void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
121void dev_pm_opp_put_prop_name(struct device *dev);
122struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count); 121struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
123void dev_pm_opp_put_regulators(struct opp_table *opp_table); 122void dev_pm_opp_put_regulators(struct opp_table *opp_table);
124int dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)); 123struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
125void dev_pm_opp_register_put_opp_helper(struct device *dev); 124void dev_pm_opp_register_put_opp_helper(struct opp_table *opp_table);
126int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); 125int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
127int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); 126int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
128int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); 127int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
@@ -224,29 +223,29 @@ static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct noti
224 return -ENOTSUPP; 223 return -ENOTSUPP;
225} 224}
226 225
227static inline int dev_pm_opp_set_supported_hw(struct device *dev, 226static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
228 const u32 *versions, 227 const u32 *versions,
229 unsigned int count) 228 unsigned int count)
230{ 229{
231 return -ENOTSUPP; 230 return ERR_PTR(-ENOTSUPP);
232} 231}
233 232
234static inline void dev_pm_opp_put_supported_hw(struct device *dev) {} 233static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
235 234
236static inline int dev_pm_opp_register_set_opp_helper(struct device *dev, 235static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
237 int (*set_opp)(struct dev_pm_set_opp_data *data)) 236 int (*set_opp)(struct dev_pm_set_opp_data *data))
238{ 237{
239 return -ENOTSUPP; 238 return ERR_PTR(-ENOTSUPP);
240} 239}
241 240
242static inline void dev_pm_opp_register_put_opp_helper(struct device *dev) {} 241static inline void dev_pm_opp_register_put_opp_helper(struct opp_table *opp_table) {}
243 242
244static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name) 243static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
245{ 244{
246 return -ENOTSUPP; 245 return ERR_PTR(-ENOTSUPP);
247} 246}
248 247
249static inline void dev_pm_opp_put_prop_name(struct device *dev) {} 248static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
250 249
251static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count) 250static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
252{ 251{