summaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorFrank Rowand <frank.rowand@sony.com>2018-03-08 17:39:04 -0500
committerRob Herring <robh@kernel.org>2018-03-12 11:27:48 -0400
commit06c4697894992b0977f1f4f079ba50da5eccf76a (patch)
tree570ed4b5b3f6b399024ca50e5fba623581725123 /drivers/of
parent2a38f6da6014f1e1922361370dbe9a15a828386e (diff)
of: unittest: remove unneeded local return value variables
A common pattern in many unittest functions is to save the return value of a function in a local variable, then test the value of the local variable, without using that return value for any further purpose. Remove the local return value variable for these cases. A second common pattern is: ret = some_test_function(many, parameters, ...); if (unittest(ret == 0, "error message format", ...)) return; This pattern is more clear when the local variable 'ret' is used, due to the long lines caused by the parameters to the test function and the long format and data parameters of unittest(). The local variable is retained in these cases. Signed-off-by: Frank Rowand <frank.rowand@sony.com> Signed-off-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/unittest.c89
1 files changed, 24 insertions, 65 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 20ffbedac524..d1dc5cd5a58e 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1529,11 +1529,8 @@ static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
1529/* test activation of device */ 1529/* test activation of device */
1530static void __init of_unittest_overlay_0(void) 1530static void __init of_unittest_overlay_0(void)
1531{ 1531{
1532 int ret;
1533
1534 /* device should enable */ 1532 /* device should enable */
1535 ret = of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY); 1533 if (of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY))
1536 if (ret != 0)
1537 return; 1534 return;
1538 1535
1539 unittest(1, "overlay test %d passed\n", 0); 1536 unittest(1, "overlay test %d passed\n", 0);
@@ -1542,11 +1539,8 @@ static void __init of_unittest_overlay_0(void)
1542/* test deactivation of device */ 1539/* test deactivation of device */
1543static void __init of_unittest_overlay_1(void) 1540static void __init of_unittest_overlay_1(void)
1544{ 1541{
1545 int ret;
1546
1547 /* device should disable */ 1542 /* device should disable */
1548 ret = of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY); 1543 if (of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY))
1549 if (ret != 0)
1550 return; 1544 return;
1551 1545
1552 unittest(1, "overlay test %d passed\n", 1); 1546 unittest(1, "overlay test %d passed\n", 1);
@@ -1555,11 +1549,8 @@ static void __init of_unittest_overlay_1(void)
1555/* test activation of device */ 1549/* test activation of device */
1556static void __init of_unittest_overlay_2(void) 1550static void __init of_unittest_overlay_2(void)
1557{ 1551{
1558 int ret;
1559
1560 /* device should enable */ 1552 /* device should enable */
1561 ret = of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY); 1553 if (of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY))
1562 if (ret != 0)
1563 return; 1554 return;
1564 1555
1565 unittest(1, "overlay test %d passed\n", 2); 1556 unittest(1, "overlay test %d passed\n", 2);
@@ -1568,11 +1559,8 @@ static void __init of_unittest_overlay_2(void)
1568/* test deactivation of device */ 1559/* test deactivation of device */
1569static void __init of_unittest_overlay_3(void) 1560static void __init of_unittest_overlay_3(void)
1570{ 1561{
1571 int ret;
1572
1573 /* device should disable */ 1562 /* device should disable */
1574 ret = of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY); 1563 if (of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY))
1575 if (ret != 0)
1576 return; 1564 return;
1577 1565
1578 unittest(1, "overlay test %d passed\n", 3); 1566 unittest(1, "overlay test %d passed\n", 3);
@@ -1581,11 +1569,8 @@ static void __init of_unittest_overlay_3(void)
1581/* test activation of a full device node */ 1569/* test activation of a full device node */
1582static void __init of_unittest_overlay_4(void) 1570static void __init of_unittest_overlay_4(void)
1583{ 1571{
1584 int ret;
1585
1586 /* device should disable */ 1572 /* device should disable */
1587 ret = of_unittest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY); 1573 if (of_unittest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY))
1588 if (ret != 0)
1589 return; 1574 return;
1590 1575
1591 unittest(1, "overlay test %d passed\n", 4); 1576 unittest(1, "overlay test %d passed\n", 4);
@@ -1594,11 +1579,8 @@ static void __init of_unittest_overlay_4(void)
1594/* test overlay apply/revert sequence */ 1579/* test overlay apply/revert sequence */
1595static void __init of_unittest_overlay_5(void) 1580static void __init of_unittest_overlay_5(void)
1596{ 1581{
1597 int ret;
1598
1599 /* device should disable */ 1582 /* device should disable */
1600 ret = of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY); 1583 if (of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY))
1601 if (ret != 0)
1602 return; 1584 return;
1603 1585
1604 unittest(1, "overlay test %d passed\n", 5); 1586 unittest(1, "overlay test %d passed\n", 5);
@@ -1607,7 +1589,7 @@ static void __init of_unittest_overlay_5(void)
1607/* test overlay application in sequence */ 1589/* test overlay application in sequence */
1608static void __init of_unittest_overlay_6(void) 1590static void __init of_unittest_overlay_6(void)
1609{ 1591{
1610 int ret, i, ov_id[2], ovcs_id; 1592 int i, ov_id[2], ovcs_id;
1611 int overlay_nr = 6, unittest_nr = 6; 1593 int overlay_nr = 6, unittest_nr = 6;
1612 int before = 0, after = 1; 1594 int before = 0, after = 1;
1613 const char *overlay_name; 1595 const char *overlay_name;
@@ -1630,8 +1612,7 @@ static void __init of_unittest_overlay_6(void)
1630 1612
1631 overlay_name = overlay_name_from_nr(overlay_nr + i); 1613 overlay_name = overlay_name_from_nr(overlay_nr + i);
1632 1614
1633 ret = overlay_data_apply(overlay_name, &ovcs_id); 1615 if (!overlay_data_apply(overlay_name, &ovcs_id)) {
1634 if (!ret) {
1635 unittest(0, "could not apply overlay \"%s\"\n", 1616 unittest(0, "could not apply overlay \"%s\"\n",
1636 overlay_name); 1617 overlay_name);
1637 return; 1618 return;
@@ -1655,8 +1636,7 @@ static void __init of_unittest_overlay_6(void)
1655 1636
1656 for (i = 1; i >= 0; i--) { 1637 for (i = 1; i >= 0; i--) {
1657 ovcs_id = ov_id[i]; 1638 ovcs_id = ov_id[i];
1658 ret = of_overlay_remove(&ovcs_id); 1639 if (of_overlay_remove(&ovcs_id)) {
1659 if (ret != 0) {
1660 unittest(0, "%s failed destroy @\"%s\"\n", 1640 unittest(0, "%s failed destroy @\"%s\"\n",
1661 overlay_name_from_nr(overlay_nr + i), 1641 overlay_name_from_nr(overlay_nr + i),
1662 unittest_path(unittest_nr + i, 1642 unittest_path(unittest_nr + i,
@@ -1685,7 +1665,7 @@ static void __init of_unittest_overlay_6(void)
1685/* test overlay application in sequence */ 1665/* test overlay application in sequence */
1686static void __init of_unittest_overlay_8(void) 1666static void __init of_unittest_overlay_8(void)
1687{ 1667{
1688 int ret, i, ov_id[2], ovcs_id; 1668 int i, ov_id[2], ovcs_id;
1689 int overlay_nr = 8, unittest_nr = 8; 1669 int overlay_nr = 8, unittest_nr = 8;
1690 const char *overlay_name; 1670 const char *overlay_name;
1691 1671
@@ -1707,8 +1687,7 @@ static void __init of_unittest_overlay_8(void)
1707 1687
1708 /* now try to remove first overlay (it should fail) */ 1688 /* now try to remove first overlay (it should fail) */
1709 ovcs_id = ov_id[0]; 1689 ovcs_id = ov_id[0];
1710 ret = of_overlay_remove(&ovcs_id); 1690 if (!of_overlay_remove(&ovcs_id)) {
1711 if (ret == 0) {
1712 unittest(0, "%s was destroyed @\"%s\"\n", 1691 unittest(0, "%s was destroyed @\"%s\"\n",
1713 overlay_name_from_nr(overlay_nr + 0), 1692 overlay_name_from_nr(overlay_nr + 0),
1714 unittest_path(unittest_nr, 1693 unittest_path(unittest_nr,
@@ -1719,8 +1698,7 @@ static void __init of_unittest_overlay_8(void)
1719 /* removing them in order should work */ 1698 /* removing them in order should work */
1720 for (i = 1; i >= 0; i--) { 1699 for (i = 1; i >= 0; i--) {
1721 ovcs_id = ov_id[i]; 1700 ovcs_id = ov_id[i];
1722 ret = of_overlay_remove(&ovcs_id); 1701 if (of_overlay_remove(&ovcs_id)) {
1723 if (ret != 0) {
1724 unittest(0, "%s not destroyed @\"%s\"\n", 1702 unittest(0, "%s not destroyed @\"%s\"\n",
1725 overlay_name_from_nr(overlay_nr + i), 1703 overlay_name_from_nr(overlay_nr + i),
1726 unittest_path(unittest_nr, 1704 unittest_path(unittest_nr,
@@ -1917,7 +1895,7 @@ static int unittest_i2c_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
1917static int unittest_i2c_mux_probe(struct i2c_client *client, 1895static int unittest_i2c_mux_probe(struct i2c_client *client,
1918 const struct i2c_device_id *id) 1896 const struct i2c_device_id *id)
1919{ 1897{
1920 int ret, i, nchans; 1898 int i, nchans;
1921 struct device *dev = &client->dev; 1899 struct device *dev = &client->dev;
1922 struct i2c_adapter *adap = to_i2c_adapter(dev->parent); 1900 struct i2c_adapter *adap = to_i2c_adapter(dev->parent);
1923 struct device_node *np = client->dev.of_node, *child; 1901 struct device_node *np = client->dev.of_node, *child;
@@ -1933,8 +1911,7 @@ static int unittest_i2c_mux_probe(struct i2c_client *client,
1933 1911
1934 max_reg = (u32)-1; 1912 max_reg = (u32)-1;
1935 for_each_child_of_node(np, child) { 1913 for_each_child_of_node(np, child) {
1936 ret = of_property_read_u32(child, "reg", &reg); 1914 if (of_property_read_u32(child, "reg", &reg))
1937 if (ret)
1938 continue; 1915 continue;
1939 if (max_reg == (u32)-1 || reg > max_reg) 1916 if (max_reg == (u32)-1 || reg > max_reg)
1940 max_reg = reg; 1917 max_reg = reg;
@@ -1950,8 +1927,7 @@ static int unittest_i2c_mux_probe(struct i2c_client *client,
1950 if (!muxc) 1927 if (!muxc)
1951 return -ENOMEM; 1928 return -ENOMEM;
1952 for (i = 0; i < nchans; i++) { 1929 for (i = 0; i < nchans; i++) {
1953 ret = i2c_mux_add_adapter(muxc, 0, i, 0); 1930 if (i2c_mux_add_adapter(muxc, 0, i, 0)) {
1954 if (ret) {
1955 dev_err(dev, "Failed to register mux #%d\n", i); 1931 dev_err(dev, "Failed to register mux #%d\n", i);
1956 i2c_mux_del_adapters(muxc); 1932 i2c_mux_del_adapters(muxc);
1957 return -ENODEV; 1933 return -ENODEV;
@@ -2025,11 +2001,8 @@ static void of_unittest_overlay_i2c_cleanup(void)
2025 2001
2026static void __init of_unittest_overlay_i2c_12(void) 2002static void __init of_unittest_overlay_i2c_12(void)
2027{ 2003{
2028 int ret;
2029
2030 /* device should enable */ 2004 /* device should enable */
2031 ret = of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY); 2005 if (of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY))
2032 if (ret != 0)
2033 return; 2006 return;
2034 2007
2035 unittest(1, "overlay test %d passed\n", 12); 2008 unittest(1, "overlay test %d passed\n", 12);
@@ -2038,11 +2011,8 @@ static void __init of_unittest_overlay_i2c_12(void)
2038/* test deactivation of device */ 2011/* test deactivation of device */
2039static void __init of_unittest_overlay_i2c_13(void) 2012static void __init of_unittest_overlay_i2c_13(void)
2040{ 2013{
2041 int ret;
2042
2043 /* device should disable */ 2014 /* device should disable */
2044 ret = of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY); 2015 if (of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY))
2045 if (ret != 0)
2046 return; 2016 return;
2047 2017
2048 unittest(1, "overlay test %d passed\n", 13); 2018 unittest(1, "overlay test %d passed\n", 13);
@@ -2055,11 +2025,8 @@ static void of_unittest_overlay_i2c_14(void)
2055 2025
2056static void __init of_unittest_overlay_i2c_15(void) 2026static void __init of_unittest_overlay_i2c_15(void)
2057{ 2027{
2058 int ret;
2059
2060 /* device should enable */ 2028 /* device should enable */
2061 ret = of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY); 2029 if (of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY))
2062 if (ret != 0)
2063 return; 2030 return;
2064 2031
2065 unittest(1, "overlay test %d passed\n", 15); 2032 unittest(1, "overlay test %d passed\n", 15);
@@ -2075,10 +2042,8 @@ static inline void of_unittest_overlay_i2c_15(void) { }
2075static void __init of_unittest_overlay(void) 2042static void __init of_unittest_overlay(void)
2076{ 2043{
2077 struct device_node *bus_np = NULL; 2044 struct device_node *bus_np = NULL;
2078 int ret;
2079 2045
2080 ret = platform_driver_register(&unittest_driver); 2046 if (platform_driver_register(&unittest_driver)) {
2081 if (ret != 0) {
2082 unittest(0, "could not register unittest driver\n"); 2047 unittest(0, "could not register unittest driver\n");
2083 goto out; 2048 goto out;
2084 } 2049 }
@@ -2089,8 +2054,7 @@ static void __init of_unittest_overlay(void)
2089 goto out; 2054 goto out;
2090 } 2055 }
2091 2056
2092 ret = of_platform_default_populate(bus_np, NULL, NULL); 2057 if (of_platform_default_populate(bus_np, NULL, NULL)) {
2093 if (ret != 0) {
2094 unittest(0, "could not populate bus @ \"%s\"\n", bus_path); 2058 unittest(0, "could not populate bus @ \"%s\"\n", bus_path);
2095 goto out; 2059 goto out;
2096 } 2060 }
@@ -2341,7 +2305,6 @@ static __init void of_unittest_overlay_high_level(void)
2341 struct device_node *overlay_base_symbols; 2305 struct device_node *overlay_base_symbols;
2342 struct device_node **pprev; 2306 struct device_node **pprev;
2343 struct property *prop; 2307 struct property *prop;
2344 int ret;
2345 2308
2346 if (!overlay_base_root) { 2309 if (!overlay_base_root) {
2347 unittest(0, "overlay_base_root not initialized\n"); 2310 unittest(0, "overlay_base_root not initialized\n");
@@ -2432,19 +2395,15 @@ static __init void of_unittest_overlay_high_level(void)
2432 prop->name); 2395 prop->name);
2433 goto err_unlock; 2396 goto err_unlock;
2434 } 2397 }
2435 ret = __of_add_property(of_symbols, new_prop); 2398 if (__of_add_property(of_symbols, new_prop)) {
2436 if (ret) { 2399 /* "name" auto-generated by unflatten */
2437 if (!strcmp(new_prop->name, "name")) { 2400 if (!strcmp(new_prop->name, "name"))
2438 /* auto-generated by unflatten */
2439 ret = 0;
2440 continue; 2401 continue;
2441 }
2442 unittest(0, "duplicate property '%s' in overlay_base node __symbols__", 2402 unittest(0, "duplicate property '%s' in overlay_base node __symbols__",
2443 prop->name); 2403 prop->name);
2444 goto err_unlock; 2404 goto err_unlock;
2445 } 2405 }
2446 ret = __of_add_property_sysfs(of_symbols, new_prop); 2406 if (__of_add_property_sysfs(of_symbols, new_prop)) {
2447 if (ret) {
2448 unittest(0, "unable to add property '%s' in overlay_base node __symbols__ to sysfs", 2407 unittest(0, "unable to add property '%s' in overlay_base node __symbols__ to sysfs",
2449 prop->name); 2408 prop->name);
2450 goto err_unlock; 2409 goto err_unlock;