Skip to content

Commit f78f590

Browse files
committed
binder: Move cleanup_object from Allocation to AllocationView.
Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent 5bb76a6 commit f78f590

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

drivers/android/allocation.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,33 +112,6 @@ impl<'a> Allocation<'a> {
112112
pub(crate) fn set_info(&mut self, info: AllocationInfo) {
113113
self.allocation_info = Some(info);
114114
}
115-
116-
fn cleanup_object(&self, index_offset: usize, view: &AllocationView) -> Result {
117-
let offset = self.read(index_offset)?;
118-
let header = view.read::<bindings::binder_object_header>(offset)?;
119-
// TODO: Handle other types.
120-
match header.type_ {
121-
BINDER_TYPE_WEAK_BINDER | BINDER_TYPE_BINDER => {
122-
let obj = view.read::<bindings::flat_binder_object>(offset)?;
123-
let strong = header.type_ == BINDER_TYPE_BINDER;
124-
// SAFETY: The type is `BINDER_TYPE_{WEAK_}BINDER`, so the `binder` field is
125-
// populated.
126-
let ptr = unsafe { obj.__bindgen_anon_1.binder } as usize;
127-
let cookie = obj.cookie as usize;
128-
self.process.update_node(ptr, cookie, strong, false);
129-
Ok(())
130-
}
131-
BINDER_TYPE_WEAK_HANDLE | BINDER_TYPE_HANDLE => {
132-
let obj = view.read::<bindings::flat_binder_object>(offset)?;
133-
let strong = header.type_ == BINDER_TYPE_HANDLE;
134-
// SAFETY: The type is `BINDER_TYPE_{WEAK_}HANDLE`, so the `handle` field is
135-
// populated.
136-
let handle = unsafe { obj.__bindgen_anon_1.handle } as _;
137-
self.process.update_ref(handle, false, strong)
138-
}
139-
_ => Ok(()),
140-
}
141-
}
142115
}
143116

144117
impl Drop for Allocation<'_> {
@@ -150,7 +123,7 @@ impl Drop for Allocation<'_> {
150123
if let Some(info) = &self.allocation_info {
151124
let view = AllocationView::new(self, info.offsets.start);
152125
for i in info.offsets.clone().step_by(size_of::<usize>()) {
153-
if self.cleanup_object(i, &view).is_err() {
126+
if view.cleanup_object(i).is_err() {
154127
pr_warn!("Error cleaning up object at offset {}\n", i)
155128
}
156129
}
@@ -250,4 +223,31 @@ impl<'a> AllocationView<'a> {
250223
}
251224
Ok(())
252225
}
226+
227+
fn cleanup_object(&self, index_offset: usize) -> Result {
228+
let offset = self.alloc.read(index_offset)?;
229+
let header = self.read::<bindings::binder_object_header>(offset)?;
230+
// TODO: Handle other types.
231+
match header.type_ {
232+
BINDER_TYPE_WEAK_BINDER | BINDER_TYPE_BINDER => {
233+
let obj = self.read::<bindings::flat_binder_object>(offset)?;
234+
let strong = header.type_ == BINDER_TYPE_BINDER;
235+
// SAFETY: The type is `BINDER_TYPE_{WEAK_}BINDER`, so the `binder` field is
236+
// populated.
237+
let ptr = unsafe { obj.__bindgen_anon_1.binder } as usize;
238+
let cookie = obj.cookie as usize;
239+
self.alloc.process.update_node(ptr, cookie, strong, false);
240+
Ok(())
241+
}
242+
BINDER_TYPE_WEAK_HANDLE | BINDER_TYPE_HANDLE => {
243+
let obj = self.read::<bindings::flat_binder_object>(offset)?;
244+
let strong = header.type_ == BINDER_TYPE_HANDLE;
245+
// SAFETY: The type is `BINDER_TYPE_{WEAK_}HANDLE`, so the `handle` field is
246+
// populated.
247+
let handle = unsafe { obj.__bindgen_anon_1.handle } as _;
248+
self.alloc.process.update_ref(handle, false, strong)
249+
}
250+
_ => Ok(()),
251+
}
252+
}
253253
}

0 commit comments

Comments
 (0)