libfdt: Add FdtNodeMut::add_subnodes()

New API helps to add multiple subnodes at once.

Existing add_subnode() can't be used for the purpose because borrow
checker thinks that both self and the new subnode have mutable reference
of Fdt at once, even when the new node is dropped immediately.

Bug: 318431695
Test: atest liblibfdt.integration_test, TH
Change-Id: Ie490954a188362611e5175029b954536f837e283
diff --git a/libs/libfdt/tests/api_test.rs b/libs/libfdt/tests/api_test.rs
index 4b1877a..cafbf97 100644
--- a/libs/libfdt/tests/api_test.rs
+++ b/libs/libfdt/tests/api_test.rs
@@ -19,6 +19,7 @@
 use core::ffi::CStr;
 use cstr::cstr;
 use libfdt::{Fdt, FdtError, FdtNodeMut, Phandle};
+use std::collections::HashSet;
 use std::ffi::CString;
 use std::fs;
 use std::ops::Range;
@@ -451,6 +452,22 @@
 }
 
 #[test]
+fn node_mut_add_subnodes() {
+    let mut data = vec![0_u8; 1000];
+    let fdt = Fdt::create_empty_tree(&mut data).unwrap();
+
+    let mut root = fdt.root_mut().unwrap();
+    let names = [cstr!("a"), cstr!("b")];
+    root.add_subnodes(&names).unwrap();
+
+    let expected: HashSet<_> = names.into_iter().collect();
+    let subnodes = fdt.root().unwrap().subnodes().unwrap();
+    let names: HashSet<_> = subnodes.map(|node| node.name().unwrap()).collect();
+
+    assert_eq!(expected, names);
+}
+
+#[test]
 #[ignore] // Borrow checker test. Compilation success is sufficient.
 fn node_subnode_lifetime() {
     let data = fs::read(TEST_TREE_PHANDLE_PATH).unwrap();