@@ -4,7 +4,7 @@ use alloc::sync::Arc;
44use core:: sync:: atomic:: { AtomicBool , Ordering } ;
55use kernel:: {
66 io_buffer:: IoBufferWriter , linked_list:: Links , prelude:: * , sync:: Ref ,
7- user_ptr:: UserSlicePtrWriter ,
7+ user_ptr:: UserSlicePtrWriter , ScopeGuard ,
88} ;
99
1010use crate :: {
@@ -144,6 +144,10 @@ impl DeliverToRead for Transaction {
144144 pub sender_pid: pid_t,
145145 pub sender_euid: uid_t,
146146 */
147+ let send_failed_reply = ScopeGuard :: new ( || {
148+ let reply = Either :: Right ( BR_FAILED_REPLY ) ;
149+ self . from . deliver_reply ( reply, & self ) ;
150+ } ) ;
147151 let mut tr = BinderTransactionData :: default ( ) ;
148152
149153 if let Some ( nref) = & self . node_ref {
@@ -171,13 +175,13 @@ impl DeliverToRead for Transaction {
171175 BR_TRANSACTION
172176 } ;
173177
174- // Write the transaction code and data to the user buffer. On failure we complete the
175- // transaction with an error.
176- if let Err ( err ) = writer. write ( & code ) . and_then ( |_| writer . write ( & tr) ) {
177- let reply = Either :: Right ( BR_FAILED_REPLY ) ;
178- self . from . deliver_reply ( reply , & self ) ;
179- return Err ( err ) ;
180- }
178+ // Write the transaction code and data to the user buffer.
179+ writer . write ( & code ) ? ;
180+ writer. write ( & tr) ? ;
181+
182+ // Dismiss the completion of transaction with a failure. No failure paths are allowed from
183+ // here on out.
184+ send_failed_reply . dismiss ( ) ;
181185
182186 // When this is not a reply and not an async transaction, update `current_transaction`. If
183187 // it's a reply, `current_transaction` has already been updated appropriately.
0 commit comments