@@ -328,20 +328,24 @@ unsafe impl<T: AsBytes + FromBytes + Send> Send for CoherentAllocation<T> {}
328328#[ macro_export]
329329macro_rules! dma_read {
330330 ( $dma: expr, $idx: expr, $( $field: tt) * ) => { {
331- let item = $crate:: dma:: CoherentAllocation :: item_from_index( & $dma, $idx) ?;
332- // SAFETY: `item_from_index` ensures that `item` is always a valid pointer and can be
333- // dereferenced. The compiler also further validates the expression on whether `field`
334- // is a member of `item` when expanded by the macro.
335- unsafe {
336- let ptr_field = :: core:: ptr:: addr_of!( ( * item) $( $field) * ) ;
337- $crate:: dma:: CoherentAllocation :: field_read( & $dma, ptr_field)
338- }
331+ ( || -> :: core:: result:: Result <_, $crate:: error:: Error > {
332+ let item = $crate:: dma:: CoherentAllocation :: item_from_index( & $dma, $idx) ?;
333+ // SAFETY: `item_from_index` ensures that `item` is always a valid pointer and can be
334+ // dereferenced. The compiler also further validates the expression on whether `field`
335+ // is a member of `item` when expanded by the macro.
336+ unsafe {
337+ let ptr_field = :: core:: ptr:: addr_of!( ( * item) $( $field) * ) ;
338+ :: core:: result:: Result :: Ok (
339+ $crate:: dma:: CoherentAllocation :: field_read( & $dma, ptr_field)
340+ )
341+ }
342+ } ) ( )
339343 } } ;
340344 ( $dma: ident [ $idx: expr ] $( $field: tt) * ) => {
341- $crate:: dma_read!( $dma, $idx, $( $field) * ) ;
345+ $crate:: dma_read!( $dma, $idx, $( $field) * )
342346 } ;
343347 ( $( $dma: ident) .* [ $idx: expr ] $( $field: tt) * ) => {
344- $crate:: dma_read!( $( $dma) .* , $idx, $( $field) * ) ;
348+ $crate:: dma_read!( $( $dma) .* , $idx, $( $field) * )
345349 } ;
346350}
347351
@@ -368,24 +372,30 @@ macro_rules! dma_read {
368372#[ macro_export]
369373macro_rules! dma_write {
370374 ( $dma: ident [ $idx: expr ] $( $field: tt) * ) => { {
371- $crate:: dma_write!( $dma, $idx, $( $field) * ) ;
375+ $crate:: dma_write!( $dma, $idx, $( $field) * )
372376 } } ;
373377 ( $( $dma: ident) .* [ $idx: expr ] $( $field: tt) * ) => { {
374- $crate:: dma_write!( $( $dma) .* , $idx, $( $field) * ) ;
378+ $crate:: dma_write!( $( $dma) .* , $idx, $( $field) * )
375379 } } ;
376380 ( $dma: expr, $idx: expr, = $val: expr) => {
377- let item = $crate:: dma:: CoherentAllocation :: item_from_index( & $dma, $idx) ?;
378- // SAFETY: `item_from_index` ensures that `item` is always a valid item.
379- unsafe { $crate:: dma:: CoherentAllocation :: field_write( & $dma, item, $val) }
381+ ( || -> :: core:: result:: Result <_, $crate:: error:: Error > {
382+ let item = $crate:: dma:: CoherentAllocation :: item_from_index( & $dma, $idx) ?;
383+ // SAFETY: `item_from_index` ensures that `item` is always a valid item.
384+ unsafe { $crate:: dma:: CoherentAllocation :: field_write( & $dma, item, $val) }
385+ :: core:: result:: Result :: Ok ( ( ) )
386+ } ) ( )
380387 } ;
381388 ( $dma: expr, $idx: expr, $( . $field: ident) * = $val: expr) => {
382- let item = $crate:: dma:: CoherentAllocation :: item_from_index( & $dma, $idx) ?;
383- // SAFETY: `item_from_index` ensures that `item` is always a valid pointer and can be
384- // dereferenced. The compiler also further validates the expression on whether `field`
385- // is a member of `item` when expanded by the macro.
386- unsafe {
387- let ptr_field = :: core:: ptr:: addr_of_mut!( ( * item) $( . $field) * ) ;
388- $crate:: dma:: CoherentAllocation :: field_write( & $dma, ptr_field, $val)
389- }
389+ ( || -> :: core:: result:: Result <_, $crate:: error:: Error > {
390+ let item = $crate:: dma:: CoherentAllocation :: item_from_index( & $dma, $idx) ?;
391+ // SAFETY: `item_from_index` ensures that `item` is always a valid pointer and can be
392+ // dereferenced. The compiler also further validates the expression on whether `field`
393+ // is a member of `item` when expanded by the macro.
394+ unsafe {
395+ let ptr_field = :: core:: ptr:: addr_of_mut!( ( * item) $( . $field) * ) ;
396+ $crate:: dma:: CoherentAllocation :: field_write( & $dma, ptr_field, $val)
397+ }
398+ :: core:: result:: Result :: Ok ( ( ) )
399+ } ) ( )
390400 } ;
391401}
0 commit comments