Skip to content

Commit 28a2643

Browse files
committed
Rename KernelResult to just Result.
This is just a rename followed by `rustfmt`, no functional change is intended. Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent 99bec9d commit 28a2643

31 files changed

+148
-219
lines changed

drivers/android/allocation.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ impl<'a> Allocation<'a> {
3939
}
4040
}
4141

42-
fn iterate<T>(&self, mut offset: usize, mut size: usize, mut cb: T) -> KernelResult
42+
fn iterate<T>(&self, mut offset: usize, mut size: usize, mut cb: T) -> Result
4343
where
44-
T: FnMut(&Pages<0>, usize, usize) -> KernelResult,
44+
T: FnMut(&Pages<0>, usize, usize) -> Result,
4545
{
4646
// Check that the request is within the buffer.
4747
if offset.checked_add(size).ok_or(Error::EINVAL)? > self.size {
@@ -65,13 +65,13 @@ impl<'a> Allocation<'a> {
6565
reader: &mut UserSlicePtrReader,
6666
offset: usize,
6767
size: usize,
68-
) -> KernelResult {
68+
) -> Result {
6969
self.iterate(offset, size, |page, offset, to_copy| {
7070
page.copy_into_page(reader, offset, to_copy)
7171
})
7272
}
7373

74-
pub(crate) fn read<T>(&self, offset: usize) -> KernelResult<T> {
74+
pub(crate) fn read<T>(&self, offset: usize) -> Result<T> {
7575
let mut out = MaybeUninit::<T>::uninit();
7676
let mut out_offset = 0;
7777
self.iterate(offset, size_of::<T>(), |page, offset, to_copy| {
@@ -90,7 +90,7 @@ impl<'a> Allocation<'a> {
9090
Ok(unsafe { out.assume_init() })
9191
}
9292

93-
pub(crate) fn write<T>(&self, offset: usize, obj: &T) -> KernelResult {
93+
pub(crate) fn write<T>(&self, offset: usize, obj: &T) -> Result {
9494
let mut obj_offset = 0;
9595
self.iterate(offset, size_of::<T>(), |page, offset, to_copy| {
9696
// SAFETY: The sum of `offset` and `to_copy` is bounded by the size of T.
@@ -112,7 +112,7 @@ impl<'a> Allocation<'a> {
112112
self.allocation_info = Some(info);
113113
}
114114

115-
fn cleanup_object(&self, index_offset: usize, view: &AllocationView) -> KernelResult {
115+
fn cleanup_object(&self, index_offset: usize, view: &AllocationView) -> Result {
116116
let offset = self.read(index_offset)?;
117117
let header = view.read::<bindings::binder_object_header>(offset)?;
118118
// TODO: Handle other types.
@@ -169,14 +169,14 @@ impl<'a> AllocationView<'a> {
169169
AllocationView { alloc, limit }
170170
}
171171

172-
pub fn read<T>(&self, offset: usize) -> KernelResult<T> {
172+
pub fn read<T>(&self, offset: usize) -> Result<T> {
173173
if offset.checked_add(size_of::<T>()).ok_or(Error::EINVAL)? > self.limit {
174174
return Err(Error::EINVAL);
175175
}
176176
self.alloc.read(offset)
177177
}
178178

179-
pub fn write<T>(&self, offset: usize, obj: &T) -> KernelResult {
179+
pub fn write<T>(&self, offset: usize, obj: &T) -> Result {
180180
if offset.checked_add(size_of::<T>()).ok_or(Error::EINVAL)? > self.limit {
181181
return Err(Error::EINVAL);
182182
}

drivers/android/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ unsafe impl Send for Context {}
2424
unsafe impl Sync for Context {}
2525

2626
impl Context {
27-
pub(crate) fn new() -> KernelResult<Pin<Arc<Self>>> {
27+
pub(crate) fn new() -> Result<Pin<Arc<Self>>> {
2828
let mut ctx_ref = Arc::try_new(Self {
2929
// SAFETY: Init is called below.
3030
manager: unsafe {
@@ -44,7 +44,7 @@ impl Context {
4444
Ok(unsafe { Pin::new_unchecked(ctx_ref) })
4545
}
4646

47-
pub(crate) fn set_manager_node(&self, node_ref: NodeRef) -> KernelResult {
47+
pub(crate) fn set_manager_node(&self, node_ref: NodeRef) -> Result {
4848
let mut manager = self.manager.lock();
4949
if manager.node.is_some() {
5050
return Err(Error::EBUSY);

drivers/android/node.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,7 @@ impl GetLinks for NodeDeath {
170170
}
171171

172172
impl DeliverToRead for NodeDeath {
173-
fn do_work(
174-
self: Arc<Self>,
175-
_thread: &Thread,
176-
writer: &mut UserSlicePtrWriter,
177-
) -> KernelResult<bool> {
173+
fn do_work(self: Arc<Self>, _thread: &Thread, writer: &mut UserSlicePtrWriter) -> Result<bool> {
178174
let done = {
179175
let inner = self.inner.lock();
180176
if inner.aborted {
@@ -335,7 +331,7 @@ impl Node {
335331
inner.weak.has_count = true;
336332
}
337333

338-
fn write(&self, writer: &mut UserSlicePtrWriter, code: u32) -> KernelResult {
334+
fn write(&self, writer: &mut UserSlicePtrWriter, code: u32) -> Result {
339335
writer.write(&code)?;
340336
writer.write(&self.ptr)?;
341337
writer.write(&self.cookie)?;
@@ -344,11 +340,7 @@ impl Node {
344340
}
345341

346342
impl DeliverToRead for Node {
347-
fn do_work(
348-
self: Arc<Self>,
349-
_thread: &Thread,
350-
writer: &mut UserSlicePtrWriter,
351-
) -> KernelResult<bool> {
343+
fn do_work(self: Arc<Self>, _thread: &Thread, writer: &mut UserSlicePtrWriter) -> Result<bool> {
352344
let mut owner_inner = self.owner.inner.lock();
353345
let inner = self.inner.access_mut(&mut owner_inner);
354346
let strong = inner.strong.count > 0;

drivers/android/process.rs

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct Mapping {
4848
}
4949

5050
impl Mapping {
51-
fn new(address: usize, size: usize, pages: Arc<[Pages<0>]>) -> KernelResult<Self> {
51+
fn new(address: usize, size: usize, pages: Arc<[Pages<0>]>) -> Result<Self> {
5252
let alloc = RangeAllocator::new(size)?;
5353
Ok(Self {
5454
address,
@@ -162,7 +162,7 @@ impl ProcessInner {
162162
/// Returns an existing node with the given pointer and cookie, if one exists.
163163
///
164164
/// Returns an error if a node with the given pointer but a different cookie exists.
165-
fn get_existing_node(&self, ptr: usize, cookie: usize) -> KernelResult<Option<Arc<Node>>> {
165+
fn get_existing_node(&self, ptr: usize, cookie: usize) -> Result<Option<Arc<Node>>> {
166166
match self.nodes.get(&ptr) {
167167
None => Ok(None),
168168
Some(node) => {
@@ -185,7 +185,7 @@ impl ProcessInner {
185185
cookie: usize,
186186
strong: bool,
187187
thread: Option<&Thread>,
188-
) -> KernelResult<Option<NodeRef>> {
188+
) -> Result<Option<NodeRef>> {
189189
Ok(match self.get_existing_node(ptr, cookie)? {
190190
None => None,
191191
Some(node) => Some(self.new_node_ref(node, strong, thread)),
@@ -225,7 +225,7 @@ struct ArcReservation<T> {
225225
}
226226

227227
impl<T> ArcReservation<T> {
228-
fn new() -> KernelResult<Self> {
228+
fn new() -> Result<Self> {
229229
Ok(Self {
230230
mem: Arc::try_new(MaybeUninit::<T>::uninit())?,
231231
})
@@ -293,7 +293,7 @@ unsafe impl Send for Process {}
293293
unsafe impl Sync for Process {}
294294

295295
impl Process {
296-
fn new(ctx: Arc<Context>) -> KernelResult<Ref<Self>> {
296+
fn new(ctx: Arc<Context>) -> Result<Ref<Self>> {
297297
let mut proc_ref = Ref::try_new(Self {
298298
ref_count: RefCount::new(),
299299
ctx,
@@ -338,7 +338,7 @@ impl Process {
338338
Either::Right(Registration::new(self, thread, &mut inner))
339339
}
340340

341-
fn get_thread(&self, id: i32) -> KernelResult<Arc<Thread>> {
341+
fn get_thread(&self, id: i32) -> Result<Arc<Thread>> {
342342
// TODO: Consider using read/write locks here instead.
343343
{
344344
let inner = self.inner.lock();
@@ -367,7 +367,7 @@ impl Process {
367367
self.inner.lock().push_work(work)
368368
}
369369

370-
fn set_as_manager(&self, info: Option<FlatBinderObject>, thread: &Thread) -> KernelResult {
370+
fn set_as_manager(&self, info: Option<FlatBinderObject>, thread: &Thread) -> Result {
371371
let (ptr, cookie) = if let Some(obj) = info {
372372
(unsafe { obj.__bindgen_anon_1.binder }, obj.cookie)
373373
} else {
@@ -390,7 +390,7 @@ impl Process {
390390
cookie: usize,
391391
strong: bool,
392392
thread: Option<&Thread>,
393-
) -> KernelResult<NodeRef> {
393+
) -> Result<NodeRef> {
394394
// Try to find an existing node.
395395
{
396396
let mut inner = self.inner.lock();
@@ -416,7 +416,7 @@ impl Process {
416416
&self,
417417
node_ref: NodeRef,
418418
is_mananger: bool,
419-
) -> KernelResult<u32> {
419+
) -> Result<u32> {
420420
let mut refs = self.node_refs.lock();
421421

422422
// Do a lookup before inserting.
@@ -475,7 +475,7 @@ impl Process {
475475
drop(removed);
476476
}
477477

478-
pub(crate) fn update_ref(&self, handle: u32, inc: bool, strong: bool) -> KernelResult {
478+
pub(crate) fn update_ref(&self, handle: u32, inc: bool, strong: bool) -> Result {
479479
if inc && handle == 0 {
480480
if let Ok(node_ref) = self.ctx.get_manager_node(strong) {
481481
if core::ptr::eq(self, &*node_ref.node.owner) {
@@ -514,11 +514,7 @@ impl Process {
514514
}
515515
}
516516

517-
pub(crate) fn inc_ref_done(
518-
&self,
519-
reader: &mut UserSlicePtrReader,
520-
strong: bool,
521-
) -> KernelResult {
517+
pub(crate) fn inc_ref_done(&self, reader: &mut UserSlicePtrReader, strong: bool) -> Result {
522518
let ptr = reader.read::<usize>()?;
523519
let cookie = reader.read::<usize>()?;
524520
self.update_node(ptr, cookie, strong, true);
@@ -539,7 +535,7 @@ impl Process {
539535
))
540536
}
541537

542-
// TODO: Review if we want an Option or a KernelResult.
538+
// TODO: Review if we want an Option or a Result.
543539
pub(crate) fn buffer_get(&self, ptr: usize) -> Option<Allocation> {
544540
let mut inner = self.inner.lock();
545541
let mapping = inner.mapping.as_mut()?;
@@ -574,7 +570,7 @@ impl Process {
574570
}
575571
}
576572

577-
fn create_mapping(&self, vma: &mut bindings::vm_area_struct) -> KernelResult {
573+
fn create_mapping(&self, vma: &mut bindings::vm_area_struct) -> Result {
578574
let size = core::cmp::min(
579575
(vma.vm_end - vma.vm_start) as usize,
580576
bindings::SZ_4M as usize,
@@ -606,7 +602,7 @@ impl Process {
606602
Ok(())
607603
}
608604

609-
fn version(&self, data: UserSlicePtr) -> KernelResult {
605+
fn version(&self, data: UserSlicePtr) -> Result {
610606
data.writer().write(&BinderVersion::current())
611607
}
612608

@@ -623,7 +619,7 @@ impl Process {
623619
self.inner.lock().max_threads = max;
624620
}
625621

626-
fn get_node_debug_info(&self, data: UserSlicePtr) -> KernelResult {
622+
fn get_node_debug_info(&self, data: UserSlicePtr) -> Result {
627623
let (mut reader, mut writer) = data.reader_writer();
628624

629625
// Read the starting point.
@@ -643,7 +639,7 @@ impl Process {
643639
writer.write(&out)
644640
}
645641

646-
fn get_node_info_from_ref(&self, data: UserSlicePtr) -> KernelResult {
642+
fn get_node_info_from_ref(&self, data: UserSlicePtr) -> Result {
647643
let (mut reader, mut writer) = data.reader_writer();
648644
let mut out = reader.read::<BinderNodeInfoForRef>()?;
649645

@@ -686,11 +682,7 @@ impl Process {
686682
ret
687683
}
688684

689-
pub(crate) fn request_death(
690-
&self,
691-
reader: &mut UserSlicePtrReader,
692-
thread: &Thread,
693-
) -> KernelResult {
685+
pub(crate) fn request_death(&self, reader: &mut UserSlicePtrReader, thread: &Thread) -> Result {
694686
let handle: u32 = reader.read()?;
695687
let cookie: usize = reader.read()?;
696688

@@ -733,11 +725,7 @@ impl Process {
733725
Ok(())
734726
}
735727

736-
pub(crate) fn clear_death(
737-
&self,
738-
reader: &mut UserSlicePtrReader,
739-
thread: &Thread,
740-
) -> KernelResult {
728+
pub(crate) fn clear_death(&self, reader: &mut UserSlicePtrReader, thread: &Thread) -> Result {
741729
let handle: u32 = reader.read()?;
742730
let cookie: usize = reader.read()?;
743731

@@ -767,7 +755,7 @@ impl Process {
767755
}
768756

769757
impl IoctlHandler for Process {
770-
fn write(&self, _file: &File, cmd: u32, reader: &mut UserSlicePtrReader) -> KernelResult<i32> {
758+
fn write(&self, _file: &File, cmd: u32, reader: &mut UserSlicePtrReader) -> Result<i32> {
771759
let thread = self.get_thread(unsafe { rust_helper_current_pid() })?;
772760
match cmd {
773761
bindings::BINDER_SET_MAX_THREADS => self.set_max_threads(reader.read()?),
@@ -781,7 +769,7 @@ impl IoctlHandler for Process {
781769
Ok(0)
782770
}
783771

784-
fn read_write(&self, file: &File, cmd: u32, data: UserSlicePtr) -> KernelResult<i32> {
772+
fn read_write(&self, file: &File, cmd: u32, data: UserSlicePtr) -> Result<i32> {
785773
let thread = self.get_thread(unsafe { rust_helper_current_pid() })?;
786774
match cmd {
787775
bindings::BINDER_WRITE_READ => thread.write_read(data, file.is_blocking())?,
@@ -801,7 +789,7 @@ unsafe impl RefCounted for Process {
801789
}
802790

803791
impl FileOpener<Arc<Context>> for Process {
804-
fn open(ctx: &Arc<Context>) -> KernelResult<Self::Wrapper> {
792+
fn open(ctx: &Arc<Context>) -> Result<Self::Wrapper> {
805793
let process = Self::new(ctx.clone())?;
806794
// SAFETY: Pointer is pinned behind `Ref`.
807795
Ok(unsafe { Pin::new_unchecked(process) })
@@ -892,15 +880,15 @@ impl FileOperations for Process {
892880
}
893881
}
894882

895-
fn ioctl(&self, file: &File, cmd: &mut IoctlCommand) -> KernelResult<i32> {
883+
fn ioctl(&self, file: &File, cmd: &mut IoctlCommand) -> Result<i32> {
896884
cmd.dispatch(self, file)
897885
}
898886

899-
fn compat_ioctl(&self, file: &File, cmd: &mut IoctlCommand) -> KernelResult<i32> {
887+
fn compat_ioctl(&self, file: &File, cmd: &mut IoctlCommand) -> Result<i32> {
900888
cmd.dispatch(self, file)
901889
}
902890

903-
fn mmap(&self, _file: &File, vma: &mut bindings::vm_area_struct) -> KernelResult {
891+
fn mmap(&self, _file: &File, vma: &mut bindings::vm_area_struct) -> Result {
904892
// TODO: Only group leader is allowed to create mappings.
905893

906894
if vma.vm_start == 0 {
@@ -918,7 +906,7 @@ impl FileOperations for Process {
918906
self.create_mapping(vma)
919907
}
920908

921-
fn poll(&self, file: &File, table: &PollTable) -> KernelResult<u32> {
909+
fn poll(&self, file: &File, table: &PollTable) -> Result<u32> {
922910
let thread = self.get_thread(unsafe { rust_helper_current_pid() })?;
923911
let (from_proc, mut mask) = thread.poll(file, table);
924912
if mask == 0 && from_proc && !self.inner.lock().work.is_empty() {

drivers/android/range_alloc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enum DescriptorState {
2020
}
2121

2222
impl<T> RangeAllocator<T> {
23-
pub(crate) fn new(size: usize) -> KernelResult<Self> {
23+
pub(crate) fn new(size: usize) -> Result<Self> {
2424
let desc = Box::try_new(Descriptor::new(0, size))?;
2525
let mut list = List::new();
2626
list.push_back(desc);
@@ -49,7 +49,7 @@ impl<T> RangeAllocator<T> {
4949
best
5050
}
5151

52-
pub(crate) fn reserve_new(&mut self, size: usize) -> KernelResult<usize> {
52+
pub(crate) fn reserve_new(&mut self, size: usize) -> Result<usize> {
5353
let desc_ptr = match self.find_best_match(size) {
5454
None => return Err(Error::ENOMEM),
5555
Some(found) => found,
@@ -70,7 +70,7 @@ impl<T> RangeAllocator<T> {
7070
Ok(desc.offset)
7171
}
7272

73-
fn free_with_cursor(cursor: &mut CursorMut<Box<Descriptor<T>>>) -> KernelResult {
73+
fn free_with_cursor(cursor: &mut CursorMut<Box<Descriptor<T>>>) -> Result {
7474
let mut size = match cursor.current() {
7575
None => return Err(Error::EINVAL),
7676
Some(ref mut entry) => {
@@ -121,13 +121,13 @@ impl<T> RangeAllocator<T> {
121121
None
122122
}
123123

124-
pub(crate) fn reservation_abort(&mut self, offset: usize) -> KernelResult {
124+
pub(crate) fn reservation_abort(&mut self, offset: usize) -> Result {
125125
// TODO: The force case is currently O(n), but could be made O(1) with unsafe.
126126
let mut cursor = self.find_at_offset(offset).ok_or(Error::EINVAL)?;
127127
Self::free_with_cursor(&mut cursor)
128128
}
129129

130-
pub(crate) fn reservation_commit(&mut self, offset: usize, data: Option<T>) -> KernelResult {
130+
pub(crate) fn reservation_commit(&mut self, offset: usize, data: Option<T>) -> Result {
131131
// TODO: This is currently O(n), make it O(1).
132132
let mut cursor = self.find_at_offset(offset).ok_or(Error::ENOENT)?;
133133
let desc = cursor.current().unwrap();
@@ -140,7 +140,7 @@ impl<T> RangeAllocator<T> {
140140
/// [`DescriptorState::Reserved`].
141141
///
142142
/// Returns the size of the existing entry and the data associated with it.
143-
pub(crate) fn reserve_existing(&mut self, offset: usize) -> KernelResult<(usize, Option<T>)> {
143+
pub(crate) fn reserve_existing(&mut self, offset: usize) -> Result<(usize, Option<T>)> {
144144
// TODO: This is currently O(n), make it O(log n).
145145
let mut cursor = self.find_at_offset(offset).ok_or(Error::ENOENT)?;
146146
let desc = cursor.current().unwrap();

0 commit comments

Comments
 (0)