MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_ofw_append_child

Function rt_ofw_append_child

components/drivers/ofw/base.c:1357–1414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1355}
1356
1357struct rt_ofw_node *rt_ofw_append_child(struct rt_ofw_node *parent, const char *full_name)
1358{
1359 rt_phandle phandle;
1360 rt_err_t err = RT_EOK;
1361 fdt32_t *phandle_value;
1362 struct rt_ofw_node *np = RT_NULL, *child;
1363
1364 if (full_name)
1365 {
1366 if ((phandle = ofw_phandle_next()))
1367 {
1368 np = rt_calloc(1, sizeof(*np) + sizeof(*phandle_value));
1369 }
1370 }
1371
1372 if (np)
1373 {
1374 parent = parent ? : ofw_node_root;
1375
1376 np->full_name = full_name;
1377 np->phandle = phandle;
1378 np->parent = parent;
1379
1380 rt_ref_init(&np->ref);
1381
1382 phandle_value = (void *)np + sizeof(*np);
1383 *phandle_value = cpu_to_fdt32(phandle);
1384
1385 err = rt_ofw_append_prop(np, "phandle", sizeof(*phandle_value), phandle_value);
1386
1387 if (!err)
1388 {
1389 if (parent->child)
1390 {
1391 rt_ofw_foreach_child_node(parent, child)
1392 {
1393 if (!child->sibling)
1394 {
1395 child->sibling = np;
1396 rt_ofw_node_put(child);
1397 break;
1398 }
1399 }
1400 }
1401 else
1402 {
1403 parent->child = np;
1404 }
1405 }
1406 else
1407 {
1408 rt_free(np);
1409 np = RT_NULL;
1410 }
1411 }
1412
1413 return rt_ofw_node_get(np);
1414}

Callers

nothing calls this directly

Calls 8

ofw_phandle_nextFunction · 0.85
rt_callocFunction · 0.85
rt_ref_initFunction · 0.85
rt_ofw_append_propFunction · 0.85
rt_ofw_node_putFunction · 0.85
rt_freeFunction · 0.85
rt_ofw_node_getFunction · 0.85
cpu_to_fdt32Function · 0.50

Tested by

no test coverage detected