@@ -15,11 +15,12 @@ use crate::Property;
1515use crate :: error:: FdtMutError ;
1616use crate :: fdt:: property:: InnerPropIter ;
1717use crate :: fdt:: { FDT_TAGSIZE , Fdt , FdtProperty } ;
18+ use crate :: fdt_mut:: FdtMut ;
1819
1920/// A mutable property of a device tree node.
2021#[ derive( Debug ) ]
2122pub struct FdtPropertyMut < ' a > {
22- pub ( crate ) data : & ' a mut [ u8 ] ,
23+ pub ( crate ) data : FdtMut < ' a > ,
2324 pub ( crate ) nameoff : usize ,
2425 pub ( crate ) prop_offset : usize ,
2526 pub ( crate ) value_offset : usize ,
@@ -64,7 +65,7 @@ impl FdtPropertyMut<'_> {
6465
6566 // Update the length in the FDT property header
6667 let ( len_bytes, _) =
67- <big_endian:: U32 >:: mut_from_prefix ( & mut self . data [ self . prop_offset + FDT_TAGSIZE ..] )
68+ <big_endian:: U32 >:: mut_from_prefix ( & mut self . data . data [ self . prop_offset + FDT_TAGSIZE ..] )
6869 . expect ( "Fdt should be valid" ) ;
6970 len_bytes. set (
7071 new_value
@@ -74,12 +75,12 @@ impl FdtPropertyMut<'_> {
7475 ) ;
7576
7677 // Copy the new value
77- self . data [ self . value_offset ..self . value_offset + new_value. len ( ) ]
78+ self . data . data [ self . value_offset ..self . value_offset + new_value. len ( ) ]
7879 . copy_from_slice ( new_value) ;
7980
8081 // Zero out any padding bytes
8182 for i in new_value. len ( ) ..new_padded {
82- self . data [ self . value_offset + i] = 0 ;
83+ self . data . data [ self . value_offset + i] = 0 ;
8384 }
8485
8586 self . len = new_value. len ( ) ;
@@ -90,7 +91,7 @@ impl FdtPropertyMut<'_> {
9091 /// Returns the value of this property.
9192 #[ must_use]
9293 pub fn value ( & self ) -> & [ u8 ] {
93- & self . data [ self . value_offset ..self . value_offset + self . len ]
94+ & self . data . data [ self . value_offset ..self . value_offset + self . len ]
9495 }
9596
9697 /// Returns a read only view of this property.
@@ -100,7 +101,7 @@ impl FdtPropertyMut<'_> {
100101 /// Panics if the underlying device tree data is invalid.
101102 #[ must_use]
102103 pub fn as_read_only ( & self ) -> FdtProperty < ' _ > {
103- let fdt = Fdt { data : & * self . data } ;
104+ let fdt = self . data . as_read_only ( ) ;
104105 let name = fdt. string ( self . nameoff ) . expect ( "Fdt should be valid" ) ;
105106 let value = fdt
106107 . data
@@ -123,12 +124,12 @@ impl<'a> Property for &'a FdtPropertyMut<'_> {
123124 type CellsItem = crate :: Cells < ' a > ;
124125
125126 fn name ( & self ) -> & str {
126- let fdt = Fdt { data : & * self . data } ;
127+ let fdt = self . data . as_read_only ( ) ;
127128 fdt. string ( self . nameoff ) . expect ( "Fdt should be valid" )
128129 }
129130
130131 fn value ( & self ) -> & [ u8 ] {
131- let fdt = Fdt { data : & * self . data } ;
132+ let fdt = self . data . as_read_only ( ) ;
132133 fdt. data
133134 . get ( self . value_offset ..self . value_offset + self . len )
134135 . expect ( "Fdt should be valid" )
@@ -157,7 +158,7 @@ impl<'a> Property for &'a FdtPropertyMut<'_> {
157158/// A mutable iterator over the properties of a device tree node.
158159#[ derive( Debug ) ]
159160pub struct FdtPropMutIter < ' a > {
160- pub ( crate ) data : & ' a mut [ u8 ] ,
161+ pub ( crate ) data : FdtMut < ' a > ,
161162 pub ( crate ) inner : InnerPropIter ,
162163}
163164
@@ -168,14 +169,14 @@ impl FdtPropMutIter<'_> {
168169 ///
169170 /// Panics if the underlying device tree data is invalid.
170171 pub fn next ( & mut self ) -> Option < FdtPropertyMut < ' _ > > {
171- let fdt = Fdt :: new_unchecked ( & * self . data ) ;
172+ let fdt = self . data . as_read_only ( ) ;
172173 let parsed = self . inner . next ( fdt) ?;
173174 Some ( FdtPropertyMut {
174175 prop_offset : parsed. prop_offset ,
175176 value_offset : parsed. value_offset ,
176177 len : parsed. len ,
177178 nameoff : parsed. nameoff ,
178- data : self . data ,
179+ data : self . data . reborrow ( ) ,
179180 } )
180181 }
181182}
0 commit comments