checks.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2007.
  4. */
  5. #include "dtc.h"
  6. #include "srcpos.h"
  7. #ifdef TRACE_CHECKS
  8. #define TRACE(c, ...) \
  9. do { \
  10. fprintf(stderr, "=== %s: ", (c)->name); \
  11. fprintf(stderr, __VA_ARGS__); \
  12. fprintf(stderr, "\n"); \
  13. } while (0)
  14. #else
  15. #define TRACE(c, fmt, ...) do { } while (0)
  16. #endif
  17. enum checkstatus {
  18. UNCHECKED = 0,
  19. PREREQ,
  20. PASSED,
  21. FAILED,
  22. };
  23. struct check;
  24. typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *node);
  25. struct check {
  26. const char *name;
  27. check_fn fn;
  28. void *data;
  29. bool warn, error;
  30. enum checkstatus status;
  31. bool inprogress;
  32. int num_prereqs;
  33. struct check **prereq;
  34. };
  35. #define CHECK_ENTRY(nm_, fn_, d_, w_, e_, ...) \
  36. static struct check *nm_##_prereqs[] = { __VA_ARGS__ }; \
  37. static struct check nm_ = { \
  38. .name = #nm_, \
  39. .fn = (fn_), \
  40. .data = (d_), \
  41. .warn = (w_), \
  42. .error = (e_), \
  43. .status = UNCHECKED, \
  44. .num_prereqs = ARRAY_SIZE(nm_##_prereqs), \
  45. .prereq = nm_##_prereqs, \
  46. };
  47. #define WARNING(nm_, fn_, d_, ...) \
  48. CHECK_ENTRY(nm_, fn_, d_, true, false, __VA_ARGS__)
  49. #define ERROR(nm_, fn_, d_, ...) \
  50. CHECK_ENTRY(nm_, fn_, d_, false, true, __VA_ARGS__)
  51. #define CHECK(nm_, fn_, d_, ...) \
  52. CHECK_ENTRY(nm_, fn_, d_, false, false, __VA_ARGS__)
  53. static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti,
  54. struct node *node,
  55. struct property *prop,
  56. const char *fmt, ...)
  57. {
  58. va_list ap;
  59. char *str = NULL;
  60. struct srcpos *pos = NULL;
  61. char *file_str;
  62. if (!(c->warn && (quiet < 1)) && !(c->error && (quiet < 2)))
  63. return;
  64. if (prop && prop->srcpos)
  65. pos = prop->srcpos;
  66. else if (node && node->srcpos)
  67. pos = node->srcpos;
  68. if (pos) {
  69. file_str = srcpos_string(pos);
  70. xasprintf(&str, "%s", file_str);
  71. free(file_str);
  72. } else if (streq(dti->outname, "-")) {
  73. xasprintf(&str, "<stdout>");
  74. } else {
  75. xasprintf(&str, "%s", dti->outname);
  76. }
  77. xasprintf_append(&str, ": %s (%s): ",
  78. (c->error) ? "ERROR" : "Warning", c->name);
  79. if (node) {
  80. if (prop)
  81. xasprintf_append(&str, "%s:%s: ", node->fullpath, prop->name);
  82. else
  83. xasprintf_append(&str, "%s: ", node->fullpath);
  84. }
  85. va_start(ap, fmt);
  86. xavsprintf_append(&str, fmt, ap);
  87. va_end(ap);
  88. xasprintf_append(&str, "\n");
  89. if (!prop && pos) {
  90. pos = node->srcpos;
  91. while (pos->next) {
  92. pos = pos->next;
  93. file_str = srcpos_string(pos);
  94. xasprintf_append(&str, " also defined at %s\n", file_str);
  95. free(file_str);
  96. }
  97. }
  98. fputs(str, stderr);
  99. }
  100. #define FAIL(c, dti, node, ...) \
  101. do { \
  102. TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
  103. (c)->status = FAILED; \
  104. check_msg((c), dti, node, NULL, __VA_ARGS__); \
  105. } while (0)
  106. #define FAIL_PROP(c, dti, node, prop, ...) \
  107. do { \
  108. TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
  109. (c)->status = FAILED; \
  110. check_msg((c), dti, node, prop, __VA_ARGS__); \
  111. } while (0)
  112. static void check_nodes_props(struct check *c, struct dt_info *dti, struct node *node)
  113. {
  114. struct node *child;
  115. TRACE(c, "%s", node->fullpath);
  116. if (c->fn)
  117. c->fn(c, dti, node);
  118. for_each_child(node, child)
  119. check_nodes_props(c, dti, child);
  120. }
  121. static bool is_multiple_of(int multiple, int divisor)
  122. {
  123. if (divisor == 0)
  124. return multiple == 0;
  125. else
  126. return (multiple % divisor) == 0;
  127. }
  128. static bool run_check(struct check *c, struct dt_info *dti)
  129. {
  130. struct node *dt = dti->dt;
  131. bool error = false;
  132. int i;
  133. assert(!c->inprogress);
  134. if (c->status != UNCHECKED)
  135. goto out;
  136. c->inprogress = true;
  137. for (i = 0; i < c->num_prereqs; i++) {
  138. struct check *prq = c->prereq[i];
  139. error = error || run_check(prq, dti);
  140. if (prq->status != PASSED) {
  141. c->status = PREREQ;
  142. check_msg(c, dti, NULL, NULL, "Failed prerequisite '%s'",
  143. c->prereq[i]->name);
  144. }
  145. }
  146. if (c->status != UNCHECKED)
  147. goto out;
  148. check_nodes_props(c, dti, dt);
  149. if (c->status == UNCHECKED)
  150. c->status = PASSED;
  151. TRACE(c, "\tCompleted, status %d", c->status);
  152. out:
  153. c->inprogress = false;
  154. if ((c->status != PASSED) && (c->error))
  155. error = true;
  156. return error;
  157. }
  158. /*
  159. * Utility check functions
  160. */
  161. /* A check which always fails, for testing purposes only */
  162. static inline void check_always_fail(struct check *c, struct dt_info *dti,
  163. struct node *node)
  164. {
  165. FAIL(c, dti, node, "always_fail check");
  166. }
  167. CHECK(always_fail, check_always_fail, NULL);
  168. static void check_is_string(struct check *c, struct dt_info *dti,
  169. struct node *node)
  170. {
  171. struct property *prop;
  172. char *propname = c->data;
  173. prop = get_property(node, propname);
  174. if (!prop)
  175. return; /* Not present, assumed ok */
  176. if (!data_is_one_string(prop->val))
  177. FAIL_PROP(c, dti, node, prop, "property is not a string");
  178. }
  179. #define WARNING_IF_NOT_STRING(nm, propname) \
  180. WARNING(nm, check_is_string, (propname))
  181. #define ERROR_IF_NOT_STRING(nm, propname) \
  182. ERROR(nm, check_is_string, (propname))
  183. static void check_is_string_list(struct check *c, struct dt_info *dti,
  184. struct node *node)
  185. {
  186. int rem, l;
  187. struct property *prop;
  188. char *propname = c->data;
  189. char *str;
  190. prop = get_property(node, propname);
  191. if (!prop)
  192. return; /* Not present, assumed ok */
  193. str = prop->val.val;
  194. rem = prop->val.len;
  195. while (rem > 0) {
  196. l = strnlen(str, rem);
  197. if (l == rem) {
  198. FAIL_PROP(c, dti, node, prop, "property is not a string list");
  199. break;
  200. }
  201. rem -= l + 1;
  202. str += l + 1;
  203. }
  204. }
  205. #define WARNING_IF_NOT_STRING_LIST(nm, propname) \
  206. WARNING(nm, check_is_string_list, (propname))
  207. #define ERROR_IF_NOT_STRING_LIST(nm, propname) \
  208. ERROR(nm, check_is_string_list, (propname))
  209. static void check_is_cell(struct check *c, struct dt_info *dti,
  210. struct node *node)
  211. {
  212. struct property *prop;
  213. char *propname = c->data;
  214. prop = get_property(node, propname);
  215. if (!prop)
  216. return; /* Not present, assumed ok */
  217. if (prop->val.len != sizeof(cell_t))
  218. FAIL_PROP(c, dti, node, prop, "property is not a single cell");
  219. }
  220. #define WARNING_IF_NOT_CELL(nm, propname) \
  221. WARNING(nm, check_is_cell, (propname))
  222. #define ERROR_IF_NOT_CELL(nm, propname) \
  223. ERROR(nm, check_is_cell, (propname))
  224. /*
  225. * Structural check functions
  226. */
  227. static void check_duplicate_node_names(struct check *c, struct dt_info *dti,
  228. struct node *node)
  229. {
  230. struct node *child, *child2;
  231. for_each_child(node, child)
  232. for (child2 = child->next_sibling;
  233. child2;
  234. child2 = child2->next_sibling)
  235. if (streq(child->name, child2->name))
  236. FAIL(c, dti, child2, "Duplicate node name");
  237. }
  238. ERROR(duplicate_node_names, check_duplicate_node_names, NULL);
  239. static void check_duplicate_property_names(struct check *c, struct dt_info *dti,
  240. struct node *node)
  241. {
  242. struct property *prop, *prop2;
  243. for_each_property(node, prop) {
  244. for (prop2 = prop->next; prop2; prop2 = prop2->next) {
  245. if (prop2->deleted)
  246. continue;
  247. if (streq(prop->name, prop2->name))
  248. FAIL_PROP(c, dti, node, prop, "Duplicate property name");
  249. }
  250. }
  251. }
  252. ERROR(duplicate_property_names, check_duplicate_property_names, NULL);
  253. #define LOWERCASE "abcdefghijklmnopqrstuvwxyz"
  254. #define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  255. #define DIGITS "0123456789"
  256. #define NODECHARS LOWERCASE UPPERCASE DIGITS ",._+-@"
  257. #define PROPCHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
  258. #define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-"
  259. static void check_node_name_chars(struct check *c, struct dt_info *dti,
  260. struct node *node)
  261. {
  262. size_t n = strspn(node->name, c->data);
  263. if (n < strlen(node->name))
  264. FAIL(c, dti, node, "Bad character '%c' in node name",
  265. node->name[n]);
  266. }
  267. ERROR(node_name_chars, check_node_name_chars, NODECHARS);
  268. static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
  269. struct node *node)
  270. {
  271. int n = strspn(node->name, c->data);
  272. if (n < node->basenamelen)
  273. FAIL(c, dti, node, "Character '%c' not recommended in node name",
  274. node->name[n]);
  275. }
  276. CHECK(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT);
  277. static void check_node_name_format(struct check *c, struct dt_info *dti,
  278. struct node *node)
  279. {
  280. if (strchr(get_unitname(node), '@'))
  281. FAIL(c, dti, node, "multiple '@' characters in node name");
  282. }
  283. ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars);
  284. static void check_node_name_vs_property_name(struct check *c,
  285. struct dt_info *dti,
  286. struct node *node)
  287. {
  288. if (!node->parent)
  289. return;
  290. if (get_property(node->parent, node->name)) {
  291. FAIL(c, dti, node, "node name and property name conflict");
  292. }
  293. }
  294. WARNING(node_name_vs_property_name, check_node_name_vs_property_name,
  295. NULL, &node_name_chars);
  296. static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
  297. struct node *node)
  298. {
  299. const char *unitname = get_unitname(node);
  300. struct property *prop = get_property(node, "reg");
  301. if (get_subnode(node, "__overlay__")) {
  302. /* HACK: Overlay fragments are a special case */
  303. return;
  304. }
  305. if (!prop) {
  306. prop = get_property(node, "ranges");
  307. if (prop && !prop->val.len)
  308. prop = NULL;
  309. }
  310. if (prop) {
  311. if (!unitname[0])
  312. FAIL(c, dti, node, "node has a reg or ranges property, but no unit name");
  313. } else {
  314. if (unitname[0])
  315. FAIL(c, dti, node, "node has a unit name, but no reg or ranges property");
  316. }
  317. }
  318. WARNING(unit_address_vs_reg, check_unit_address_vs_reg, NULL);
  319. static void check_property_name_chars(struct check *c, struct dt_info *dti,
  320. struct node *node)
  321. {
  322. struct property *prop;
  323. for_each_property(node, prop) {
  324. size_t n = strspn(prop->name, c->data);
  325. if (n < strlen(prop->name))
  326. FAIL_PROP(c, dti, node, prop, "Bad character '%c' in property name",
  327. prop->name[n]);
  328. }
  329. }
  330. ERROR(property_name_chars, check_property_name_chars, PROPCHARS);
  331. static void check_property_name_chars_strict(struct check *c,
  332. struct dt_info *dti,
  333. struct node *node)
  334. {
  335. struct property *prop;
  336. for_each_property(node, prop) {
  337. const char *name = prop->name;
  338. size_t n = strspn(name, c->data);
  339. if (n == strlen(prop->name))
  340. continue;
  341. /* Certain names are whitelisted */
  342. if (streq(name, "device_type"))
  343. continue;
  344. /*
  345. * # is only allowed at the beginning of property names not counting
  346. * the vendor prefix.
  347. */
  348. if (name[n] == '#' && ((n == 0) || (name[n-1] == ','))) {
  349. name += n + 1;
  350. n = strspn(name, c->data);
  351. }
  352. if (n < strlen(name))
  353. FAIL_PROP(c, dti, node, prop, "Character '%c' not recommended in property name",
  354. name[n]);
  355. }
  356. }
  357. CHECK(property_name_chars_strict, check_property_name_chars_strict, PROPNODECHARSSTRICT);
  358. #define DESCLABEL_FMT "%s%s%s%s%s"
  359. #define DESCLABEL_ARGS(node,prop,mark) \
  360. ((mark) ? "value of " : ""), \
  361. ((prop) ? "'" : ""), \
  362. ((prop) ? (prop)->name : ""), \
  363. ((prop) ? "' in " : ""), (node)->fullpath
  364. static void check_duplicate_label(struct check *c, struct dt_info *dti,
  365. const char *label, struct node *node,
  366. struct property *prop, struct marker *mark)
  367. {
  368. struct node *dt = dti->dt;
  369. struct node *othernode = NULL;
  370. struct property *otherprop = NULL;
  371. struct marker *othermark = NULL;
  372. othernode = get_node_by_label(dt, label);
  373. if (!othernode)
  374. otherprop = get_property_by_label(dt, label, &othernode);
  375. if (!othernode)
  376. othermark = get_marker_label(dt, label, &othernode,
  377. &otherprop);
  378. if (!othernode)
  379. return;
  380. if ((othernode != node) || (otherprop != prop) || (othermark != mark))
  381. FAIL(c, dti, node, "Duplicate label '%s' on " DESCLABEL_FMT
  382. " and " DESCLABEL_FMT,
  383. label, DESCLABEL_ARGS(node, prop, mark),
  384. DESCLABEL_ARGS(othernode, otherprop, othermark));
  385. }
  386. static void check_duplicate_label_node(struct check *c, struct dt_info *dti,
  387. struct node *node)
  388. {
  389. struct label *l;
  390. struct property *prop;
  391. for_each_label(node->labels, l)
  392. check_duplicate_label(c, dti, l->label, node, NULL, NULL);
  393. for_each_property(node, prop) {
  394. struct marker *m = prop->val.markers;
  395. for_each_label(prop->labels, l)
  396. check_duplicate_label(c, dti, l->label, node, prop, NULL);
  397. for_each_marker_of_type(m, LABEL)
  398. check_duplicate_label(c, dti, m->ref, node, prop, m);
  399. }
  400. }
  401. ERROR(duplicate_label, check_duplicate_label_node, NULL);
  402. static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
  403. struct node *node, const char *propname)
  404. {
  405. struct node *root = dti->dt;
  406. struct property *prop;
  407. struct marker *m;
  408. cell_t phandle;
  409. prop = get_property(node, propname);
  410. if (!prop)
  411. return 0;
  412. if (prop->val.len != sizeof(cell_t)) {
  413. FAIL_PROP(c, dti, node, prop, "bad length (%d) %s property",
  414. prop->val.len, prop->name);
  415. return 0;
  416. }
  417. m = prop->val.markers;
  418. for_each_marker_of_type(m, REF_PHANDLE) {
  419. assert(m->offset == 0);
  420. if (node != get_node_by_ref(root, m->ref))
  421. /* "Set this node's phandle equal to some
  422. * other node's phandle". That's nonsensical
  423. * by construction. */ {
  424. FAIL(c, dti, node, "%s is a reference to another node",
  425. prop->name);
  426. }
  427. /* But setting this node's phandle equal to its own
  428. * phandle is allowed - that means allocate a unique
  429. * phandle for this node, even if it's not otherwise
  430. * referenced. The value will be filled in later, so
  431. * we treat it as having no phandle data for now. */
  432. return 0;
  433. }
  434. phandle = propval_cell(prop);
  435. if (!phandle_is_valid(phandle)) {
  436. FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property",
  437. phandle, prop->name);
  438. return 0;
  439. }
  440. return phandle;
  441. }
  442. static void check_explicit_phandles(struct check *c, struct dt_info *dti,
  443. struct node *node)
  444. {
  445. struct node *root = dti->dt;
  446. struct node *other;
  447. cell_t phandle, linux_phandle;
  448. /* Nothing should have assigned phandles yet */
  449. assert(!node->phandle);
  450. phandle = check_phandle_prop(c, dti, node, "phandle");
  451. linux_phandle = check_phandle_prop(c, dti, node, "linux,phandle");
  452. if (!phandle && !linux_phandle)
  453. /* No valid phandles; nothing further to check */
  454. return;
  455. if (linux_phandle && phandle && (phandle != linux_phandle))
  456. FAIL(c, dti, node, "mismatching 'phandle' and 'linux,phandle'"
  457. " properties");
  458. if (linux_phandle && !phandle)
  459. phandle = linux_phandle;
  460. other = get_node_by_phandle(root, phandle);
  461. if (other && (other != node)) {
  462. FAIL(c, dti, node, "duplicated phandle 0x%x (seen before at %s)",
  463. phandle, other->fullpath);
  464. return;
  465. }
  466. node->phandle = phandle;
  467. }
  468. ERROR(explicit_phandles, check_explicit_phandles, NULL);
  469. static void check_name_properties(struct check *c, struct dt_info *dti,
  470. struct node *node)
  471. {
  472. struct property **pp, *prop = NULL;
  473. for (pp = &node->proplist; *pp; pp = &((*pp)->next))
  474. if (streq((*pp)->name, "name")) {
  475. prop = *pp;
  476. break;
  477. }
  478. if (!prop)
  479. return; /* No name property, that's fine */
  480. if ((prop->val.len != node->basenamelen + 1U)
  481. || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
  482. FAIL(c, dti, node, "\"name\" property is incorrect (\"%s\" instead"
  483. " of base node name)", prop->val.val);
  484. } else {
  485. /* The name property is correct, and therefore redundant.
  486. * Delete it */
  487. *pp = prop->next;
  488. free(prop->name);
  489. data_free(prop->val);
  490. free(prop);
  491. }
  492. }
  493. ERROR_IF_NOT_STRING(name_is_string, "name");
  494. ERROR(name_properties, check_name_properties, NULL, &name_is_string);
  495. /*
  496. * Reference fixup functions
  497. */
  498. static void fixup_phandle_references(struct check *c, struct dt_info *dti,
  499. struct node *node)
  500. {
  501. struct node *dt = dti->dt;
  502. struct property *prop;
  503. for_each_property(node, prop) {
  504. struct marker *m = prop->val.markers;
  505. struct node *refnode;
  506. cell_t phandle;
  507. for_each_marker_of_type(m, REF_PHANDLE) {
  508. assert(m->offset + sizeof(cell_t) <= prop->val.len);
  509. refnode = get_node_by_ref(dt, m->ref);
  510. if (! refnode) {
  511. if (!(dti->dtsflags & DTSF_PLUGIN))
  512. FAIL(c, dti, node, "Reference to non-existent node or "
  513. "label \"%s\"\n", m->ref);
  514. else /* mark the entry as unresolved */
  515. *((fdt32_t *)(prop->val.val + m->offset)) =
  516. cpu_to_fdt32(0xffffffff);
  517. continue;
  518. }
  519. phandle = get_node_phandle(dt, refnode);
  520. *((fdt32_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
  521. reference_node(refnode);
  522. }
  523. }
  524. }
  525. ERROR(phandle_references, fixup_phandle_references, NULL,
  526. &duplicate_node_names, &explicit_phandles);
  527. static void fixup_path_references(struct check *c, struct dt_info *dti,
  528. struct node *node)
  529. {
  530. struct node *dt = dti->dt;
  531. struct property *prop;
  532. for_each_property(node, prop) {
  533. struct marker *m = prop->val.markers;
  534. struct node *refnode;
  535. char *path;
  536. for_each_marker_of_type(m, REF_PATH) {
  537. assert(m->offset <= prop->val.len);
  538. refnode = get_node_by_ref(dt, m->ref);
  539. if (!refnode) {
  540. FAIL(c, dti, node, "Reference to non-existent node or label \"%s\"\n",
  541. m->ref);
  542. continue;
  543. }
  544. path = refnode->fullpath;
  545. prop->val = data_insert_at_marker(prop->val, m, path,
  546. strlen(path) + 1);
  547. reference_node(refnode);
  548. }
  549. }
  550. }
  551. ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);
  552. static void fixup_omit_unused_nodes(struct check *c, struct dt_info *dti,
  553. struct node *node)
  554. {
  555. if (generate_symbols && node->labels)
  556. return;
  557. if (node->omit_if_unused && !node->is_referenced)
  558. delete_node(node);
  559. }
  560. ERROR(omit_unused_nodes, fixup_omit_unused_nodes, NULL, &phandle_references, &path_references);
  561. /*
  562. * Semantic checks
  563. */
  564. WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells");
  565. WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells");
  566. WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
  567. WARNING_IF_NOT_STRING(model_is_string, "model");
  568. WARNING_IF_NOT_STRING(status_is_string, "status");
  569. WARNING_IF_NOT_STRING(label_is_string, "label");
  570. WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
  571. static void check_names_is_string_list(struct check *c, struct dt_info *dti,
  572. struct node *node)
  573. {
  574. struct property *prop;
  575. for_each_property(node, prop) {
  576. if (!strends(prop->name, "-names"))
  577. continue;
  578. c->data = prop->name;
  579. check_is_string_list(c, dti, node);
  580. }
  581. }
  582. WARNING(names_is_string_list, check_names_is_string_list, NULL);
  583. static void check_alias_paths(struct check *c, struct dt_info *dti,
  584. struct node *node)
  585. {
  586. struct property *prop;
  587. if (!streq(node->name, "aliases"))
  588. return;
  589. for_each_property(node, prop) {
  590. if (streq(prop->name, "phandle")
  591. || streq(prop->name, "linux,phandle")) {
  592. continue;
  593. }
  594. if (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val)) {
  595. FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)",
  596. prop->val.val);
  597. continue;
  598. }
  599. if (strspn(prop->name, LOWERCASE DIGITS "-") != strlen(prop->name))
  600. FAIL(c, dti, node, "aliases property name must include only lowercase and '-'");
  601. }
  602. }
  603. WARNING(alias_paths, check_alias_paths, NULL);
  604. static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
  605. struct node *node)
  606. {
  607. struct property *prop;
  608. node->addr_cells = -1;
  609. node->size_cells = -1;
  610. prop = get_property(node, "#address-cells");
  611. if (prop)
  612. node->addr_cells = propval_cell(prop);
  613. prop = get_property(node, "#size-cells");
  614. if (prop)
  615. node->size_cells = propval_cell(prop);
  616. }
  617. WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
  618. &address_cells_is_cell, &size_cells_is_cell);
  619. #define node_addr_cells(n) \
  620. (((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
  621. #define node_size_cells(n) \
  622. (((n)->size_cells == -1) ? 1 : (n)->size_cells)
  623. static void check_reg_format(struct check *c, struct dt_info *dti,
  624. struct node *node)
  625. {
  626. struct property *prop;
  627. int addr_cells, size_cells, entrylen;
  628. prop = get_property(node, "reg");
  629. if (!prop)
  630. return; /* No "reg", that's fine */
  631. if (!node->parent) {
  632. FAIL(c, dti, node, "Root node has a \"reg\" property");
  633. return;
  634. }
  635. if (prop->val.len == 0)
  636. FAIL_PROP(c, dti, node, prop, "property is empty");
  637. addr_cells = node_addr_cells(node->parent);
  638. size_cells = node_size_cells(node->parent);
  639. entrylen = (addr_cells + size_cells) * sizeof(cell_t);
  640. if (!is_multiple_of(prop->val.len, entrylen))
  641. FAIL_PROP(c, dti, node, prop, "property has invalid length (%d bytes) "
  642. "(#address-cells == %d, #size-cells == %d)",
  643. prop->val.len, addr_cells, size_cells);
  644. }
  645. WARNING(reg_format, check_reg_format, NULL, &addr_size_cells);
  646. static void check_ranges_format(struct check *c, struct dt_info *dti,
  647. struct node *node)
  648. {
  649. struct property *prop;
  650. int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;
  651. const char *ranges = c->data;
  652. prop = get_property(node, ranges);
  653. if (!prop)
  654. return;
  655. if (!node->parent) {
  656. FAIL_PROP(c, dti, node, prop, "Root node has a \"%s\" property",
  657. ranges);
  658. return;
  659. }
  660. p_addr_cells = node_addr_cells(node->parent);
  661. p_size_cells = node_size_cells(node->parent);
  662. c_addr_cells = node_addr_cells(node);
  663. c_size_cells = node_size_cells(node);
  664. entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);
  665. if (prop->val.len == 0) {
  666. if (p_addr_cells != c_addr_cells)
  667. FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
  668. "#address-cells (%d) differs from %s (%d)",
  669. ranges, c_addr_cells, node->parent->fullpath,
  670. p_addr_cells);
  671. if (p_size_cells != c_size_cells)
  672. FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
  673. "#size-cells (%d) differs from %s (%d)",
  674. ranges, c_size_cells, node->parent->fullpath,
  675. p_size_cells);
  676. } else if (!is_multiple_of(prop->val.len, entrylen)) {
  677. FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
  678. "(parent #address-cells == %d, child #address-cells == %d, "
  679. "#size-cells == %d)", ranges, prop->val.len,
  680. p_addr_cells, c_addr_cells, c_size_cells);
  681. }
  682. }
  683. WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
  684. WARNING(dma_ranges_format, check_ranges_format, "dma-ranges", &addr_size_cells);
  685. static const struct bus_type pci_bus = {
  686. .name = "PCI",
  687. };
  688. static void check_pci_bridge(struct check *c, struct dt_info *dti, struct node *node)
  689. {
  690. struct property *prop;
  691. cell_t *cells;
  692. prop = get_property(node, "device_type");
  693. if (!prop || !streq(prop->val.val, "pci"))
  694. return;
  695. node->bus = &pci_bus;
  696. if (!strprefixeq(node->name, node->basenamelen, "pci") &&
  697. !strprefixeq(node->name, node->basenamelen, "pcie"))
  698. FAIL(c, dti, node, "node name is not \"pci\" or \"pcie\"");
  699. prop = get_property(node, "ranges");
  700. if (!prop)
  701. FAIL(c, dti, node, "missing ranges for PCI bridge (or not a bridge)");
  702. if (node_addr_cells(node) != 3)
  703. FAIL(c, dti, node, "incorrect #address-cells for PCI bridge");
  704. if (node_size_cells(node) != 2)
  705. FAIL(c, dti, node, "incorrect #size-cells for PCI bridge");
  706. prop = get_property(node, "bus-range");
  707. if (!prop)
  708. return;
  709. if (prop->val.len != (sizeof(cell_t) * 2)) {
  710. FAIL_PROP(c, dti, node, prop, "value must be 2 cells");
  711. return;
  712. }
  713. cells = (cell_t *)prop->val.val;
  714. if (fdt32_to_cpu(cells[0]) > fdt32_to_cpu(cells[1]))
  715. FAIL_PROP(c, dti, node, prop, "1st cell must be less than or equal to 2nd cell");
  716. if (fdt32_to_cpu(cells[1]) > 0xff)
  717. FAIL_PROP(c, dti, node, prop, "maximum bus number must be less than 256");
  718. }
  719. WARNING(pci_bridge, check_pci_bridge, NULL,
  720. &device_type_is_string, &addr_size_cells);
  721. static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struct node *node)
  722. {
  723. struct property *prop;
  724. unsigned int bus_num, min_bus, max_bus;
  725. cell_t *cells;
  726. if (!node->parent || (node->parent->bus != &pci_bus))
  727. return;
  728. prop = get_property(node, "reg");
  729. if (!prop)
  730. return;
  731. cells = (cell_t *)prop->val.val;
  732. bus_num = (fdt32_to_cpu(cells[0]) & 0x00ff0000) >> 16;
  733. prop = get_property(node->parent, "bus-range");
  734. if (!prop) {
  735. min_bus = max_bus = 0;
  736. } else {
  737. cells = (cell_t *)prop->val.val;
  738. min_bus = fdt32_to_cpu(cells[0]);
  739. max_bus = fdt32_to_cpu(cells[1]);
  740. }
  741. if ((bus_num < min_bus) || (bus_num > max_bus))
  742. FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)",
  743. bus_num, min_bus, max_bus);
  744. }
  745. WARNING(pci_device_bus_num, check_pci_device_bus_num, NULL, &reg_format, &pci_bridge);
  746. static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct node *node)
  747. {
  748. struct property *prop;
  749. const char *unitname = get_unitname(node);
  750. char unit_addr[5];
  751. unsigned int dev, func, reg;
  752. cell_t *cells;
  753. if (!node->parent || (node->parent->bus != &pci_bus))
  754. return;
  755. prop = get_property(node, "reg");
  756. if (!prop)
  757. return;
  758. cells = (cell_t *)prop->val.val;
  759. if (cells[1] || cells[2])
  760. FAIL_PROP(c, dti, node, prop, "PCI reg config space address cells 2 and 3 must be 0");
  761. reg = fdt32_to_cpu(cells[0]);
  762. dev = (reg & 0xf800) >> 11;
  763. func = (reg & 0x700) >> 8;
  764. if (reg & 0xff000000)
  765. FAIL_PROP(c, dti, node, prop, "PCI reg address is not configuration space");
  766. if (reg & 0x000000ff)
  767. FAIL_PROP(c, dti, node, prop, "PCI reg config space address register number must be 0");
  768. if (func == 0) {
  769. snprintf(unit_addr, sizeof(unit_addr), "%x", dev);
  770. if (streq(unitname, unit_addr))
  771. return;
  772. }
  773. snprintf(unit_addr, sizeof(unit_addr), "%x,%x", dev, func);
  774. if (streq(unitname, unit_addr))
  775. return;
  776. FAIL(c, dti, node, "PCI unit address format error, expected \"%s\"",
  777. unit_addr);
  778. }
  779. WARNING(pci_device_reg, check_pci_device_reg, NULL, &reg_format, &pci_bridge);
  780. static const struct bus_type simple_bus = {
  781. .name = "simple-bus",
  782. };
  783. static bool node_is_compatible(struct node *node, const char *compat)
  784. {
  785. struct property *prop;
  786. const char *str, *end;
  787. prop = get_property(node, "compatible");
  788. if (!prop)
  789. return false;
  790. for (str = prop->val.val, end = str + prop->val.len; str < end;
  791. str += strnlen(str, end - str) + 1) {
  792. if (streq(str, compat))
  793. return true;
  794. }
  795. return false;
  796. }
  797. static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
  798. {
  799. if (node_is_compatible(node, "simple-bus"))
  800. node->bus = &simple_bus;
  801. }
  802. WARNING(simple_bus_bridge, check_simple_bus_bridge, NULL,
  803. &addr_size_cells, &compatible_is_string_list);
  804. static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
  805. {
  806. struct property *prop;
  807. const char *unitname = get_unitname(node);
  808. char unit_addr[17];
  809. unsigned int size;
  810. uint64_t reg = 0;
  811. cell_t *cells = NULL;
  812. if (!node->parent || (node->parent->bus != &simple_bus))
  813. return;
  814. prop = get_property(node, "reg");
  815. if (prop)
  816. cells = (cell_t *)prop->val.val;
  817. else {
  818. prop = get_property(node, "ranges");
  819. if (prop && prop->val.len)
  820. /* skip of child address */
  821. cells = ((cell_t *)prop->val.val) + node_addr_cells(node);
  822. }
  823. if (!cells) {
  824. if (node->parent->parent && !(node->bus == &simple_bus))
  825. FAIL(c, dti, node, "missing or empty reg/ranges property");
  826. return;
  827. }
  828. size = node_addr_cells(node->parent);
  829. while (size--)
  830. reg = (reg << 32) | fdt32_to_cpu(*(cells++));
  831. snprintf(unit_addr, sizeof(unit_addr), "%"PRIx64, reg);
  832. if (!streq(unitname, unit_addr))
  833. FAIL(c, dti, node, "simple-bus unit address format error, expected \"%s\"",
  834. unit_addr);
  835. }
  836. WARNING(simple_bus_reg, check_simple_bus_reg, NULL, &reg_format, &simple_bus_bridge);
  837. static const struct bus_type i2c_bus = {
  838. .name = "i2c-bus",
  839. };
  840. static void check_i2c_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
  841. {
  842. if (strprefixeq(node->name, node->basenamelen, "i2c-bus") ||
  843. strprefixeq(node->name, node->basenamelen, "i2c-arb")) {
  844. node->bus = &i2c_bus;
  845. } else if (strprefixeq(node->name, node->basenamelen, "i2c")) {
  846. struct node *child;
  847. for_each_child(node, child) {
  848. if (strprefixeq(child->name, node->basenamelen, "i2c-bus"))
  849. return;
  850. }
  851. node->bus = &i2c_bus;
  852. } else
  853. return;
  854. if (!node->children)
  855. return;
  856. if (node_addr_cells(node) != 1)
  857. FAIL(c, dti, node, "incorrect #address-cells for I2C bus");
  858. if (node_size_cells(node) != 0)
  859. FAIL(c, dti, node, "incorrect #size-cells for I2C bus");
  860. }
  861. WARNING(i2c_bus_bridge, check_i2c_bus_bridge, NULL, &addr_size_cells);
  862. #define I2C_OWN_SLAVE_ADDRESS (1U << 30)
  863. #define I2C_TEN_BIT_ADDRESS (1U << 31)
  864. static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
  865. {
  866. struct property *prop;
  867. const char *unitname = get_unitname(node);
  868. char unit_addr[17];
  869. uint32_t reg = 0;
  870. int len;
  871. cell_t *cells = NULL;
  872. if (!node->parent || (node->parent->bus != &i2c_bus))
  873. return;
  874. prop = get_property(node, "reg");
  875. if (prop)
  876. cells = (cell_t *)prop->val.val;
  877. if (!cells) {
  878. FAIL(c, dti, node, "missing or empty reg property");
  879. return;
  880. }
  881. reg = fdt32_to_cpu(*cells);
  882. /* Ignore I2C_OWN_SLAVE_ADDRESS */
  883. reg &= ~I2C_OWN_SLAVE_ADDRESS;
  884. snprintf(unit_addr, sizeof(unit_addr), "%x", reg);
  885. if (!streq(unitname, unit_addr))
  886. FAIL(c, dti, node, "I2C bus unit address format error, expected \"%s\"",
  887. unit_addr);
  888. for (len = prop->val.len; len > 0; len -= 4) {
  889. reg = fdt32_to_cpu(*(cells++));
  890. /* Ignore I2C_OWN_SLAVE_ADDRESS */
  891. reg &= ~I2C_OWN_SLAVE_ADDRESS;
  892. if ((reg & I2C_TEN_BIT_ADDRESS) && ((reg & ~I2C_TEN_BIT_ADDRESS) > 0x3ff))
  893. FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"",
  894. reg);
  895. else if (reg > 0x7f)
  896. FAIL_PROP(c, dti, node, prop, "I2C address must be less than 7-bits, got \"0x%x\". Set I2C_TEN_BIT_ADDRESS for 10 bit addresses or fix the property",
  897. reg);
  898. }
  899. }
  900. WARNING(i2c_bus_reg, check_i2c_bus_reg, NULL, &reg_format, &i2c_bus_bridge);
  901. static const struct bus_type spi_bus = {
  902. .name = "spi-bus",
  903. };
  904. static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
  905. {
  906. int spi_addr_cells = 1;
  907. if (strprefixeq(node->name, node->basenamelen, "spi")) {
  908. node->bus = &spi_bus;
  909. } else {
  910. /* Try to detect SPI buses which don't have proper node name */
  911. struct node *child;
  912. if (node_addr_cells(node) != 1 || node_size_cells(node) != 0)
  913. return;
  914. for_each_child(node, child) {
  915. struct property *prop;
  916. for_each_property(child, prop) {
  917. if (strprefixeq(prop->name, 4, "spi-")) {
  918. node->bus = &spi_bus;
  919. break;
  920. }
  921. }
  922. if (node->bus == &spi_bus)
  923. break;
  924. }
  925. if (node->bus == &spi_bus && get_property(node, "reg"))
  926. FAIL(c, dti, node, "node name for SPI buses should be 'spi'");
  927. }
  928. if (node->bus != &spi_bus || !node->children)
  929. return;
  930. if (get_property(node, "spi-slave"))
  931. spi_addr_cells = 0;
  932. if (node_addr_cells(node) != spi_addr_cells)
  933. FAIL(c, dti, node, "incorrect #address-cells for SPI bus");
  934. if (node_size_cells(node) != 0)
  935. FAIL(c, dti, node, "incorrect #size-cells for SPI bus");
  936. }
  937. WARNING(spi_bus_bridge, check_spi_bus_bridge, NULL, &addr_size_cells);
  938. static void check_spi_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
  939. {
  940. struct property *prop;
  941. const char *unitname = get_unitname(node);
  942. char unit_addr[9];
  943. uint32_t reg = 0;
  944. cell_t *cells = NULL;
  945. if (!node->parent || (node->parent->bus != &spi_bus))
  946. return;
  947. if (get_property(node->parent, "spi-slave"))
  948. return;
  949. prop = get_property(node, "reg");
  950. if (prop)
  951. cells = (cell_t *)prop->val.val;
  952. if (!cells) {
  953. FAIL(c, dti, node, "missing or empty reg property");
  954. return;
  955. }
  956. reg = fdt32_to_cpu(*cells);
  957. snprintf(unit_addr, sizeof(unit_addr), "%x", reg);
  958. if (!streq(unitname, unit_addr))
  959. FAIL(c, dti, node, "SPI bus unit address format error, expected \"%s\"",
  960. unit_addr);
  961. }
  962. WARNING(spi_bus_reg, check_spi_bus_reg, NULL, &reg_format, &spi_bus_bridge);
  963. static void check_unit_address_format(struct check *c, struct dt_info *dti,
  964. struct node *node)
  965. {
  966. const char *unitname = get_unitname(node);
  967. if (node->parent && node->parent->bus)
  968. return;
  969. if (!unitname[0])
  970. return;
  971. if (!strncmp(unitname, "0x", 2)) {
  972. FAIL(c, dti, node, "unit name should not have leading \"0x\"");
  973. /* skip over 0x for next test */
  974. unitname += 2;
  975. }
  976. if (unitname[0] == '0' && isxdigit(unitname[1]))
  977. FAIL(c, dti, node, "unit name should not have leading 0s");
  978. }
  979. WARNING(unit_address_format, check_unit_address_format, NULL,
  980. &node_name_format, &pci_bridge, &simple_bus_bridge);
  981. /*
  982. * Style checks
  983. */
  984. static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti,
  985. struct node *node)
  986. {
  987. struct property *reg, *ranges;
  988. if (!node->parent)
  989. return; /* Ignore root node */
  990. reg = get_property(node, "reg");
  991. ranges = get_property(node, "ranges");
  992. if (!reg && !ranges)
  993. return;
  994. if (node->parent->addr_cells == -1)
  995. FAIL(c, dti, node, "Relying on default #address-cells value");
  996. if (node->parent->size_cells == -1)
  997. FAIL(c, dti, node, "Relying on default #size-cells value");
  998. }
  999. WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
  1000. &addr_size_cells);
  1001. static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *dti,
  1002. struct node *node)
  1003. {
  1004. struct property *prop;
  1005. struct node *child;
  1006. bool has_reg = false;
  1007. if (!node->parent || node->addr_cells < 0 || node->size_cells < 0)
  1008. return;
  1009. if (get_property(node, "ranges") || !node->children)
  1010. return;
  1011. for_each_child(node, child) {
  1012. prop = get_property(child, "reg");
  1013. if (prop)
  1014. has_reg = true;
  1015. }
  1016. if (!has_reg)
  1017. FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property");
  1018. }
  1019. WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size);
  1020. static bool node_is_disabled(struct node *node)
  1021. {
  1022. struct property *prop;
  1023. prop = get_property(node, "status");
  1024. if (prop) {
  1025. char *str = prop->val.val;
  1026. if (streq("disabled", str))
  1027. return true;
  1028. }
  1029. return false;
  1030. }
  1031. static void check_unique_unit_address_common(struct check *c,
  1032. struct dt_info *dti,
  1033. struct node *node,
  1034. bool disable_check)
  1035. {
  1036. struct node *childa;
  1037. if (node->addr_cells < 0 || node->size_cells < 0)
  1038. return;
  1039. if (!node->children)
  1040. return;
  1041. for_each_child(node, childa) {
  1042. struct node *childb;
  1043. const char *addr_a = get_unitname(childa);
  1044. if (!strlen(addr_a))
  1045. continue;
  1046. if (disable_check && node_is_disabled(childa))
  1047. continue;
  1048. for_each_child(node, childb) {
  1049. const char *addr_b = get_unitname(childb);
  1050. if (childa == childb)
  1051. break;
  1052. if (disable_check && node_is_disabled(childb))
  1053. continue;
  1054. if (streq(addr_a, addr_b))
  1055. FAIL(c, dti, childb, "duplicate unit-address (also used in node %s)", childa->fullpath);
  1056. }
  1057. }
  1058. }
  1059. static void check_unique_unit_address(struct check *c, struct dt_info *dti,
  1060. struct node *node)
  1061. {
  1062. check_unique_unit_address_common(c, dti, node, false);
  1063. }
  1064. WARNING(unique_unit_address, check_unique_unit_address, NULL, &avoid_default_addr_size);
  1065. static void check_unique_unit_address_if_enabled(struct check *c, struct dt_info *dti,
  1066. struct node *node)
  1067. {
  1068. check_unique_unit_address_common(c, dti, node, true);
  1069. }
  1070. CHECK_ENTRY(unique_unit_address_if_enabled, check_unique_unit_address_if_enabled,
  1071. NULL, false, false, &avoid_default_addr_size);
  1072. static void check_obsolete_chosen_interrupt_controller(struct check *c,
  1073. struct dt_info *dti,
  1074. struct node *node)
  1075. {
  1076. struct node *dt = dti->dt;
  1077. struct node *chosen;
  1078. struct property *prop;
  1079. if (node != dt)
  1080. return;
  1081. chosen = get_node_by_path(dt, "/chosen");
  1082. if (!chosen)
  1083. return;
  1084. prop = get_property(chosen, "interrupt-controller");
  1085. if (prop)
  1086. FAIL_PROP(c, dti, node, prop,
  1087. "/chosen has obsolete \"interrupt-controller\" property");
  1088. }
  1089. WARNING(obsolete_chosen_interrupt_controller,
  1090. check_obsolete_chosen_interrupt_controller, NULL);
  1091. static void check_chosen_node_is_root(struct check *c, struct dt_info *dti,
  1092. struct node *node)
  1093. {
  1094. if (!streq(node->name, "chosen"))
  1095. return;
  1096. if (node->parent != dti->dt)
  1097. FAIL(c, dti, node, "chosen node must be at root node");
  1098. }
  1099. WARNING(chosen_node_is_root, check_chosen_node_is_root, NULL);
  1100. static void check_chosen_node_bootargs(struct check *c, struct dt_info *dti,
  1101. struct node *node)
  1102. {
  1103. struct property *prop;
  1104. if (!streq(node->name, "chosen"))
  1105. return;
  1106. prop = get_property(node, "bootargs");
  1107. if (!prop)
  1108. return;
  1109. c->data = prop->name;
  1110. check_is_string(c, dti, node);
  1111. }
  1112. WARNING(chosen_node_bootargs, check_chosen_node_bootargs, NULL);
  1113. static void check_chosen_node_stdout_path(struct check *c, struct dt_info *dti,
  1114. struct node *node)
  1115. {
  1116. struct property *prop;
  1117. if (!streq(node->name, "chosen"))
  1118. return;
  1119. prop = get_property(node, "stdout-path");
  1120. if (!prop) {
  1121. prop = get_property(node, "linux,stdout-path");
  1122. if (!prop)
  1123. return;
  1124. FAIL_PROP(c, dti, node, prop, "Use 'stdout-path' instead");
  1125. }
  1126. c->data = prop->name;
  1127. check_is_string(c, dti, node);
  1128. }
  1129. WARNING(chosen_node_stdout_path, check_chosen_node_stdout_path, NULL);
  1130. struct provider {
  1131. const char *prop_name;
  1132. const char *cell_name;
  1133. bool optional;
  1134. };
  1135. static void check_property_phandle_args(struct check *c,
  1136. struct dt_info *dti,
  1137. struct node *node,
  1138. struct property *prop,
  1139. const struct provider *provider)
  1140. {
  1141. struct node *root = dti->dt;
  1142. unsigned int cell, cellsize = 0;
  1143. if (!is_multiple_of(prop->val.len, sizeof(cell_t))) {
  1144. FAIL_PROP(c, dti, node, prop,
  1145. "property size (%d) is invalid, expected multiple of %zu",
  1146. prop->val.len, sizeof(cell_t));
  1147. return;
  1148. }
  1149. for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) {
  1150. struct node *provider_node;
  1151. struct property *cellprop;
  1152. cell_t phandle;
  1153. phandle = propval_cell_n(prop, cell);
  1154. /*
  1155. * Some bindings use a cell value 0 or -1 to skip over optional
  1156. * entries when each index position has a specific definition.
  1157. */
  1158. if (!phandle_is_valid(phandle)) {
  1159. /* Give up if this is an overlay with external references */
  1160. if (dti->dtsflags & DTSF_PLUGIN)
  1161. break;
  1162. cellsize = 0;
  1163. continue;
  1164. }
  1165. /* If we have markers, verify the current cell is a phandle */
  1166. if (prop->val.markers) {
  1167. struct marker *m = prop->val.markers;
  1168. for_each_marker_of_type(m, REF_PHANDLE) {
  1169. if (m->offset == (cell * sizeof(cell_t)))
  1170. break;
  1171. }
  1172. if (!m)
  1173. FAIL_PROP(c, dti, node, prop,
  1174. "cell %d is not a phandle reference",
  1175. cell);
  1176. }
  1177. provider_node = get_node_by_phandle(root, phandle);
  1178. if (!provider_node) {
  1179. FAIL_PROP(c, dti, node, prop,
  1180. "Could not get phandle node for (cell %d)",
  1181. cell);
  1182. break;
  1183. }
  1184. cellprop = get_property(provider_node, provider->cell_name);
  1185. if (cellprop) {
  1186. cellsize = propval_cell(cellprop);
  1187. } else if (provider->optional) {
  1188. cellsize = 0;
  1189. } else {
  1190. FAIL(c, dti, node, "Missing property '%s' in node %s or bad phandle (referred from %s[%d])",
  1191. provider->cell_name,
  1192. provider_node->fullpath,
  1193. prop->name, cell);
  1194. break;
  1195. }
  1196. if (prop->val.len < ((cell + cellsize + 1) * sizeof(cell_t))) {
  1197. FAIL_PROP(c, dti, node, prop,
  1198. "property size (%d) too small for cell size %d",
  1199. prop->val.len, cellsize);
  1200. }
  1201. }
  1202. }
  1203. static void check_provider_cells_property(struct check *c,
  1204. struct dt_info *dti,
  1205. struct node *node)
  1206. {
  1207. struct provider *provider = c->data;
  1208. struct property *prop;
  1209. prop = get_property(node, provider->prop_name);
  1210. if (!prop)
  1211. return;
  1212. check_property_phandle_args(c, dti, node, prop, provider);
  1213. }
  1214. #define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \
  1215. static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \
  1216. WARNING_IF_NOT_CELL(nm##_is_cell, cells_name); \
  1217. WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &nm##_is_cell, &phandle_references);
  1218. WARNING_PROPERTY_PHANDLE_CELLS(clocks, "clocks", "#clock-cells");
  1219. WARNING_PROPERTY_PHANDLE_CELLS(cooling_device, "cooling-device", "#cooling-cells");
  1220. WARNING_PROPERTY_PHANDLE_CELLS(dmas, "dmas", "#dma-cells");
  1221. WARNING_PROPERTY_PHANDLE_CELLS(hwlocks, "hwlocks", "#hwlock-cells");
  1222. WARNING_PROPERTY_PHANDLE_CELLS(interrupts_extended, "interrupts-extended", "#interrupt-cells");
  1223. WARNING_PROPERTY_PHANDLE_CELLS(io_channels, "io-channels", "#io-channel-cells");
  1224. WARNING_PROPERTY_PHANDLE_CELLS(iommus, "iommus", "#iommu-cells");
  1225. WARNING_PROPERTY_PHANDLE_CELLS(mboxes, "mboxes", "#mbox-cells");
  1226. WARNING_PROPERTY_PHANDLE_CELLS(msi_parent, "msi-parent", "#msi-cells", true);
  1227. WARNING_PROPERTY_PHANDLE_CELLS(mux_controls, "mux-controls", "#mux-control-cells");
  1228. WARNING_PROPERTY_PHANDLE_CELLS(phys, "phys", "#phy-cells");
  1229. WARNING_PROPERTY_PHANDLE_CELLS(power_domains, "power-domains", "#power-domain-cells");
  1230. WARNING_PROPERTY_PHANDLE_CELLS(pwms, "pwms", "#pwm-cells");
  1231. WARNING_PROPERTY_PHANDLE_CELLS(resets, "resets", "#reset-cells");
  1232. WARNING_PROPERTY_PHANDLE_CELLS(sound_dai, "sound-dai", "#sound-dai-cells");
  1233. WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sensor-cells");
  1234. static bool prop_is_gpio(struct property *prop)
  1235. {
  1236. /*
  1237. * *-gpios and *-gpio can appear in property names,
  1238. * so skip over any false matches (only one known ATM)
  1239. */
  1240. if (strends(prop->name, ",nr-gpios"))
  1241. return false;
  1242. return strends(prop->name, "-gpios") ||
  1243. streq(prop->name, "gpios") ||
  1244. strends(prop->name, "-gpio") ||
  1245. streq(prop->name, "gpio");
  1246. }
  1247. static void check_gpios_property(struct check *c,
  1248. struct dt_info *dti,
  1249. struct node *node)
  1250. {
  1251. struct property *prop;
  1252. /* Skip GPIO hog nodes which have 'gpios' property */
  1253. if (get_property(node, "gpio-hog"))
  1254. return;
  1255. for_each_property(node, prop) {
  1256. struct provider provider;
  1257. if (!prop_is_gpio(prop))
  1258. continue;
  1259. provider.prop_name = prop->name;
  1260. provider.cell_name = "#gpio-cells";
  1261. provider.optional = false;
  1262. check_property_phandle_args(c, dti, node, prop, &provider);
  1263. }
  1264. }
  1265. WARNING(gpios_property, check_gpios_property, NULL, &phandle_references);
  1266. static void check_deprecated_gpio_property(struct check *c,
  1267. struct dt_info *dti,
  1268. struct node *node)
  1269. {
  1270. struct property *prop;
  1271. for_each_property(node, prop) {
  1272. if (!prop_is_gpio(prop))
  1273. continue;
  1274. if (!strends(prop->name, "gpio"))
  1275. continue;
  1276. FAIL_PROP(c, dti, node, prop,
  1277. "'[*-]gpio' is deprecated, use '[*-]gpios' instead");
  1278. }
  1279. }
  1280. CHECK(deprecated_gpio_property, check_deprecated_gpio_property, NULL);
  1281. static bool node_is_interrupt_provider(struct node *node)
  1282. {
  1283. struct property *prop;
  1284. prop = get_property(node, "interrupt-controller");
  1285. if (prop)
  1286. return true;
  1287. prop = get_property(node, "interrupt-map");
  1288. if (prop)
  1289. return true;
  1290. return false;
  1291. }
  1292. static void check_interrupt_provider(struct check *c,
  1293. struct dt_info *dti,
  1294. struct node *node)
  1295. {
  1296. struct property *prop;
  1297. bool irq_provider = node_is_interrupt_provider(node);
  1298. prop = get_property(node, "#interrupt-cells");
  1299. if (irq_provider && !prop) {
  1300. FAIL(c, dti, node,
  1301. "Missing '#interrupt-cells' in interrupt provider");
  1302. return;
  1303. }
  1304. if (!irq_provider && prop) {
  1305. FAIL(c, dti, node,
  1306. "'#interrupt-cells' found, but node is not an interrupt provider");
  1307. return;
  1308. }
  1309. }
  1310. WARNING(interrupt_provider, check_interrupt_provider, NULL, &interrupts_extended_is_cell);
  1311. static void check_interrupt_map(struct check *c,
  1312. struct dt_info *dti,
  1313. struct node *node)
  1314. {
  1315. struct node *root = dti->dt;
  1316. struct property *prop, *irq_map_prop;
  1317. size_t cellsize, cell, map_cells;
  1318. irq_map_prop = get_property(node, "interrupt-map");
  1319. if (!irq_map_prop)
  1320. return;
  1321. if (node->addr_cells < 0) {
  1322. FAIL(c, dti, node,
  1323. "Missing '#address-cells' in interrupt-map provider");
  1324. return;
  1325. }
  1326. cellsize = node_addr_cells(node);
  1327. cellsize += propval_cell(get_property(node, "#interrupt-cells"));
  1328. prop = get_property(node, "interrupt-map-mask");
  1329. if (prop && (prop->val.len != (cellsize * sizeof(cell_t))))
  1330. FAIL_PROP(c, dti, node, prop,
  1331. "property size (%d) is invalid, expected %zu",
  1332. prop->val.len, cellsize * sizeof(cell_t));
  1333. if (!is_multiple_of(irq_map_prop->val.len, sizeof(cell_t))) {
  1334. FAIL_PROP(c, dti, node, irq_map_prop,
  1335. "property size (%d) is invalid, expected multiple of %zu",
  1336. irq_map_prop->val.len, sizeof(cell_t));
  1337. return;
  1338. }
  1339. map_cells = irq_map_prop->val.len / sizeof(cell_t);
  1340. for (cell = 0; cell < map_cells; ) {
  1341. struct node *provider_node;
  1342. struct property *cellprop;
  1343. int phandle;
  1344. size_t parent_cellsize;
  1345. if ((cell + cellsize) >= map_cells) {
  1346. FAIL_PROP(c, dti, node, irq_map_prop,
  1347. "property size (%d) too small, expected > %zu",
  1348. irq_map_prop->val.len, (cell + cellsize) * sizeof(cell_t));
  1349. break;
  1350. }
  1351. cell += cellsize;
  1352. phandle = propval_cell_n(irq_map_prop, cell);
  1353. if (!phandle_is_valid(phandle)) {
  1354. /* Give up if this is an overlay with external references */
  1355. if (!(dti->dtsflags & DTSF_PLUGIN))
  1356. FAIL_PROP(c, dti, node, irq_map_prop,
  1357. "Cell %zu is not a phandle(%d)",
  1358. cell, phandle);
  1359. break;
  1360. }
  1361. provider_node = get_node_by_phandle(root, phandle);
  1362. if (!provider_node) {
  1363. FAIL_PROP(c, dti, node, irq_map_prop,
  1364. "Could not get phandle(%d) node for (cell %zu)",
  1365. phandle, cell);
  1366. break;
  1367. }
  1368. cellprop = get_property(provider_node, "#interrupt-cells");
  1369. if (cellprop) {
  1370. parent_cellsize = propval_cell(cellprop);
  1371. } else {
  1372. FAIL(c, dti, node, "Missing property '#interrupt-cells' in node %s or bad phandle (referred from interrupt-map[%zu])",
  1373. provider_node->fullpath, cell);
  1374. break;
  1375. }
  1376. cellprop = get_property(provider_node, "#address-cells");
  1377. if (cellprop)
  1378. parent_cellsize += propval_cell(cellprop);
  1379. cell += 1 + parent_cellsize;
  1380. }
  1381. }
  1382. WARNING(interrupt_map, check_interrupt_map, NULL, &phandle_references, &addr_size_cells, &interrupt_provider);
  1383. static void check_interrupts_property(struct check *c,
  1384. struct dt_info *dti,
  1385. struct node *node)
  1386. {
  1387. struct node *root = dti->dt;
  1388. struct node *irq_node = NULL, *parent = node;
  1389. struct property *irq_prop, *prop = NULL;
  1390. cell_t irq_cells, phandle;
  1391. irq_prop = get_property(node, "interrupts");
  1392. if (!irq_prop)
  1393. return;
  1394. if (!is_multiple_of(irq_prop->val.len, sizeof(cell_t)))
  1395. FAIL_PROP(c, dti, node, irq_prop, "size (%d) is invalid, expected multiple of %zu",
  1396. irq_prop->val.len, sizeof(cell_t));
  1397. while (parent && !prop) {
  1398. if (parent != node && node_is_interrupt_provider(parent)) {
  1399. irq_node = parent;
  1400. break;
  1401. }
  1402. prop = get_property(parent, "interrupt-parent");
  1403. if (prop) {
  1404. phandle = propval_cell(prop);
  1405. if (!phandle_is_valid(phandle)) {
  1406. /* Give up if this is an overlay with
  1407. * external references */
  1408. if (dti->dtsflags & DTSF_PLUGIN)
  1409. return;
  1410. FAIL_PROP(c, dti, parent, prop, "Invalid phandle");
  1411. continue;
  1412. }
  1413. irq_node = get_node_by_phandle(root, phandle);
  1414. if (!irq_node) {
  1415. FAIL_PROP(c, dti, parent, prop, "Bad phandle");
  1416. return;
  1417. }
  1418. if (!node_is_interrupt_provider(irq_node))
  1419. FAIL(c, dti, irq_node,
  1420. "Missing interrupt-controller or interrupt-map property");
  1421. break;
  1422. }
  1423. parent = parent->parent;
  1424. }
  1425. if (!irq_node) {
  1426. FAIL(c, dti, node, "Missing interrupt-parent");
  1427. return;
  1428. }
  1429. prop = get_property(irq_node, "#interrupt-cells");
  1430. if (!prop) {
  1431. /* We warn about that already in another test. */
  1432. return;
  1433. }
  1434. irq_cells = propval_cell(prop);
  1435. if (!is_multiple_of(irq_prop->val.len, irq_cells * sizeof(cell_t))) {
  1436. FAIL_PROP(c, dti, node, prop,
  1437. "size is (%d), expected multiple of %d",
  1438. irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)));
  1439. }
  1440. }
  1441. WARNING(interrupts_property, check_interrupts_property, &phandle_references);
  1442. static const struct bus_type graph_port_bus = {
  1443. .name = "graph-port",
  1444. };
  1445. static const struct bus_type graph_ports_bus = {
  1446. .name = "graph-ports",
  1447. };
  1448. static void check_graph_nodes(struct check *c, struct dt_info *dti,
  1449. struct node *node)
  1450. {
  1451. struct node *child;
  1452. for_each_child(node, child) {
  1453. if (!(strprefixeq(child->name, child->basenamelen, "endpoint") ||
  1454. get_property(child, "remote-endpoint")))
  1455. continue;
  1456. node->bus = &graph_port_bus;
  1457. /* The parent of 'port' nodes can be either 'ports' or a device */
  1458. if (!node->parent->bus &&
  1459. (streq(node->parent->name, "ports") || get_property(node, "reg")))
  1460. node->parent->bus = &graph_ports_bus;
  1461. break;
  1462. }
  1463. }
  1464. WARNING(graph_nodes, check_graph_nodes, NULL);
  1465. static void check_graph_child_address(struct check *c, struct dt_info *dti,
  1466. struct node *node)
  1467. {
  1468. int cnt = 0;
  1469. struct node *child;
  1470. if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus)
  1471. return;
  1472. for_each_child(node, child) {
  1473. struct property *prop = get_property(child, "reg");
  1474. /* No error if we have any non-zero unit address */
  1475. if (prop && propval_cell(prop) != 0)
  1476. return;
  1477. cnt++;
  1478. }
  1479. if (cnt == 1 && node->addr_cells != -1)
  1480. FAIL(c, dti, node, "graph node has single child node '%s', #address-cells/#size-cells are not necessary",
  1481. node->children->name);
  1482. }
  1483. WARNING(graph_child_address, check_graph_child_address, NULL, &graph_nodes);
  1484. static void check_graph_reg(struct check *c, struct dt_info *dti,
  1485. struct node *node)
  1486. {
  1487. char unit_addr[9];
  1488. const char *unitname = get_unitname(node);
  1489. struct property *prop;
  1490. prop = get_property(node, "reg");
  1491. if (!prop || !unitname)
  1492. return;
  1493. if (!(prop->val.val && prop->val.len == sizeof(cell_t))) {
  1494. FAIL(c, dti, node, "graph node malformed 'reg' property");
  1495. return;
  1496. }
  1497. snprintf(unit_addr, sizeof(unit_addr), "%x", propval_cell(prop));
  1498. if (!streq(unitname, unit_addr))
  1499. FAIL(c, dti, node, "graph node unit address error, expected \"%s\"",
  1500. unit_addr);
  1501. if (node->parent->addr_cells != 1)
  1502. FAIL_PROP(c, dti, node, get_property(node, "#address-cells"),
  1503. "graph node '#address-cells' is %d, must be 1",
  1504. node->parent->addr_cells);
  1505. if (node->parent->size_cells != 0)
  1506. FAIL_PROP(c, dti, node, get_property(node, "#size-cells"),
  1507. "graph node '#size-cells' is %d, must be 0",
  1508. node->parent->size_cells);
  1509. }
  1510. static void check_graph_port(struct check *c, struct dt_info *dti,
  1511. struct node *node)
  1512. {
  1513. if (node->bus != &graph_port_bus)
  1514. return;
  1515. if (!strprefixeq(node->name, node->basenamelen, "port"))
  1516. FAIL(c, dti, node, "graph port node name should be 'port'");
  1517. check_graph_reg(c, dti, node);
  1518. }
  1519. WARNING(graph_port, check_graph_port, NULL, &graph_nodes);
  1520. static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,
  1521. struct node *endpoint)
  1522. {
  1523. cell_t phandle;
  1524. struct node *node;
  1525. struct property *prop;
  1526. prop = get_property(endpoint, "remote-endpoint");
  1527. if (!prop)
  1528. return NULL;
  1529. phandle = propval_cell(prop);
  1530. /* Give up if this is an overlay with external references */
  1531. if (!phandle_is_valid(phandle))
  1532. return NULL;
  1533. node = get_node_by_phandle(dti->dt, phandle);
  1534. if (!node)
  1535. FAIL_PROP(c, dti, endpoint, prop, "graph phandle is not valid");
  1536. return node;
  1537. }
  1538. static void check_graph_endpoint(struct check *c, struct dt_info *dti,
  1539. struct node *node)
  1540. {
  1541. struct node *remote_node;
  1542. if (!node->parent || node->parent->bus != &graph_port_bus)
  1543. return;
  1544. if (!strprefixeq(node->name, node->basenamelen, "endpoint"))
  1545. FAIL(c, dti, node, "graph endpoint node name should be 'endpoint'");
  1546. check_graph_reg(c, dti, node);
  1547. remote_node = get_remote_endpoint(c, dti, node);
  1548. if (!remote_node)
  1549. return;
  1550. if (get_remote_endpoint(c, dti, remote_node) != node)
  1551. FAIL(c, dti, node, "graph connection to node '%s' is not bidirectional",
  1552. remote_node->fullpath);
  1553. }
  1554. WARNING(graph_endpoint, check_graph_endpoint, NULL, &graph_nodes);
  1555. static struct check *check_table[] = {
  1556. &duplicate_node_names, &duplicate_property_names,
  1557. &node_name_chars, &node_name_format, &property_name_chars,
  1558. &name_is_string, &name_properties, &node_name_vs_property_name,
  1559. &duplicate_label,
  1560. &explicit_phandles,
  1561. &phandle_references, &path_references,
  1562. &omit_unused_nodes,
  1563. &address_cells_is_cell, &size_cells_is_cell,
  1564. &device_type_is_string, &model_is_string, &status_is_string,
  1565. &label_is_string,
  1566. &compatible_is_string_list, &names_is_string_list,
  1567. &property_name_chars_strict,
  1568. &node_name_chars_strict,
  1569. &addr_size_cells, &reg_format, &ranges_format, &dma_ranges_format,
  1570. &unit_address_vs_reg,
  1571. &unit_address_format,
  1572. &pci_bridge,
  1573. &pci_device_reg,
  1574. &pci_device_bus_num,
  1575. &simple_bus_bridge,
  1576. &simple_bus_reg,
  1577. &i2c_bus_bridge,
  1578. &i2c_bus_reg,
  1579. &spi_bus_bridge,
  1580. &spi_bus_reg,
  1581. &avoid_default_addr_size,
  1582. &avoid_unnecessary_addr_size,
  1583. &unique_unit_address,
  1584. &unique_unit_address_if_enabled,
  1585. &obsolete_chosen_interrupt_controller,
  1586. &chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path,
  1587. &clocks_property,
  1588. &clocks_is_cell,
  1589. &cooling_device_property,
  1590. &cooling_device_is_cell,
  1591. &dmas_property,
  1592. &dmas_is_cell,
  1593. &hwlocks_property,
  1594. &hwlocks_is_cell,
  1595. &interrupts_extended_property,
  1596. &interrupts_extended_is_cell,
  1597. &io_channels_property,
  1598. &io_channels_is_cell,
  1599. &iommus_property,
  1600. &iommus_is_cell,
  1601. &mboxes_property,
  1602. &mboxes_is_cell,
  1603. &msi_parent_property,
  1604. &msi_parent_is_cell,
  1605. &mux_controls_property,
  1606. &mux_controls_is_cell,
  1607. &phys_property,
  1608. &phys_is_cell,
  1609. &power_domains_property,
  1610. &power_domains_is_cell,
  1611. &pwms_property,
  1612. &pwms_is_cell,
  1613. &resets_property,
  1614. &resets_is_cell,
  1615. &sound_dai_property,
  1616. &sound_dai_is_cell,
  1617. &thermal_sensors_property,
  1618. &thermal_sensors_is_cell,
  1619. &deprecated_gpio_property,
  1620. &gpios_property,
  1621. &interrupts_property,
  1622. &interrupt_provider,
  1623. &interrupt_map,
  1624. &alias_paths,
  1625. &graph_nodes, &graph_child_address, &graph_port, &graph_endpoint,
  1626. &always_fail,
  1627. };
  1628. static void enable_warning_error(struct check *c, bool warn, bool error)
  1629. {
  1630. int i;
  1631. /* Raising level, also raise it for prereqs */
  1632. if ((warn && !c->warn) || (error && !c->error))
  1633. for (i = 0; i < c->num_prereqs; i++)
  1634. enable_warning_error(c->prereq[i], warn, error);
  1635. c->warn = c->warn || warn;
  1636. c->error = c->error || error;
  1637. }
  1638. static void disable_warning_error(struct check *c, bool warn, bool error)
  1639. {
  1640. unsigned int i;
  1641. /* Lowering level, also lower it for things this is the prereq
  1642. * for */
  1643. if ((warn && c->warn) || (error && c->error)) {
  1644. for (i = 0; i < ARRAY_SIZE(check_table); i++) {
  1645. struct check *cc = check_table[i];
  1646. int j;
  1647. for (j = 0; j < cc->num_prereqs; j++)
  1648. if (cc->prereq[j] == c)
  1649. disable_warning_error(cc, warn, error);
  1650. }
  1651. }
  1652. c->warn = c->warn && !warn;
  1653. c->error = c->error && !error;
  1654. }
  1655. void parse_checks_option(bool warn, bool error, const char *arg)
  1656. {
  1657. unsigned int i;
  1658. const char *name = arg;
  1659. bool enable = true;
  1660. if ((strncmp(arg, "no-", 3) == 0)
  1661. || (strncmp(arg, "no_", 3) == 0)) {
  1662. name = arg + 3;
  1663. enable = false;
  1664. }
  1665. for (i = 0; i < ARRAY_SIZE(check_table); i++) {
  1666. struct check *c = check_table[i];
  1667. if (streq(c->name, name)) {
  1668. if (enable)
  1669. enable_warning_error(c, warn, error);
  1670. else
  1671. disable_warning_error(c, warn, error);
  1672. return;
  1673. }
  1674. }
  1675. die("Unrecognized check name \"%s\"\n", name);
  1676. }
  1677. void process_checks(bool force, struct dt_info *dti)
  1678. {
  1679. unsigned int i;
  1680. int error = 0;
  1681. for (i = 0; i < ARRAY_SIZE(check_table); i++) {
  1682. struct check *c = check_table[i];
  1683. if (c->warn || c->error)
  1684. error = error || run_check(c, dti);
  1685. }
  1686. if (error) {
  1687. if (!force) {
  1688. fprintf(stderr, "ERROR: Input tree has errors, aborting "
  1689. "(use -f to force output)\n");
  1690. exit(2);
  1691. } else if (quiet < 3) {
  1692. fprintf(stderr, "Warning: Input tree has errors, "
  1693. "output forced\n");
  1694. }
  1695. }
  1696. }