Skip to content

Commit 8df748e

Browse files
committed
binder: No need to pass alloc explicitly to translate_object.
Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent f78f590 commit 8df748e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

drivers/android/allocation.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ impl Drop for Allocation<'_> {
121121
}
122122

123123
if let Some(info) = &self.allocation_info {
124-
let view = AllocationView::new(self, info.offsets.start);
125-
for i in info.offsets.clone().step_by(size_of::<usize>()) {
124+
let offsets = info.offsets.clone();
125+
let view = AllocationView::new(self, offsets.start);
126+
for i in offsets.step_by(size_of::<usize>()) {
126127
if view.cleanup_object(i).is_err() {
127128
pr_warn!("Error cleaning up object at offset {}\n", i)
128129
}
@@ -133,13 +134,13 @@ impl Drop for Allocation<'_> {
133134
}
134135
}
135136

136-
pub(crate) struct AllocationView<'a> {
137-
alloc: &'a Allocation<'a>,
137+
pub(crate) struct AllocationView<'a, 'b> {
138+
pub(crate) alloc: &'a mut Allocation<'b>,
138139
limit: usize,
139140
}
140141

141-
impl<'a> AllocationView<'a> {
142-
pub(crate) fn new(alloc: &'a Allocation, limit: usize) -> Self {
142+
impl<'a, 'b> AllocationView<'a, 'b> {
143+
pub(crate) fn new(alloc: &'a mut Allocation<'b>, limit: usize) -> Self {
143144
AllocationView { alloc, limit }
144145
}
145146

drivers/android/thread.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,10 @@ impl Thread {
376376
fn translate_object(
377377
&self,
378378
index_offset: usize,
379-
alloc: &Allocation,
380379
view: &AllocationView,
381380
allow_fds: bool,
382381
) -> BinderResult {
383-
let offset = alloc.read(index_offset)?;
382+
let offset = view.alloc.read(index_offset)?;
384383
let header = view.read::<bindings::binder_object_header>(offset)?;
385384
// TODO: Handle other types.
386385
match header.type_ {
@@ -421,9 +420,9 @@ impl Thread {
421420
end: usize,
422421
allow_fds: bool,
423422
) -> BinderResult {
424-
let view = AllocationView::new(&alloc, start);
423+
let view = AllocationView::new(alloc, start);
425424
for i in (start..end).step_by(size_of::<usize>()) {
426-
if let Err(err) = self.translate_object(i, alloc, &view, allow_fds) {
425+
if let Err(err) = self.translate_object(i, &view, allow_fds) {
427426
alloc.set_info(AllocationInfo { offsets: start..i });
428427
return Err(err);
429428
}

0 commit comments

Comments
 (0)