Skip to content

Commit a5aa111

Browse files
committed
binder: Use ScopeGuard on transaction processing.
This is in preparation for introducing additional error paths that require sending an error reply to the transaction issuer, but return a success result to the function caller. Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent 1157c24 commit a5aa111

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/android/transaction.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloc::sync::Arc;
44
use core::sync::atomic::{AtomicBool, Ordering};
55
use kernel::{
66
io_buffer::IoBufferWriter, linked_list::Links, prelude::*, sync::Ref,
7-
user_ptr::UserSlicePtrWriter,
7+
user_ptr::UserSlicePtrWriter, ScopeGuard,
88
};
99

1010
use crate::{
@@ -142,6 +142,10 @@ impl DeliverToRead for Transaction {
142142
pub sender_pid: pid_t,
143143
pub sender_euid: uid_t,
144144
*/
145+
let send_failed_reply = ScopeGuard::new(|| {
146+
let reply = Either::Right(BR_FAILED_REPLY);
147+
self.from.deliver_reply(reply, &self);
148+
});
145149
let mut tr = BinderTransactionData::default();
146150

147151
if let Some(nref) = &self.node_ref {
@@ -169,13 +173,13 @@ impl DeliverToRead for Transaction {
169173
BR_TRANSACTION
170174
};
171175

172-
// Write the transaction code and data to the user buffer. On failure we complete the
173-
// transaction with an error.
174-
if let Err(err) = writer.write(&code).and_then(|_| writer.write(&tr)) {
175-
let reply = Either::Right(BR_FAILED_REPLY);
176-
self.from.deliver_reply(reply, &self);
177-
return Err(err);
178-
}
176+
// Write the transaction code and data to the user buffer.
177+
writer.write(&code)?;
178+
writer.write(&tr)?;
179+
180+
// Dismiss the completion of transaction with a failure. No failure paths are allowed from
181+
// here on out.
182+
send_failed_reply.dismiss();
179183

180184
// When this is not a reply and not an async transaction, update `current_transaction`. If
181185
// it's a reply, `current_transaction` has already been updated appropriately.

0 commit comments

Comments
 (0)