unittest.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900
  1. /*
  2. * Self tests for device tree subsystem
  3. */
  4. #define pr_fmt(fmt) "### dt-test ### " fmt
  5. #include <linux/clk.h>
  6. #include <linux/err.h>
  7. #include <linux/errno.h>
  8. #include <linux/hashtable.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/of_fdt.h>
  12. #include <linux/of_irq.h>
  13. #include <linux/of_platform.h>
  14. #include <linux/list.h>
  15. #include <linux/mutex.h>
  16. #include <linux/slab.h>
  17. #include <linux/device.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/of_platform.h>
  20. #include <linux/i2c.h>
  21. #include <linux/i2c-mux.h>
  22. #include "of_private.h"
  23. static struct selftest_results {
  24. int passed;
  25. int failed;
  26. } selftest_results;
  27. #define selftest(result, fmt, ...) ({ \
  28. bool failed = !(result); \
  29. if (failed) { \
  30. selftest_results.failed++; \
  31. pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \
  32. } else { \
  33. selftest_results.passed++; \
  34. pr_debug("pass %s():%i\n", __func__, __LINE__); \
  35. } \
  36. failed; \
  37. })
  38. static void __init of_selftest_find_node_by_name(void)
  39. {
  40. struct device_node *np;
  41. const char *options;
  42. np = of_find_node_by_path("/testcase-data");
  43. selftest(np && !strcmp("/testcase-data", np->full_name),
  44. "find /testcase-data failed\n");
  45. of_node_put(np);
  46. /* Test if trailing '/' works */
  47. np = of_find_node_by_path("/testcase-data/");
  48. selftest(!np, "trailing '/' on /testcase-data/ should fail\n");
  49. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  50. selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name),
  51. "find /testcase-data/phandle-tests/consumer-a failed\n");
  52. of_node_put(np);
  53. np = of_find_node_by_path("testcase-alias");
  54. selftest(np && !strcmp("/testcase-data", np->full_name),
  55. "find testcase-alias failed\n");
  56. of_node_put(np);
  57. /* Test if trailing '/' works on aliases */
  58. np = of_find_node_by_path("testcase-alias/");
  59. selftest(!np, "trailing '/' on testcase-alias/ should fail\n");
  60. np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
  61. selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name),
  62. "find testcase-alias/phandle-tests/consumer-a failed\n");
  63. of_node_put(np);
  64. np = of_find_node_by_path("/testcase-data/missing-path");
  65. selftest(!np, "non-existent path returned node %s\n", np->full_name);
  66. of_node_put(np);
  67. np = of_find_node_by_path("missing-alias");
  68. selftest(!np, "non-existent alias returned node %s\n", np->full_name);
  69. of_node_put(np);
  70. np = of_find_node_by_path("testcase-alias/missing-path");
  71. selftest(!np, "non-existent alias with relative path returned node %s\n", np->full_name);
  72. of_node_put(np);
  73. np = of_find_node_opts_by_path("/testcase-data:testoption", &options);
  74. selftest(np && !strcmp("testoption", options),
  75. "option path test failed\n");
  76. of_node_put(np);
  77. np = of_find_node_opts_by_path("/testcase-data:test/option", &options);
  78. selftest(np && !strcmp("test/option", options),
  79. "option path test, subcase #1 failed\n");
  80. of_node_put(np);
  81. np = of_find_node_opts_by_path("/testcase-data/testcase-device1:test/option", &options);
  82. selftest(np && !strcmp("test/option", options),
  83. "option path test, subcase #2 failed\n");
  84. of_node_put(np);
  85. np = of_find_node_opts_by_path("/testcase-data:testoption", NULL);
  86. selftest(np, "NULL option path test failed\n");
  87. of_node_put(np);
  88. np = of_find_node_opts_by_path("testcase-alias:testaliasoption",
  89. &options);
  90. selftest(np && !strcmp("testaliasoption", options),
  91. "option alias path test failed\n");
  92. of_node_put(np);
  93. np = of_find_node_opts_by_path("testcase-alias:test/alias/option",
  94. &options);
  95. selftest(np && !strcmp("test/alias/option", options),
  96. "option alias path test, subcase #1 failed\n");
  97. of_node_put(np);
  98. np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL);
  99. selftest(np, "NULL option alias path test failed\n");
  100. of_node_put(np);
  101. options = "testoption";
  102. np = of_find_node_opts_by_path("testcase-alias", &options);
  103. selftest(np && !options, "option clearing test failed\n");
  104. of_node_put(np);
  105. options = "testoption";
  106. np = of_find_node_opts_by_path("/", &options);
  107. selftest(np && !options, "option clearing root node test failed\n");
  108. of_node_put(np);
  109. }
  110. static void __init of_selftest_dynamic(void)
  111. {
  112. struct device_node *np;
  113. struct property *prop;
  114. np = of_find_node_by_path("/testcase-data");
  115. if (!np) {
  116. pr_err("missing testcase data\n");
  117. return;
  118. }
  119. /* Array of 4 properties for the purpose of testing */
  120. prop = kzalloc(sizeof(*prop) * 4, GFP_KERNEL);
  121. if (!prop) {
  122. selftest(0, "kzalloc() failed\n");
  123. return;
  124. }
  125. /* Add a new property - should pass*/
  126. prop->name = "new-property";
  127. prop->value = "new-property-data";
  128. prop->length = strlen(prop->value);
  129. selftest(of_add_property(np, prop) == 0, "Adding a new property failed\n");
  130. /* Try to add an existing property - should fail */
  131. prop++;
  132. prop->name = "new-property";
  133. prop->value = "new-property-data-should-fail";
  134. prop->length = strlen(prop->value);
  135. selftest(of_add_property(np, prop) != 0,
  136. "Adding an existing property should have failed\n");
  137. /* Try to modify an existing property - should pass */
  138. prop->value = "modify-property-data-should-pass";
  139. prop->length = strlen(prop->value);
  140. selftest(of_update_property(np, prop) == 0,
  141. "Updating an existing property should have passed\n");
  142. /* Try to modify non-existent property - should pass*/
  143. prop++;
  144. prop->name = "modify-property";
  145. prop->value = "modify-missing-property-data-should-pass";
  146. prop->length = strlen(prop->value);
  147. selftest(of_update_property(np, prop) == 0,
  148. "Updating a missing property should have passed\n");
  149. /* Remove property - should pass */
  150. selftest(of_remove_property(np, prop) == 0,
  151. "Removing a property should have passed\n");
  152. /* Adding very large property - should pass */
  153. prop++;
  154. prop->name = "large-property-PAGE_SIZEx8";
  155. prop->length = PAGE_SIZE * 8;
  156. prop->value = kzalloc(prop->length, GFP_KERNEL);
  157. selftest(prop->value != NULL, "Unable to allocate large buffer\n");
  158. if (prop->value)
  159. selftest(of_add_property(np, prop) == 0,
  160. "Adding a large property should have passed\n");
  161. }
  162. static int __init of_selftest_check_node_linkage(struct device_node *np)
  163. {
  164. struct device_node *child;
  165. int count = 0, rc;
  166. for_each_child_of_node(np, child) {
  167. if (child->parent != np) {
  168. pr_err("Child node %s links to wrong parent %s\n",
  169. child->name, np->name);
  170. return -EINVAL;
  171. }
  172. rc = of_selftest_check_node_linkage(child);
  173. if (rc < 0)
  174. return rc;
  175. count += rc;
  176. }
  177. return count + 1;
  178. }
  179. static void __init of_selftest_check_tree_linkage(void)
  180. {
  181. struct device_node *np;
  182. int allnode_count = 0, child_count;
  183. if (!of_root)
  184. return;
  185. for_each_of_allnodes(np)
  186. allnode_count++;
  187. child_count = of_selftest_check_node_linkage(of_root);
  188. selftest(child_count > 0, "Device node data structure is corrupted\n");
  189. selftest(child_count == allnode_count,
  190. "allnodes list size (%i) doesn't match sibling lists size (%i)\n",
  191. allnode_count, child_count);
  192. pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count);
  193. }
  194. struct node_hash {
  195. struct hlist_node node;
  196. struct device_node *np;
  197. };
  198. static DEFINE_HASHTABLE(phandle_ht, 8);
  199. static void __init of_selftest_check_phandles(void)
  200. {
  201. struct device_node *np;
  202. struct node_hash *nh;
  203. struct hlist_node *tmp;
  204. int i, dup_count = 0, phandle_count = 0;
  205. for_each_of_allnodes(np) {
  206. if (!np->phandle)
  207. continue;
  208. hash_for_each_possible(phandle_ht, nh, node, np->phandle) {
  209. if (nh->np->phandle == np->phandle) {
  210. pr_info("Duplicate phandle! %i used by %s and %s\n",
  211. np->phandle, nh->np->full_name, np->full_name);
  212. dup_count++;
  213. break;
  214. }
  215. }
  216. nh = kzalloc(sizeof(*nh), GFP_KERNEL);
  217. if (WARN_ON(!nh))
  218. return;
  219. nh->np = np;
  220. hash_add(phandle_ht, &nh->node, np->phandle);
  221. phandle_count++;
  222. }
  223. selftest(dup_count == 0, "Found %i duplicates in %i phandles\n",
  224. dup_count, phandle_count);
  225. /* Clean up */
  226. hash_for_each_safe(phandle_ht, i, tmp, nh, node) {
  227. hash_del(&nh->node);
  228. kfree(nh);
  229. }
  230. }
  231. static void __init of_selftest_parse_phandle_with_args(void)
  232. {
  233. struct device_node *np;
  234. struct of_phandle_args args;
  235. int i, rc;
  236. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  237. if (!np) {
  238. pr_err("missing testcase data\n");
  239. return;
  240. }
  241. rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
  242. selftest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc);
  243. for (i = 0; i < 8; i++) {
  244. bool passed = true;
  245. rc = of_parse_phandle_with_args(np, "phandle-list",
  246. "#phandle-cells", i, &args);
  247. /* Test the values from tests-phandle.dtsi */
  248. switch (i) {
  249. case 0:
  250. passed &= !rc;
  251. passed &= (args.args_count == 1);
  252. passed &= (args.args[0] == (i + 1));
  253. break;
  254. case 1:
  255. passed &= !rc;
  256. passed &= (args.args_count == 2);
  257. passed &= (args.args[0] == (i + 1));
  258. passed &= (args.args[1] == 0);
  259. break;
  260. case 2:
  261. passed &= (rc == -ENOENT);
  262. break;
  263. case 3:
  264. passed &= !rc;
  265. passed &= (args.args_count == 3);
  266. passed &= (args.args[0] == (i + 1));
  267. passed &= (args.args[1] == 4);
  268. passed &= (args.args[2] == 3);
  269. break;
  270. case 4:
  271. passed &= !rc;
  272. passed &= (args.args_count == 2);
  273. passed &= (args.args[0] == (i + 1));
  274. passed &= (args.args[1] == 100);
  275. break;
  276. case 5:
  277. passed &= !rc;
  278. passed &= (args.args_count == 0);
  279. break;
  280. case 6:
  281. passed &= !rc;
  282. passed &= (args.args_count == 1);
  283. passed &= (args.args[0] == (i + 1));
  284. break;
  285. case 7:
  286. passed &= (rc == -ENOENT);
  287. break;
  288. default:
  289. passed = false;
  290. }
  291. selftest(passed, "index %i - data error on node %s rc=%i\n",
  292. i, args.np->full_name, rc);
  293. }
  294. /* Check for missing list property */
  295. rc = of_parse_phandle_with_args(np, "phandle-list-missing",
  296. "#phandle-cells", 0, &args);
  297. selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
  298. rc = of_count_phandle_with_args(np, "phandle-list-missing",
  299. "#phandle-cells");
  300. selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
  301. /* Check for missing cells property */
  302. rc = of_parse_phandle_with_args(np, "phandle-list",
  303. "#phandle-cells-missing", 0, &args);
  304. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  305. rc = of_count_phandle_with_args(np, "phandle-list",
  306. "#phandle-cells-missing");
  307. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  308. /* Check for bad phandle in list */
  309. rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
  310. "#phandle-cells", 0, &args);
  311. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  312. rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle",
  313. "#phandle-cells");
  314. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  315. /* Check for incorrectly formed argument list */
  316. rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
  317. "#phandle-cells", 1, &args);
  318. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  319. rc = of_count_phandle_with_args(np, "phandle-list-bad-args",
  320. "#phandle-cells");
  321. selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
  322. }
  323. static void __init of_selftest_property_string(void)
  324. {
  325. const char *strings[4];
  326. struct device_node *np;
  327. int rc;
  328. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  329. if (!np) {
  330. pr_err("No testcase data in device tree\n");
  331. return;
  332. }
  333. rc = of_property_match_string(np, "phandle-list-names", "first");
  334. selftest(rc == 0, "first expected:0 got:%i\n", rc);
  335. rc = of_property_match_string(np, "phandle-list-names", "second");
  336. selftest(rc == 1, "second expected:1 got:%i\n", rc);
  337. rc = of_property_match_string(np, "phandle-list-names", "third");
  338. selftest(rc == 2, "third expected:2 got:%i\n", rc);
  339. rc = of_property_match_string(np, "phandle-list-names", "fourth");
  340. selftest(rc == -ENODATA, "unmatched string; rc=%i\n", rc);
  341. rc = of_property_match_string(np, "missing-property", "blah");
  342. selftest(rc == -EINVAL, "missing property; rc=%i\n", rc);
  343. rc = of_property_match_string(np, "empty-property", "blah");
  344. selftest(rc == -ENODATA, "empty property; rc=%i\n", rc);
  345. rc = of_property_match_string(np, "unterminated-string", "blah");
  346. selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
  347. /* of_property_count_strings() tests */
  348. rc = of_property_count_strings(np, "string-property");
  349. selftest(rc == 1, "Incorrect string count; rc=%i\n", rc);
  350. rc = of_property_count_strings(np, "phandle-list-names");
  351. selftest(rc == 3, "Incorrect string count; rc=%i\n", rc);
  352. rc = of_property_count_strings(np, "unterminated-string");
  353. selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
  354. rc = of_property_count_strings(np, "unterminated-string-list");
  355. selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
  356. /* of_property_read_string_index() tests */
  357. rc = of_property_read_string_index(np, "string-property", 0, strings);
  358. selftest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc);
  359. strings[0] = NULL;
  360. rc = of_property_read_string_index(np, "string-property", 1, strings);
  361. selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  362. rc = of_property_read_string_index(np, "phandle-list-names", 0, strings);
  363. selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
  364. rc = of_property_read_string_index(np, "phandle-list-names", 1, strings);
  365. selftest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc);
  366. rc = of_property_read_string_index(np, "phandle-list-names", 2, strings);
  367. selftest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc);
  368. strings[0] = NULL;
  369. rc = of_property_read_string_index(np, "phandle-list-names", 3, strings);
  370. selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  371. strings[0] = NULL;
  372. rc = of_property_read_string_index(np, "unterminated-string", 0, strings);
  373. selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  374. rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings);
  375. selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
  376. strings[0] = NULL;
  377. rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */
  378. selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
  379. strings[1] = NULL;
  380. /* of_property_read_string_array() tests */
  381. rc = of_property_read_string_array(np, "string-property", strings, 4);
  382. selftest(rc == 1, "Incorrect string count; rc=%i\n", rc);
  383. rc = of_property_read_string_array(np, "phandle-list-names", strings, 4);
  384. selftest(rc == 3, "Incorrect string count; rc=%i\n", rc);
  385. rc = of_property_read_string_array(np, "unterminated-string", strings, 4);
  386. selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
  387. /* -- An incorrectly formed string should cause a failure */
  388. rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4);
  389. selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
  390. /* -- parsing the correctly formed strings should still work: */
  391. strings[2] = NULL;
  392. rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2);
  393. selftest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc);
  394. strings[1] = NULL;
  395. rc = of_property_read_string_array(np, "phandle-list-names", strings, 1);
  396. selftest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]);
  397. }
  398. #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
  399. (p1)->value && (p2)->value && \
  400. !memcmp((p1)->value, (p2)->value, (p1)->length) && \
  401. !strcmp((p1)->name, (p2)->name))
  402. static void __init of_selftest_property_copy(void)
  403. {
  404. #ifdef CONFIG_OF_DYNAMIC
  405. struct property p1 = { .name = "p1", .length = 0, .value = "" };
  406. struct property p2 = { .name = "p2", .length = 5, .value = "abcd" };
  407. struct property *new;
  408. new = __of_prop_dup(&p1, GFP_KERNEL);
  409. selftest(new && propcmp(&p1, new), "empty property didn't copy correctly\n");
  410. kfree(new->value);
  411. kfree(new->name);
  412. kfree(new);
  413. new = __of_prop_dup(&p2, GFP_KERNEL);
  414. selftest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
  415. kfree(new->value);
  416. kfree(new->name);
  417. kfree(new);
  418. #endif
  419. }
  420. static void __init of_selftest_changeset(void)
  421. {
  422. #ifdef CONFIG_OF_DYNAMIC
  423. struct property *ppadd, padd = { .name = "prop-add", .length = 0, .value = "" };
  424. struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" };
  425. struct property *ppremove;
  426. struct device_node *n1, *n2, *n21, *nremove, *parent, *np;
  427. struct of_changeset chgset;
  428. n1 = __of_node_dup(NULL, "/testcase-data/changeset/n1");
  429. selftest(n1, "testcase setup failure\n");
  430. n2 = __of_node_dup(NULL, "/testcase-data/changeset/n2");
  431. selftest(n2, "testcase setup failure\n");
  432. n21 = __of_node_dup(NULL, "%s/%s", "/testcase-data/changeset/n2", "n21");
  433. selftest(n21, "testcase setup failure %p\n", n21);
  434. nremove = of_find_node_by_path("/testcase-data/changeset/node-remove");
  435. selftest(nremove, "testcase setup failure\n");
  436. ppadd = __of_prop_dup(&padd, GFP_KERNEL);
  437. selftest(ppadd, "testcase setup failure\n");
  438. ppupdate = __of_prop_dup(&pupdate, GFP_KERNEL);
  439. selftest(ppupdate, "testcase setup failure\n");
  440. parent = nremove->parent;
  441. n1->parent = parent;
  442. n2->parent = parent;
  443. n21->parent = n2;
  444. n2->child = n21;
  445. ppremove = of_find_property(parent, "prop-remove", NULL);
  446. selftest(ppremove, "failed to find removal prop");
  447. of_changeset_init(&chgset);
  448. selftest(!of_changeset_attach_node(&chgset, n1), "fail attach n1\n");
  449. selftest(!of_changeset_attach_node(&chgset, n2), "fail attach n2\n");
  450. selftest(!of_changeset_detach_node(&chgset, nremove), "fail remove node\n");
  451. selftest(!of_changeset_attach_node(&chgset, n21), "fail attach n21\n");
  452. selftest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop\n");
  453. selftest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n");
  454. selftest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n");
  455. mutex_lock(&of_mutex);
  456. selftest(!of_changeset_apply(&chgset), "apply failed\n");
  457. mutex_unlock(&of_mutex);
  458. /* Make sure node names are constructed correctly */
  459. selftest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")),
  460. "'%s' not added\n", n21->full_name);
  461. of_node_put(np);
  462. mutex_lock(&of_mutex);
  463. selftest(!of_changeset_revert(&chgset), "revert failed\n");
  464. mutex_unlock(&of_mutex);
  465. of_changeset_destroy(&chgset);
  466. #endif
  467. }
  468. static void __init of_selftest_parse_interrupts(void)
  469. {
  470. struct device_node *np;
  471. struct of_phandle_args args;
  472. int i, rc;
  473. np = of_find_node_by_path("/testcase-data/interrupts/interrupts0");
  474. if (!np) {
  475. pr_err("missing testcase data\n");
  476. return;
  477. }
  478. for (i = 0; i < 4; i++) {
  479. bool passed = true;
  480. args.args_count = 0;
  481. rc = of_irq_parse_one(np, i, &args);
  482. passed &= !rc;
  483. passed &= (args.args_count == 1);
  484. passed &= (args.args[0] == (i + 1));
  485. selftest(passed, "index %i - data error on node %s rc=%i\n",
  486. i, args.np->full_name, rc);
  487. }
  488. of_node_put(np);
  489. np = of_find_node_by_path("/testcase-data/interrupts/interrupts1");
  490. if (!np) {
  491. pr_err("missing testcase data\n");
  492. return;
  493. }
  494. for (i = 0; i < 4; i++) {
  495. bool passed = true;
  496. args.args_count = 0;
  497. rc = of_irq_parse_one(np, i, &args);
  498. /* Test the values from tests-phandle.dtsi */
  499. switch (i) {
  500. case 0:
  501. passed &= !rc;
  502. passed &= (args.args_count == 1);
  503. passed &= (args.args[0] == 9);
  504. break;
  505. case 1:
  506. passed &= !rc;
  507. passed &= (args.args_count == 3);
  508. passed &= (args.args[0] == 10);
  509. passed &= (args.args[1] == 11);
  510. passed &= (args.args[2] == 12);
  511. break;
  512. case 2:
  513. passed &= !rc;
  514. passed &= (args.args_count == 2);
  515. passed &= (args.args[0] == 13);
  516. passed &= (args.args[1] == 14);
  517. break;
  518. case 3:
  519. passed &= !rc;
  520. passed &= (args.args_count == 2);
  521. passed &= (args.args[0] == 15);
  522. passed &= (args.args[1] == 16);
  523. break;
  524. default:
  525. passed = false;
  526. }
  527. selftest(passed, "index %i - data error on node %s rc=%i\n",
  528. i, args.np->full_name, rc);
  529. }
  530. of_node_put(np);
  531. }
  532. static void __init of_selftest_parse_interrupts_extended(void)
  533. {
  534. struct device_node *np;
  535. struct of_phandle_args args;
  536. int i, rc;
  537. np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
  538. if (!np) {
  539. pr_err("missing testcase data\n");
  540. return;
  541. }
  542. for (i = 0; i < 7; i++) {
  543. bool passed = true;
  544. rc = of_irq_parse_one(np, i, &args);
  545. /* Test the values from tests-phandle.dtsi */
  546. switch (i) {
  547. case 0:
  548. passed &= !rc;
  549. passed &= (args.args_count == 1);
  550. passed &= (args.args[0] == 1);
  551. break;
  552. case 1:
  553. passed &= !rc;
  554. passed &= (args.args_count == 3);
  555. passed &= (args.args[0] == 2);
  556. passed &= (args.args[1] == 3);
  557. passed &= (args.args[2] == 4);
  558. break;
  559. case 2:
  560. passed &= !rc;
  561. passed &= (args.args_count == 2);
  562. passed &= (args.args[0] == 5);
  563. passed &= (args.args[1] == 6);
  564. break;
  565. case 3:
  566. passed &= !rc;
  567. passed &= (args.args_count == 1);
  568. passed &= (args.args[0] == 9);
  569. break;
  570. case 4:
  571. passed &= !rc;
  572. passed &= (args.args_count == 3);
  573. passed &= (args.args[0] == 10);
  574. passed &= (args.args[1] == 11);
  575. passed &= (args.args[2] == 12);
  576. break;
  577. case 5:
  578. passed &= !rc;
  579. passed &= (args.args_count == 2);
  580. passed &= (args.args[0] == 13);
  581. passed &= (args.args[1] == 14);
  582. break;
  583. case 6:
  584. passed &= !rc;
  585. passed &= (args.args_count == 1);
  586. passed &= (args.args[0] == 15);
  587. break;
  588. default:
  589. passed = false;
  590. }
  591. selftest(passed, "index %i - data error on node %s rc=%i\n",
  592. i, args.np->full_name, rc);
  593. }
  594. of_node_put(np);
  595. }
  596. static const struct of_device_id match_node_table[] = {
  597. { .data = "A", .name = "name0", }, /* Name alone is lowest priority */
  598. { .data = "B", .type = "type1", }, /* followed by type alone */
  599. { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */
  600. { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */
  601. { .data = "Cc", .name = "name2", .type = "type2", },
  602. { .data = "E", .compatible = "compat3" },
  603. { .data = "G", .compatible = "compat2", },
  604. { .data = "H", .compatible = "compat2", .name = "name5", },
  605. { .data = "I", .compatible = "compat2", .type = "type1", },
  606. { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", },
  607. { .data = "K", .compatible = "compat2", .name = "name9", },
  608. {}
  609. };
  610. static struct {
  611. const char *path;
  612. const char *data;
  613. } match_node_tests[] = {
  614. { .path = "/testcase-data/match-node/name0", .data = "A", },
  615. { .path = "/testcase-data/match-node/name1", .data = "B", },
  616. { .path = "/testcase-data/match-node/a/name2", .data = "Ca", },
  617. { .path = "/testcase-data/match-node/b/name2", .data = "Cb", },
  618. { .path = "/testcase-data/match-node/c/name2", .data = "Cc", },
  619. { .path = "/testcase-data/match-node/name3", .data = "E", },
  620. { .path = "/testcase-data/match-node/name4", .data = "G", },
  621. { .path = "/testcase-data/match-node/name5", .data = "H", },
  622. { .path = "/testcase-data/match-node/name6", .data = "G", },
  623. { .path = "/testcase-data/match-node/name7", .data = "I", },
  624. { .path = "/testcase-data/match-node/name8", .data = "J", },
  625. { .path = "/testcase-data/match-node/name9", .data = "K", },
  626. };
  627. static void __init of_selftest_match_node(void)
  628. {
  629. struct device_node *np;
  630. const struct of_device_id *match;
  631. int i;
  632. for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) {
  633. np = of_find_node_by_path(match_node_tests[i].path);
  634. if (!np) {
  635. selftest(0, "missing testcase node %s\n",
  636. match_node_tests[i].path);
  637. continue;
  638. }
  639. match = of_match_node(match_node_table, np);
  640. if (!match) {
  641. selftest(0, "%s didn't match anything\n",
  642. match_node_tests[i].path);
  643. continue;
  644. }
  645. if (strcmp(match->data, match_node_tests[i].data) != 0) {
  646. selftest(0, "%s got wrong match. expected %s, got %s\n",
  647. match_node_tests[i].path, match_node_tests[i].data,
  648. (const char *)match->data);
  649. continue;
  650. }
  651. selftest(1, "passed");
  652. }
  653. }
  654. struct device test_bus = {
  655. .init_name = "unittest-bus",
  656. };
  657. static void __init of_selftest_platform_populate(void)
  658. {
  659. int irq, rc;
  660. struct device_node *np, *child, *grandchild;
  661. struct platform_device *pdev;
  662. const struct of_device_id match[] = {
  663. { .compatible = "test-device", },
  664. {}
  665. };
  666. np = of_find_node_by_path("/testcase-data");
  667. of_platform_populate(np, of_default_bus_match_table, NULL, NULL);
  668. /* Test that a missing irq domain returns -EPROBE_DEFER */
  669. np = of_find_node_by_path("/testcase-data/testcase-device1");
  670. pdev = of_find_device_by_node(np);
  671. selftest(pdev, "device 1 creation failed\n");
  672. irq = platform_get_irq(pdev, 0);
  673. selftest(irq == -EPROBE_DEFER, "device deferred probe failed - %d\n", irq);
  674. /* Test that a parsing failure does not return -EPROBE_DEFER */
  675. np = of_find_node_by_path("/testcase-data/testcase-device2");
  676. pdev = of_find_device_by_node(np);
  677. selftest(pdev, "device 2 creation failed\n");
  678. irq = platform_get_irq(pdev, 0);
  679. selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq);
  680. if (selftest(np = of_find_node_by_path("/testcase-data/platform-tests"),
  681. "No testcase data in device tree\n"));
  682. return;
  683. if (selftest(!(rc = device_register(&test_bus)),
  684. "testbus registration failed; rc=%i\n", rc));
  685. return;
  686. for_each_child_of_node(np, child) {
  687. of_platform_populate(child, match, NULL, &test_bus);
  688. for_each_child_of_node(child, grandchild)
  689. selftest(of_find_device_by_node(grandchild),
  690. "Could not create device for node '%s'\n",
  691. grandchild->name);
  692. }
  693. of_platform_depopulate(&test_bus);
  694. for_each_child_of_node(np, child) {
  695. for_each_child_of_node(child, grandchild)
  696. selftest(!of_find_device_by_node(grandchild),
  697. "device didn't get destroyed '%s'\n",
  698. grandchild->name);
  699. }
  700. device_unregister(&test_bus);
  701. of_node_put(np);
  702. }
  703. /**
  704. * update_node_properties - adds the properties
  705. * of np into dup node (present in live tree) and
  706. * updates parent of children of np to dup.
  707. *
  708. * @np: node already present in live tree
  709. * @dup: node present in live tree to be updated
  710. */
  711. static void update_node_properties(struct device_node *np,
  712. struct device_node *dup)
  713. {
  714. struct property *prop;
  715. struct device_node *child;
  716. for_each_property_of_node(np, prop)
  717. of_add_property(dup, prop);
  718. for_each_child_of_node(np, child)
  719. child->parent = dup;
  720. }
  721. /**
  722. * attach_node_and_children - attaches nodes
  723. * and its children to live tree
  724. *
  725. * @np: Node to attach to live tree
  726. */
  727. static int attach_node_and_children(struct device_node *np)
  728. {
  729. struct device_node *next, *dup, *child;
  730. unsigned long flags;
  731. dup = of_find_node_by_path(np->full_name);
  732. if (dup) {
  733. update_node_properties(np, dup);
  734. return 0;
  735. }
  736. child = np->child;
  737. np->child = NULL;
  738. mutex_lock(&of_mutex);
  739. raw_spin_lock_irqsave(&devtree_lock, flags);
  740. np->sibling = np->parent->child;
  741. np->parent->child = np;
  742. of_node_clear_flag(np, OF_DETACHED);
  743. raw_spin_unlock_irqrestore(&devtree_lock, flags);
  744. __of_attach_node_sysfs(np);
  745. mutex_unlock(&of_mutex);
  746. while (child) {
  747. next = child->sibling;
  748. attach_node_and_children(child);
  749. child = next;
  750. }
  751. return 0;
  752. }
  753. /**
  754. * selftest_data_add - Reads, copies data from
  755. * linked tree and attaches it to the live tree
  756. */
  757. static int __init selftest_data_add(void)
  758. {
  759. void *selftest_data;
  760. struct device_node *selftest_data_node, *np;
  761. extern uint8_t __dtb_testcases_begin[];
  762. extern uint8_t __dtb_testcases_end[];
  763. const int size = __dtb_testcases_end - __dtb_testcases_begin;
  764. int rc;
  765. if (!size) {
  766. pr_warn("%s: No testcase data to attach; not running tests\n",
  767. __func__);
  768. return -ENODATA;
  769. }
  770. /* creating copy */
  771. selftest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL);
  772. if (!selftest_data) {
  773. pr_warn("%s: Failed to allocate memory for selftest_data; "
  774. "not running tests\n", __func__);
  775. return -ENOMEM;
  776. }
  777. of_fdt_unflatten_tree(selftest_data, &selftest_data_node);
  778. if (!selftest_data_node) {
  779. pr_warn("%s: No tree to attach; not running tests\n", __func__);
  780. return -ENODATA;
  781. }
  782. of_node_set_flag(selftest_data_node, OF_DETACHED);
  783. rc = of_resolve_phandles(selftest_data_node);
  784. if (rc) {
  785. pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
  786. return -EINVAL;
  787. }
  788. if (!of_root) {
  789. of_root = selftest_data_node;
  790. for_each_of_allnodes(np)
  791. __of_attach_node_sysfs(np);
  792. of_aliases = of_find_node_by_path("/aliases");
  793. of_chosen = of_find_node_by_path("/chosen");
  794. return 0;
  795. }
  796. /* attach the sub-tree to live tree */
  797. np = selftest_data_node->child;
  798. while (np) {
  799. struct device_node *next = np->sibling;
  800. np->parent = of_root;
  801. attach_node_and_children(np);
  802. np = next;
  803. }
  804. return 0;
  805. }
  806. #ifdef CONFIG_OF_OVERLAY
  807. static int selftest_probe(struct platform_device *pdev)
  808. {
  809. struct device *dev = &pdev->dev;
  810. struct device_node *np = dev->of_node;
  811. if (np == NULL) {
  812. dev_err(dev, "No OF data for device\n");
  813. return -EINVAL;
  814. }
  815. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  816. of_platform_populate(np, NULL, NULL, &pdev->dev);
  817. return 0;
  818. }
  819. static int selftest_remove(struct platform_device *pdev)
  820. {
  821. struct device *dev = &pdev->dev;
  822. struct device_node *np = dev->of_node;
  823. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  824. return 0;
  825. }
  826. static const struct of_device_id selftest_match[] = {
  827. { .compatible = "selftest", },
  828. {},
  829. };
  830. static struct platform_driver selftest_driver = {
  831. .probe = selftest_probe,
  832. .remove = selftest_remove,
  833. .driver = {
  834. .name = "selftest",
  835. .owner = THIS_MODULE,
  836. .of_match_table = of_match_ptr(selftest_match),
  837. },
  838. };
  839. /* get the platform device instantiated at the path */
  840. static struct platform_device *of_path_to_platform_device(const char *path)
  841. {
  842. struct device_node *np;
  843. struct platform_device *pdev;
  844. np = of_find_node_by_path(path);
  845. if (np == NULL)
  846. return NULL;
  847. pdev = of_find_device_by_node(np);
  848. of_node_put(np);
  849. return pdev;
  850. }
  851. /* find out if a platform device exists at that path */
  852. static int of_path_platform_device_exists(const char *path)
  853. {
  854. struct platform_device *pdev;
  855. pdev = of_path_to_platform_device(path);
  856. platform_device_put(pdev);
  857. return pdev != NULL;
  858. }
  859. #if IS_BUILTIN(CONFIG_I2C)
  860. /* get the i2c client device instantiated at the path */
  861. static struct i2c_client *of_path_to_i2c_client(const char *path)
  862. {
  863. struct device_node *np;
  864. struct i2c_client *client;
  865. np = of_find_node_by_path(path);
  866. if (np == NULL)
  867. return NULL;
  868. client = of_find_i2c_device_by_node(np);
  869. of_node_put(np);
  870. return client;
  871. }
  872. /* find out if a i2c client device exists at that path */
  873. static int of_path_i2c_client_exists(const char *path)
  874. {
  875. struct i2c_client *client;
  876. client = of_path_to_i2c_client(path);
  877. if (client)
  878. put_device(&client->dev);
  879. return client != NULL;
  880. }
  881. #else
  882. static int of_path_i2c_client_exists(const char *path)
  883. {
  884. return 0;
  885. }
  886. #endif
  887. enum overlay_type {
  888. PDEV_OVERLAY,
  889. I2C_OVERLAY
  890. };
  891. static int of_path_device_type_exists(const char *path,
  892. enum overlay_type ovtype)
  893. {
  894. switch (ovtype) {
  895. case PDEV_OVERLAY:
  896. return of_path_platform_device_exists(path);
  897. case I2C_OVERLAY:
  898. return of_path_i2c_client_exists(path);
  899. }
  900. return 0;
  901. }
  902. static const char *selftest_path(int nr, enum overlay_type ovtype)
  903. {
  904. const char *base;
  905. static char buf[256];
  906. switch (ovtype) {
  907. case PDEV_OVERLAY:
  908. base = "/testcase-data/overlay-node/test-bus";
  909. break;
  910. case I2C_OVERLAY:
  911. base = "/testcase-data/overlay-node/test-bus/i2c-test-bus";
  912. break;
  913. default:
  914. buf[0] = '\0';
  915. return buf;
  916. }
  917. snprintf(buf, sizeof(buf) - 1, "%s/test-selftest%d", base, nr);
  918. buf[sizeof(buf) - 1] = '\0';
  919. return buf;
  920. }
  921. static int of_selftest_device_exists(int selftest_nr, enum overlay_type ovtype)
  922. {
  923. const char *path;
  924. path = selftest_path(selftest_nr, ovtype);
  925. switch (ovtype) {
  926. case PDEV_OVERLAY:
  927. return of_path_platform_device_exists(path);
  928. case I2C_OVERLAY:
  929. return of_path_i2c_client_exists(path);
  930. }
  931. return 0;
  932. }
  933. static const char *overlay_path(int nr)
  934. {
  935. static char buf[256];
  936. snprintf(buf, sizeof(buf) - 1,
  937. "/testcase-data/overlay%d", nr);
  938. buf[sizeof(buf) - 1] = '\0';
  939. return buf;
  940. }
  941. static const char *bus_path = "/testcase-data/overlay-node/test-bus";
  942. static int of_selftest_apply_overlay(int selftest_nr, int overlay_nr,
  943. int *overlay_id)
  944. {
  945. struct device_node *np = NULL;
  946. int ret, id = -1;
  947. np = of_find_node_by_path(overlay_path(overlay_nr));
  948. if (np == NULL) {
  949. selftest(0, "could not find overlay node @\"%s\"\n",
  950. overlay_path(overlay_nr));
  951. ret = -EINVAL;
  952. goto out;
  953. }
  954. ret = of_overlay_create(np);
  955. if (ret < 0) {
  956. selftest(0, "could not create overlay from \"%s\"\n",
  957. overlay_path(overlay_nr));
  958. goto out;
  959. }
  960. id = ret;
  961. ret = 0;
  962. out:
  963. of_node_put(np);
  964. if (overlay_id)
  965. *overlay_id = id;
  966. return ret;
  967. }
  968. /* apply an overlay while checking before and after states */
  969. static int of_selftest_apply_overlay_check(int overlay_nr, int selftest_nr,
  970. int before, int after, enum overlay_type ovtype)
  971. {
  972. int ret;
  973. /* selftest device must not be in before state */
  974. if (of_selftest_device_exists(selftest_nr, ovtype) != before) {
  975. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  976. overlay_path(overlay_nr),
  977. selftest_path(selftest_nr, ovtype),
  978. !before ? "enabled" : "disabled");
  979. return -EINVAL;
  980. }
  981. ret = of_selftest_apply_overlay(overlay_nr, selftest_nr, NULL);
  982. if (ret != 0) {
  983. /* of_selftest_apply_overlay already called selftest() */
  984. return ret;
  985. }
  986. /* selftest device must be to set to after state */
  987. if (of_selftest_device_exists(selftest_nr, ovtype) != after) {
  988. selftest(0, "overlay @\"%s\" failed to create @\"%s\" %s\n",
  989. overlay_path(overlay_nr),
  990. selftest_path(selftest_nr, ovtype),
  991. !after ? "enabled" : "disabled");
  992. return -EINVAL;
  993. }
  994. return 0;
  995. }
  996. /* apply an overlay and then revert it while checking before, after states */
  997. static int of_selftest_apply_revert_overlay_check(int overlay_nr,
  998. int selftest_nr, int before, int after,
  999. enum overlay_type ovtype)
  1000. {
  1001. int ret, ov_id;
  1002. /* selftest device must be in before state */
  1003. if (of_selftest_device_exists(selftest_nr, ovtype) != before) {
  1004. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  1005. overlay_path(overlay_nr),
  1006. selftest_path(selftest_nr, ovtype),
  1007. !before ? "enabled" : "disabled");
  1008. return -EINVAL;
  1009. }
  1010. /* apply the overlay */
  1011. ret = of_selftest_apply_overlay(overlay_nr, selftest_nr, &ov_id);
  1012. if (ret != 0) {
  1013. /* of_selftest_apply_overlay already called selftest() */
  1014. return ret;
  1015. }
  1016. /* selftest device must be in after state */
  1017. if (of_selftest_device_exists(selftest_nr, ovtype) != after) {
  1018. selftest(0, "overlay @\"%s\" failed to create @\"%s\" %s\n",
  1019. overlay_path(overlay_nr),
  1020. selftest_path(selftest_nr, ovtype),
  1021. !after ? "enabled" : "disabled");
  1022. return -EINVAL;
  1023. }
  1024. ret = of_overlay_destroy(ov_id);
  1025. if (ret != 0) {
  1026. selftest(0, "overlay @\"%s\" failed to be destroyed @\"%s\"\n",
  1027. overlay_path(overlay_nr),
  1028. selftest_path(selftest_nr, ovtype));
  1029. return ret;
  1030. }
  1031. /* selftest device must be again in before state */
  1032. if (of_selftest_device_exists(selftest_nr, PDEV_OVERLAY) != before) {
  1033. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  1034. overlay_path(overlay_nr),
  1035. selftest_path(selftest_nr, ovtype),
  1036. !before ? "enabled" : "disabled");
  1037. return -EINVAL;
  1038. }
  1039. return 0;
  1040. }
  1041. /* test activation of device */
  1042. static void of_selftest_overlay_0(void)
  1043. {
  1044. int ret;
  1045. /* device should enable */
  1046. ret = of_selftest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY);
  1047. if (ret != 0)
  1048. return;
  1049. selftest(1, "overlay test %d passed\n", 0);
  1050. }
  1051. /* test deactivation of device */
  1052. static void of_selftest_overlay_1(void)
  1053. {
  1054. int ret;
  1055. /* device should disable */
  1056. ret = of_selftest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY);
  1057. if (ret != 0)
  1058. return;
  1059. selftest(1, "overlay test %d passed\n", 1);
  1060. }
  1061. /* test activation of device */
  1062. static void of_selftest_overlay_2(void)
  1063. {
  1064. int ret;
  1065. /* device should enable */
  1066. ret = of_selftest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY);
  1067. if (ret != 0)
  1068. return;
  1069. selftest(1, "overlay test %d passed\n", 2);
  1070. }
  1071. /* test deactivation of device */
  1072. static void of_selftest_overlay_3(void)
  1073. {
  1074. int ret;
  1075. /* device should disable */
  1076. ret = of_selftest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY);
  1077. if (ret != 0)
  1078. return;
  1079. selftest(1, "overlay test %d passed\n", 3);
  1080. }
  1081. /* test activation of a full device node */
  1082. static void of_selftest_overlay_4(void)
  1083. {
  1084. int ret;
  1085. /* device should disable */
  1086. ret = of_selftest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY);
  1087. if (ret != 0)
  1088. return;
  1089. selftest(1, "overlay test %d passed\n", 4);
  1090. }
  1091. /* test overlay apply/revert sequence */
  1092. static void of_selftest_overlay_5(void)
  1093. {
  1094. int ret;
  1095. /* device should disable */
  1096. ret = of_selftest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY);
  1097. if (ret != 0)
  1098. return;
  1099. selftest(1, "overlay test %d passed\n", 5);
  1100. }
  1101. /* test overlay application in sequence */
  1102. static void of_selftest_overlay_6(void)
  1103. {
  1104. struct device_node *np;
  1105. int ret, i, ov_id[2];
  1106. int overlay_nr = 6, selftest_nr = 6;
  1107. int before = 0, after = 1;
  1108. /* selftest device must be in before state */
  1109. for (i = 0; i < 2; i++) {
  1110. if (of_selftest_device_exists(selftest_nr + i, PDEV_OVERLAY)
  1111. != before) {
  1112. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  1113. overlay_path(overlay_nr + i),
  1114. selftest_path(selftest_nr + i,
  1115. PDEV_OVERLAY),
  1116. !before ? "enabled" : "disabled");
  1117. return;
  1118. }
  1119. }
  1120. /* apply the overlays */
  1121. for (i = 0; i < 2; i++) {
  1122. np = of_find_node_by_path(overlay_path(overlay_nr + i));
  1123. if (np == NULL) {
  1124. selftest(0, "could not find overlay node @\"%s\"\n",
  1125. overlay_path(overlay_nr + i));
  1126. return;
  1127. }
  1128. ret = of_overlay_create(np);
  1129. if (ret < 0) {
  1130. selftest(0, "could not create overlay from \"%s\"\n",
  1131. overlay_path(overlay_nr + i));
  1132. return;
  1133. }
  1134. ov_id[i] = ret;
  1135. }
  1136. for (i = 0; i < 2; i++) {
  1137. /* selftest device must be in after state */
  1138. if (of_selftest_device_exists(selftest_nr + i, PDEV_OVERLAY)
  1139. != after) {
  1140. selftest(0, "overlay @\"%s\" failed @\"%s\" %s\n",
  1141. overlay_path(overlay_nr + i),
  1142. selftest_path(selftest_nr + i,
  1143. PDEV_OVERLAY),
  1144. !after ? "enabled" : "disabled");
  1145. return;
  1146. }
  1147. }
  1148. for (i = 1; i >= 0; i--) {
  1149. ret = of_overlay_destroy(ov_id[i]);
  1150. if (ret != 0) {
  1151. selftest(0, "overlay @\"%s\" failed destroy @\"%s\"\n",
  1152. overlay_path(overlay_nr + i),
  1153. selftest_path(selftest_nr + i,
  1154. PDEV_OVERLAY));
  1155. return;
  1156. }
  1157. }
  1158. for (i = 0; i < 2; i++) {
  1159. /* selftest device must be again in before state */
  1160. if (of_selftest_device_exists(selftest_nr + i, PDEV_OVERLAY)
  1161. != before) {
  1162. selftest(0, "overlay @\"%s\" with device @\"%s\" %s\n",
  1163. overlay_path(overlay_nr + i),
  1164. selftest_path(selftest_nr + i,
  1165. PDEV_OVERLAY),
  1166. !before ? "enabled" : "disabled");
  1167. return;
  1168. }
  1169. }
  1170. selftest(1, "overlay test %d passed\n", 6);
  1171. }
  1172. /* test overlay application in sequence */
  1173. static void of_selftest_overlay_8(void)
  1174. {
  1175. struct device_node *np;
  1176. int ret, i, ov_id[2];
  1177. int overlay_nr = 8, selftest_nr = 8;
  1178. /* we don't care about device state in this test */
  1179. /* apply the overlays */
  1180. for (i = 0; i < 2; i++) {
  1181. np = of_find_node_by_path(overlay_path(overlay_nr + i));
  1182. if (np == NULL) {
  1183. selftest(0, "could not find overlay node @\"%s\"\n",
  1184. overlay_path(overlay_nr + i));
  1185. return;
  1186. }
  1187. ret = of_overlay_create(np);
  1188. if (ret < 0) {
  1189. selftest(0, "could not create overlay from \"%s\"\n",
  1190. overlay_path(overlay_nr + i));
  1191. return;
  1192. }
  1193. ov_id[i] = ret;
  1194. }
  1195. /* now try to remove first overlay (it should fail) */
  1196. ret = of_overlay_destroy(ov_id[0]);
  1197. if (ret == 0) {
  1198. selftest(0, "overlay @\"%s\" was destroyed @\"%s\"\n",
  1199. overlay_path(overlay_nr + 0),
  1200. selftest_path(selftest_nr,
  1201. PDEV_OVERLAY));
  1202. return;
  1203. }
  1204. /* removing them in order should work */
  1205. for (i = 1; i >= 0; i--) {
  1206. ret = of_overlay_destroy(ov_id[i]);
  1207. if (ret != 0) {
  1208. selftest(0, "overlay @\"%s\" not destroyed @\"%s\"\n",
  1209. overlay_path(overlay_nr + i),
  1210. selftest_path(selftest_nr,
  1211. PDEV_OVERLAY));
  1212. return;
  1213. }
  1214. }
  1215. selftest(1, "overlay test %d passed\n", 8);
  1216. }
  1217. /* test insertion of a bus with parent devices */
  1218. static void of_selftest_overlay_10(void)
  1219. {
  1220. int ret;
  1221. char *child_path;
  1222. /* device should disable */
  1223. ret = of_selftest_apply_overlay_check(10, 10, 0, 1, PDEV_OVERLAY);
  1224. if (selftest(ret == 0,
  1225. "overlay test %d failed; overlay application\n", 10))
  1226. return;
  1227. child_path = kasprintf(GFP_KERNEL, "%s/test-selftest101",
  1228. selftest_path(10, PDEV_OVERLAY));
  1229. if (selftest(child_path, "overlay test %d failed; kasprintf\n", 10))
  1230. return;
  1231. ret = of_path_device_type_exists(child_path, PDEV_OVERLAY);
  1232. kfree(child_path);
  1233. if (selftest(ret, "overlay test %d failed; no child device\n", 10))
  1234. return;
  1235. }
  1236. /* test insertion of a bus with parent devices (and revert) */
  1237. static void of_selftest_overlay_11(void)
  1238. {
  1239. int ret;
  1240. /* device should disable */
  1241. ret = of_selftest_apply_revert_overlay_check(11, 11, 0, 1,
  1242. PDEV_OVERLAY);
  1243. if (selftest(ret == 0,
  1244. "overlay test %d failed; overlay application\n", 11))
  1245. return;
  1246. }
  1247. #if IS_BUILTIN(CONFIG_I2C) && IS_ENABLED(CONFIG_OF_OVERLAY)
  1248. struct selftest_i2c_bus_data {
  1249. struct platform_device *pdev;
  1250. struct i2c_adapter adap;
  1251. };
  1252. static int selftest_i2c_master_xfer(struct i2c_adapter *adap,
  1253. struct i2c_msg *msgs, int num)
  1254. {
  1255. struct selftest_i2c_bus_data *std = i2c_get_adapdata(adap);
  1256. (void)std;
  1257. return num;
  1258. }
  1259. static u32 selftest_i2c_functionality(struct i2c_adapter *adap)
  1260. {
  1261. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  1262. }
  1263. static const struct i2c_algorithm selftest_i2c_algo = {
  1264. .master_xfer = selftest_i2c_master_xfer,
  1265. .functionality = selftest_i2c_functionality,
  1266. };
  1267. static int selftest_i2c_bus_probe(struct platform_device *pdev)
  1268. {
  1269. struct device *dev = &pdev->dev;
  1270. struct device_node *np = dev->of_node;
  1271. struct selftest_i2c_bus_data *std;
  1272. struct i2c_adapter *adap;
  1273. int ret;
  1274. if (np == NULL) {
  1275. dev_err(dev, "No OF data for device\n");
  1276. return -EINVAL;
  1277. }
  1278. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1279. std = devm_kzalloc(dev, sizeof(*std), GFP_KERNEL);
  1280. if (!std) {
  1281. dev_err(dev, "Failed to allocate selftest i2c data\n");
  1282. return -ENOMEM;
  1283. }
  1284. /* link them together */
  1285. std->pdev = pdev;
  1286. platform_set_drvdata(pdev, std);
  1287. adap = &std->adap;
  1288. i2c_set_adapdata(adap, std);
  1289. adap->nr = -1;
  1290. strlcpy(adap->name, pdev->name, sizeof(adap->name));
  1291. adap->class = I2C_CLASS_DEPRECATED;
  1292. adap->algo = &selftest_i2c_algo;
  1293. adap->dev.parent = dev;
  1294. adap->dev.of_node = dev->of_node;
  1295. adap->timeout = 5 * HZ;
  1296. adap->retries = 3;
  1297. ret = i2c_add_numbered_adapter(adap);
  1298. if (ret != 0) {
  1299. dev_err(dev, "Failed to add I2C adapter\n");
  1300. return ret;
  1301. }
  1302. return 0;
  1303. }
  1304. static int selftest_i2c_bus_remove(struct platform_device *pdev)
  1305. {
  1306. struct device *dev = &pdev->dev;
  1307. struct device_node *np = dev->of_node;
  1308. struct selftest_i2c_bus_data *std = platform_get_drvdata(pdev);
  1309. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1310. i2c_del_adapter(&std->adap);
  1311. return 0;
  1312. }
  1313. static const struct of_device_id selftest_i2c_bus_match[] = {
  1314. { .compatible = "selftest-i2c-bus", },
  1315. {},
  1316. };
  1317. static struct platform_driver selftest_i2c_bus_driver = {
  1318. .probe = selftest_i2c_bus_probe,
  1319. .remove = selftest_i2c_bus_remove,
  1320. .driver = {
  1321. .name = "selftest-i2c-bus",
  1322. .of_match_table = of_match_ptr(selftest_i2c_bus_match),
  1323. },
  1324. };
  1325. static int selftest_i2c_dev_probe(struct i2c_client *client,
  1326. const struct i2c_device_id *id)
  1327. {
  1328. struct device *dev = &client->dev;
  1329. struct device_node *np = client->dev.of_node;
  1330. if (!np) {
  1331. dev_err(dev, "No OF node\n");
  1332. return -EINVAL;
  1333. }
  1334. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1335. return 0;
  1336. };
  1337. static int selftest_i2c_dev_remove(struct i2c_client *client)
  1338. {
  1339. struct device *dev = &client->dev;
  1340. struct device_node *np = client->dev.of_node;
  1341. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1342. return 0;
  1343. }
  1344. static const struct i2c_device_id selftest_i2c_dev_id[] = {
  1345. { .name = "selftest-i2c-dev" },
  1346. { }
  1347. };
  1348. static struct i2c_driver selftest_i2c_dev_driver = {
  1349. .driver = {
  1350. .name = "selftest-i2c-dev",
  1351. .owner = THIS_MODULE,
  1352. },
  1353. .probe = selftest_i2c_dev_probe,
  1354. .remove = selftest_i2c_dev_remove,
  1355. .id_table = selftest_i2c_dev_id,
  1356. };
  1357. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1358. struct selftest_i2c_mux_data {
  1359. int nchans;
  1360. struct i2c_adapter *adap[];
  1361. };
  1362. static int selftest_i2c_mux_select_chan(struct i2c_adapter *adap,
  1363. void *client, u32 chan)
  1364. {
  1365. return 0;
  1366. }
  1367. static int selftest_i2c_mux_probe(struct i2c_client *client,
  1368. const struct i2c_device_id *id)
  1369. {
  1370. int ret, i, nchans, size;
  1371. struct device *dev = &client->dev;
  1372. struct i2c_adapter *adap = to_i2c_adapter(dev->parent);
  1373. struct device_node *np = client->dev.of_node, *child;
  1374. struct selftest_i2c_mux_data *stm;
  1375. u32 reg, max_reg;
  1376. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1377. if (!np) {
  1378. dev_err(dev, "No OF node\n");
  1379. return -EINVAL;
  1380. }
  1381. max_reg = (u32)-1;
  1382. for_each_child_of_node(np, child) {
  1383. ret = of_property_read_u32(child, "reg", &reg);
  1384. if (ret)
  1385. continue;
  1386. if (max_reg == (u32)-1 || reg > max_reg)
  1387. max_reg = reg;
  1388. }
  1389. nchans = max_reg == (u32)-1 ? 0 : max_reg + 1;
  1390. if (nchans == 0) {
  1391. dev_err(dev, "No channels\n");
  1392. return -EINVAL;
  1393. }
  1394. size = offsetof(struct selftest_i2c_mux_data, adap[nchans]);
  1395. stm = devm_kzalloc(dev, size, GFP_KERNEL);
  1396. if (!stm) {
  1397. dev_err(dev, "Out of memory\n");
  1398. return -ENOMEM;
  1399. }
  1400. stm->nchans = nchans;
  1401. for (i = 0; i < nchans; i++) {
  1402. stm->adap[i] = i2c_add_mux_adapter(adap, dev, client,
  1403. 0, i, 0, selftest_i2c_mux_select_chan, NULL);
  1404. if (!stm->adap[i]) {
  1405. dev_err(dev, "Failed to register mux #%d\n", i);
  1406. for (i--; i >= 0; i--)
  1407. i2c_del_mux_adapter(stm->adap[i]);
  1408. return -ENODEV;
  1409. }
  1410. }
  1411. i2c_set_clientdata(client, stm);
  1412. return 0;
  1413. };
  1414. static int selftest_i2c_mux_remove(struct i2c_client *client)
  1415. {
  1416. struct device *dev = &client->dev;
  1417. struct device_node *np = client->dev.of_node;
  1418. struct selftest_i2c_mux_data *stm = i2c_get_clientdata(client);
  1419. int i;
  1420. dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
  1421. for (i = stm->nchans - 1; i >= 0; i--)
  1422. i2c_del_mux_adapter(stm->adap[i]);
  1423. return 0;
  1424. }
  1425. static const struct i2c_device_id selftest_i2c_mux_id[] = {
  1426. { .name = "selftest-i2c-mux" },
  1427. { }
  1428. };
  1429. static struct i2c_driver selftest_i2c_mux_driver = {
  1430. .driver = {
  1431. .name = "selftest-i2c-mux",
  1432. .owner = THIS_MODULE,
  1433. },
  1434. .probe = selftest_i2c_mux_probe,
  1435. .remove = selftest_i2c_mux_remove,
  1436. .id_table = selftest_i2c_mux_id,
  1437. };
  1438. #endif
  1439. static int of_selftest_overlay_i2c_init(void)
  1440. {
  1441. int ret;
  1442. ret = i2c_add_driver(&selftest_i2c_dev_driver);
  1443. if (selftest(ret == 0,
  1444. "could not register selftest i2c device driver\n"))
  1445. return ret;
  1446. ret = platform_driver_register(&selftest_i2c_bus_driver);
  1447. if (selftest(ret == 0,
  1448. "could not register selftest i2c bus driver\n"))
  1449. return ret;
  1450. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1451. ret = i2c_add_driver(&selftest_i2c_mux_driver);
  1452. if (selftest(ret == 0,
  1453. "could not register selftest i2c mux driver\n"))
  1454. return ret;
  1455. #endif
  1456. return 0;
  1457. }
  1458. static void of_selftest_overlay_i2c_cleanup(void)
  1459. {
  1460. #if IS_BUILTIN(CONFIG_I2C_MUX)
  1461. i2c_del_driver(&selftest_i2c_mux_driver);
  1462. #endif
  1463. platform_driver_unregister(&selftest_i2c_bus_driver);
  1464. i2c_del_driver(&selftest_i2c_dev_driver);
  1465. }
  1466. static void of_selftest_overlay_i2c_12(void)
  1467. {
  1468. int ret;
  1469. /* device should enable */
  1470. ret = of_selftest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY);
  1471. if (ret != 0)
  1472. return;
  1473. selftest(1, "overlay test %d passed\n", 12);
  1474. }
  1475. /* test deactivation of device */
  1476. static void of_selftest_overlay_i2c_13(void)
  1477. {
  1478. int ret;
  1479. /* device should disable */
  1480. ret = of_selftest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY);
  1481. if (ret != 0)
  1482. return;
  1483. selftest(1, "overlay test %d passed\n", 13);
  1484. }
  1485. /* just check for i2c mux existence */
  1486. static void of_selftest_overlay_i2c_14(void)
  1487. {
  1488. }
  1489. static void of_selftest_overlay_i2c_15(void)
  1490. {
  1491. int ret;
  1492. /* device should enable */
  1493. ret = of_selftest_apply_overlay_check(16, 15, 0, 1, I2C_OVERLAY);
  1494. if (ret != 0)
  1495. return;
  1496. selftest(1, "overlay test %d passed\n", 15);
  1497. }
  1498. #else
  1499. static inline void of_selftest_overlay_i2c_14(void) { }
  1500. static inline void of_selftest_overlay_i2c_15(void) { }
  1501. #endif
  1502. static void __init of_selftest_overlay(void)
  1503. {
  1504. struct device_node *bus_np = NULL;
  1505. int ret;
  1506. ret = platform_driver_register(&selftest_driver);
  1507. if (ret != 0) {
  1508. selftest(0, "could not register selftest driver\n");
  1509. goto out;
  1510. }
  1511. bus_np = of_find_node_by_path(bus_path);
  1512. if (bus_np == NULL) {
  1513. selftest(0, "could not find bus_path \"%s\"\n", bus_path);
  1514. goto out;
  1515. }
  1516. ret = of_platform_populate(bus_np, of_default_bus_match_table,
  1517. NULL, NULL);
  1518. if (ret != 0) {
  1519. selftest(0, "could not populate bus @ \"%s\"\n", bus_path);
  1520. goto out;
  1521. }
  1522. if (!of_selftest_device_exists(100, PDEV_OVERLAY)) {
  1523. selftest(0, "could not find selftest0 @ \"%s\"\n",
  1524. selftest_path(100, PDEV_OVERLAY));
  1525. goto out;
  1526. }
  1527. if (of_selftest_device_exists(101, PDEV_OVERLAY)) {
  1528. selftest(0, "selftest1 @ \"%s\" should not exist\n",
  1529. selftest_path(101, PDEV_OVERLAY));
  1530. goto out;
  1531. }
  1532. selftest(1, "basic infrastructure of overlays passed");
  1533. /* tests in sequence */
  1534. of_selftest_overlay_0();
  1535. of_selftest_overlay_1();
  1536. of_selftest_overlay_2();
  1537. of_selftest_overlay_3();
  1538. of_selftest_overlay_4();
  1539. of_selftest_overlay_5();
  1540. of_selftest_overlay_6();
  1541. of_selftest_overlay_8();
  1542. of_selftest_overlay_10();
  1543. of_selftest_overlay_11();
  1544. #if IS_BUILTIN(CONFIG_I2C)
  1545. if (selftest(of_selftest_overlay_i2c_init() == 0, "i2c init failed\n"))
  1546. goto out;
  1547. of_selftest_overlay_i2c_12();
  1548. of_selftest_overlay_i2c_13();
  1549. of_selftest_overlay_i2c_14();
  1550. of_selftest_overlay_i2c_15();
  1551. of_selftest_overlay_i2c_cleanup();
  1552. #endif
  1553. out:
  1554. of_node_put(bus_np);
  1555. }
  1556. #else
  1557. static inline void __init of_selftest_overlay(void) { }
  1558. #endif
  1559. static int __init of_selftest(void)
  1560. {
  1561. struct device_node *np;
  1562. int res;
  1563. /* adding data for selftest */
  1564. res = selftest_data_add();
  1565. if (res)
  1566. return res;
  1567. if (!of_aliases)
  1568. of_aliases = of_find_node_by_path("/aliases");
  1569. np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
  1570. if (!np) {
  1571. pr_info("No testcase data in device tree; not running tests\n");
  1572. return 0;
  1573. }
  1574. of_node_put(np);
  1575. pr_info("start of selftest - you will see error messages\n");
  1576. of_selftest_check_tree_linkage();
  1577. of_selftest_check_phandles();
  1578. of_selftest_find_node_by_name();
  1579. of_selftest_dynamic();
  1580. of_selftest_parse_phandle_with_args();
  1581. of_selftest_property_string();
  1582. of_selftest_property_copy();
  1583. of_selftest_changeset();
  1584. of_selftest_parse_interrupts();
  1585. of_selftest_parse_interrupts_extended();
  1586. of_selftest_match_node();
  1587. of_selftest_platform_populate();
  1588. of_selftest_overlay();
  1589. /* Double check linkage after removing testcase data */
  1590. of_selftest_check_tree_linkage();
  1591. pr_info("end of selftest - %i passed, %i failed\n",
  1592. selftest_results.passed, selftest_results.failed);
  1593. return 0;
  1594. }
  1595. late_initcall(of_selftest);