diff options
Diffstat (limited to 'drivers/of/unittest.c')
-rw-r--r-- | drivers/of/unittest.c | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index bbdaf5606820..3640dae4b9b2 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c | |||
@@ -1217,7 +1217,7 @@ static void of_unittest_untrack_overlay(int id) | |||
1217 | 1217 | ||
1218 | static void of_unittest_destroy_tracked_overlays(void) | 1218 | static void of_unittest_destroy_tracked_overlays(void) |
1219 | { | 1219 | { |
1220 | int id, ret, defers; | 1220 | int id, ret, defers, ovcs_id; |
1221 | 1221 | ||
1222 | if (overlay_first_id < 0) | 1222 | if (overlay_first_id < 0) |
1223 | return; | 1223 | return; |
@@ -1230,7 +1230,8 @@ static void of_unittest_destroy_tracked_overlays(void) | |||
1230 | if (!(overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id))) | 1230 | if (!(overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id))) |
1231 | continue; | 1231 | continue; |
1232 | 1232 | ||
1233 | ret = of_overlay_remove(id + overlay_first_id); | 1233 | ovcs_id = id + overlay_first_id; |
1234 | ret = of_overlay_remove(&ovcs_id); | ||
1234 | if (ret == -ENODEV) { | 1235 | if (ret == -ENODEV) { |
1235 | pr_warn("%s: no overlay to destroy for #%d\n", | 1236 | pr_warn("%s: no overlay to destroy for #%d\n", |
1236 | __func__, id + overlay_first_id); | 1237 | __func__, id + overlay_first_id); |
@@ -1252,7 +1253,7 @@ static int of_unittest_apply_overlay(int overlay_nr, int unittest_nr, | |||
1252 | int *overlay_id) | 1253 | int *overlay_id) |
1253 | { | 1254 | { |
1254 | struct device_node *np = NULL; | 1255 | struct device_node *np = NULL; |
1255 | int ret, id = -1; | 1256 | int ret; |
1256 | 1257 | ||
1257 | np = of_find_node_by_path(overlay_path(overlay_nr)); | 1258 | np = of_find_node_by_path(overlay_path(overlay_nr)); |
1258 | if (np == NULL) { | 1259 | if (np == NULL) { |
@@ -1262,23 +1263,20 @@ static int of_unittest_apply_overlay(int overlay_nr, int unittest_nr, | |||
1262 | goto out; | 1263 | goto out; |
1263 | } | 1264 | } |
1264 | 1265 | ||
1265 | ret = of_overlay_apply(np); | 1266 | *overlay_id = 0; |
1267 | ret = of_overlay_apply(np, overlay_id); | ||
1266 | if (ret < 0) { | 1268 | if (ret < 0) { |
1267 | unittest(0, "could not create overlay from \"%s\"\n", | 1269 | unittest(0, "could not create overlay from \"%s\"\n", |
1268 | overlay_path(overlay_nr)); | 1270 | overlay_path(overlay_nr)); |
1269 | goto out; | 1271 | goto out; |
1270 | } | 1272 | } |
1271 | id = ret; | 1273 | of_unittest_track_overlay(*overlay_id); |
1272 | of_unittest_track_overlay(id); | ||
1273 | 1274 | ||
1274 | ret = 0; | 1275 | ret = 0; |
1275 | 1276 | ||
1276 | out: | 1277 | out: |
1277 | of_node_put(np); | 1278 | of_node_put(np); |
1278 | 1279 | ||
1279 | if (overlay_id) | ||
1280 | *overlay_id = id; | ||
1281 | |||
1282 | return ret; | 1280 | return ret; |
1283 | } | 1281 | } |
1284 | 1282 | ||
@@ -1286,7 +1284,7 @@ out: | |||
1286 | static int of_unittest_apply_overlay_check(int overlay_nr, int unittest_nr, | 1284 | static int of_unittest_apply_overlay_check(int overlay_nr, int unittest_nr, |
1287 | int before, int after, enum overlay_type ovtype) | 1285 | int before, int after, enum overlay_type ovtype) |
1288 | { | 1286 | { |
1289 | int ret; | 1287 | int ret, ovcs_id; |
1290 | 1288 | ||
1291 | /* unittest device must not be in before state */ | 1289 | /* unittest device must not be in before state */ |
1292 | if (of_unittest_device_exists(unittest_nr, ovtype) != before) { | 1290 | if (of_unittest_device_exists(unittest_nr, ovtype) != before) { |
@@ -1297,7 +1295,8 @@ static int of_unittest_apply_overlay_check(int overlay_nr, int unittest_nr, | |||
1297 | return -EINVAL; | 1295 | return -EINVAL; |
1298 | } | 1296 | } |
1299 | 1297 | ||
1300 | ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, NULL); | 1298 | ovcs_id = 0; |
1299 | ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id); | ||
1301 | if (ret != 0) { | 1300 | if (ret != 0) { |
1302 | /* of_unittest_apply_overlay already called unittest() */ | 1301 | /* of_unittest_apply_overlay already called unittest() */ |
1303 | return ret; | 1302 | return ret; |
@@ -1320,7 +1319,7 @@ static int of_unittest_apply_revert_overlay_check(int overlay_nr, | |||
1320 | int unittest_nr, int before, int after, | 1319 | int unittest_nr, int before, int after, |
1321 | enum overlay_type ovtype) | 1320 | enum overlay_type ovtype) |
1322 | { | 1321 | { |
1323 | int ret, ov_id; | 1322 | int ret, ovcs_id; |
1324 | 1323 | ||
1325 | /* unittest device must be in before state */ | 1324 | /* unittest device must be in before state */ |
1326 | if (of_unittest_device_exists(unittest_nr, ovtype) != before) { | 1325 | if (of_unittest_device_exists(unittest_nr, ovtype) != before) { |
@@ -1332,7 +1331,8 @@ static int of_unittest_apply_revert_overlay_check(int overlay_nr, | |||
1332 | } | 1331 | } |
1333 | 1332 | ||
1334 | /* apply the overlay */ | 1333 | /* apply the overlay */ |
1335 | ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ov_id); | 1334 | ovcs_id = 0; |
1335 | ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id); | ||
1336 | if (ret != 0) { | 1336 | if (ret != 0) { |
1337 | /* of_unittest_apply_overlay already called unittest() */ | 1337 | /* of_unittest_apply_overlay already called unittest() */ |
1338 | return ret; | 1338 | return ret; |
@@ -1347,7 +1347,7 @@ static int of_unittest_apply_revert_overlay_check(int overlay_nr, | |||
1347 | return -EINVAL; | 1347 | return -EINVAL; |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | ret = of_overlay_remove(ov_id); | 1350 | ret = of_overlay_remove(&ovcs_id); |
1351 | if (ret != 0) { | 1351 | if (ret != 0) { |
1352 | unittest(0, "overlay @\"%s\" failed to be destroyed @\"%s\"\n", | 1352 | unittest(0, "overlay @\"%s\" failed to be destroyed @\"%s\"\n", |
1353 | overlay_path(overlay_nr), | 1353 | overlay_path(overlay_nr), |
@@ -1449,7 +1449,7 @@ static void of_unittest_overlay_5(void) | |||
1449 | static void of_unittest_overlay_6(void) | 1449 | static void of_unittest_overlay_6(void) |
1450 | { | 1450 | { |
1451 | struct device_node *np; | 1451 | struct device_node *np; |
1452 | int ret, i, ov_id[2]; | 1452 | int ret, i, ov_id[2], ovcs_id; |
1453 | int overlay_nr = 6, unittest_nr = 6; | 1453 | int overlay_nr = 6, unittest_nr = 6; |
1454 | int before = 0, after = 1; | 1454 | int before = 0, after = 1; |
1455 | 1455 | ||
@@ -1476,13 +1476,14 @@ static void of_unittest_overlay_6(void) | |||
1476 | return; | 1476 | return; |
1477 | } | 1477 | } |
1478 | 1478 | ||
1479 | ret = of_overlay_apply(np); | 1479 | ovcs_id = 0; |
1480 | ret = of_overlay_apply(np, &ovcs_id); | ||
1480 | if (ret < 0) { | 1481 | if (ret < 0) { |
1481 | unittest(0, "could not create overlay from \"%s\"\n", | 1482 | unittest(0, "could not create overlay from \"%s\"\n", |
1482 | overlay_path(overlay_nr + i)); | 1483 | overlay_path(overlay_nr + i)); |
1483 | return; | 1484 | return; |
1484 | } | 1485 | } |
1485 | ov_id[i] = ret; | 1486 | ov_id[i] = ovcs_id; |
1486 | of_unittest_track_overlay(ov_id[i]); | 1487 | of_unittest_track_overlay(ov_id[i]); |
1487 | } | 1488 | } |
1488 | 1489 | ||
@@ -1500,7 +1501,8 @@ static void of_unittest_overlay_6(void) | |||
1500 | } | 1501 | } |
1501 | 1502 | ||
1502 | for (i = 1; i >= 0; i--) { | 1503 | for (i = 1; i >= 0; i--) { |
1503 | ret = of_overlay_remove(ov_id[i]); | 1504 | ovcs_id = ov_id[i]; |
1505 | ret = of_overlay_remove(&ovcs_id); | ||
1504 | if (ret != 0) { | 1506 | if (ret != 0) { |
1505 | unittest(0, "overlay @\"%s\" failed destroy @\"%s\"\n", | 1507 | unittest(0, "overlay @\"%s\" failed destroy @\"%s\"\n", |
1506 | overlay_path(overlay_nr + i), | 1508 | overlay_path(overlay_nr + i), |
@@ -1531,7 +1533,7 @@ static void of_unittest_overlay_6(void) | |||
1531 | static void of_unittest_overlay_8(void) | 1533 | static void of_unittest_overlay_8(void) |
1532 | { | 1534 | { |
1533 | struct device_node *np; | 1535 | struct device_node *np; |
1534 | int ret, i, ov_id[2]; | 1536 | int ret, i, ov_id[2], ovcs_id; |
1535 | int overlay_nr = 8, unittest_nr = 8; | 1537 | int overlay_nr = 8, unittest_nr = 8; |
1536 | 1538 | ||
1537 | /* we don't care about device state in this test */ | 1539 | /* we don't care about device state in this test */ |
@@ -1546,18 +1548,20 @@ static void of_unittest_overlay_8(void) | |||
1546 | return; | 1548 | return; |
1547 | } | 1549 | } |
1548 | 1550 | ||
1549 | ret = of_overlay_apply(np); | 1551 | ovcs_id = 0; |
1552 | ret = of_overlay_apply(np, &ovcs_id); | ||
1550 | if (ret < 0) { | 1553 | if (ret < 0) { |
1551 | unittest(0, "could not create overlay from \"%s\"\n", | 1554 | unittest(0, "could not create overlay from \"%s\"\n", |
1552 | overlay_path(overlay_nr + i)); | 1555 | overlay_path(overlay_nr + i)); |
1553 | return; | 1556 | return; |
1554 | } | 1557 | } |
1555 | ov_id[i] = ret; | 1558 | ov_id[i] = ovcs_id; |
1556 | of_unittest_track_overlay(ov_id[i]); | 1559 | of_unittest_track_overlay(ov_id[i]); |
1557 | } | 1560 | } |
1558 | 1561 | ||
1559 | /* now try to remove first overlay (it should fail) */ | 1562 | /* now try to remove first overlay (it should fail) */ |
1560 | ret = of_overlay_remove(ov_id[0]); | 1563 | ovcs_id = ov_id[0]; |
1564 | ret = of_overlay_remove(&ovcs_id); | ||
1561 | if (ret == 0) { | 1565 | if (ret == 0) { |
1562 | unittest(0, "overlay @\"%s\" was destroyed @\"%s\"\n", | 1566 | unittest(0, "overlay @\"%s\" was destroyed @\"%s\"\n", |
1563 | overlay_path(overlay_nr + 0), | 1567 | overlay_path(overlay_nr + 0), |
@@ -1568,7 +1572,8 @@ static void of_unittest_overlay_8(void) | |||
1568 | 1572 | ||
1569 | /* removing them in order should work */ | 1573 | /* removing them in order should work */ |
1570 | for (i = 1; i >= 0; i--) { | 1574 | for (i = 1; i >= 0; i--) { |
1571 | ret = of_overlay_remove(ov_id[i]); | 1575 | ovcs_id = ov_id[i]; |
1576 | ret = of_overlay_remove(&ovcs_id); | ||
1572 | if (ret != 0) { | 1577 | if (ret != 0) { |
1573 | unittest(0, "overlay @\"%s\" not destroyed @\"%s\"\n", | 1578 | unittest(0, "overlay @\"%s\" not destroyed @\"%s\"\n", |
1574 | overlay_path(overlay_nr + i), | 1579 | overlay_path(overlay_nr + i), |
@@ -2149,13 +2154,11 @@ static int __init overlay_data_add(int onum) | |||
2149 | goto out_free_np_overlay; | 2154 | goto out_free_np_overlay; |
2150 | } | 2155 | } |
2151 | 2156 | ||
2152 | ret = of_overlay_apply(info->np_overlay); | 2157 | info->overlay_id = 0; |
2158 | ret = of_overlay_apply(info->np_overlay, &info->overlay_id); | ||
2153 | if (ret < 0) { | 2159 | if (ret < 0) { |
2154 | pr_err("of_overlay_apply() (ret=%d), %d\n", ret, onum); | 2160 | pr_err("of_overlay_apply() (ret=%d), %d\n", ret, onum); |
2155 | goto out_free_np_overlay; | 2161 | goto out_free_np_overlay; |
2156 | } else { | ||
2157 | info->overlay_id = ret; | ||
2158 | ret = 0; | ||
2159 | } | 2162 | } |
2160 | 2163 | ||
2161 | pr_debug("__dtb_overlay_begin applied, overlay id %d\n", ret); | 2164 | pr_debug("__dtb_overlay_begin applied, overlay id %d\n", ret); |