Skip to content

Commit

Permalink
rust: kernel: remove usage of allocator_api unstable feature
Browse files Browse the repository at this point in the history
With the adoption of `BoxExt` and `VecExt`, we don't need the functions
provided by this feature (namely the methods prefixed with `try_` and
different allocator per collection instance).

We do need `AllocError`, but we define our own as it is a trivial empty
struct.

Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
Link: https://lore.kernel.org/r/20240328013603.206764-11-wedsonaf@gmail.com
  • Loading branch information
wedsonaf authored and fbq committed Mar 29, 2024
1 parent 2f3d8d5 commit cdc13ea
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 15 deletions.
4 changes: 4 additions & 0 deletions rust/kernel/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ mod allocator;
pub mod box_ext;
pub mod vec_ext;

/// Indicates an allocation error.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct AllocError;

/// Flags to be used when allocating memory.
///
/// They can be combined with the operators `|`, `&`, and `!`.
Expand Down
3 changes: 1 addition & 2 deletions rust/kernel/alloc/box_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

//! Extensions to [`Box`] for fallible allocations.

use super::Flags;
use super::{AllocError, Flags};
use alloc::boxed::Box;
use core::alloc::AllocError;
use core::mem::MaybeUninit;
use core::result::Result;

Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/alloc/vec_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

//! Extensions to [`Vec`] for fallible allocations.

use super::Flags;
use alloc::{alloc::AllocError, vec::Vec};
use super::{AllocError, Flags};
use alloc::vec::Vec;
use core::result::Result;

/// Extensions to [`Vec`].
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//!
//! C header: [`include/uapi/asm-generic/errno-base.h`](srctree/include/uapi/asm-generic/errno-base.h)

use crate::str::CStr;
use crate::{alloc::AllocError, str::CStr};

use alloc::alloc::{AllocError, LayoutError};
use alloc::alloc::LayoutError;

use core::convert::From;
use core::fmt;
Expand Down
3 changes: 1 addition & 2 deletions rust/kernel/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,13 @@
//! [`pin_init!`]: crate::pin_init!

use crate::{
alloc::{box_ext::BoxExt, Flags},
alloc::{box_ext::BoxExt, AllocError, Flags},
error::{self, Error},
sync::UniqueArc,
types::{Opaque, ScopeGuard},
};
use alloc::boxed::Box;
use core::{
alloc::AllocError,
cell::UnsafeCell,
convert::Infallible,
marker::PhantomData,
Expand Down
1 change: 0 additions & 1 deletion rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//! do so first instead of bypassing this crate.

#![no_std]
#![feature(allocator_api)]
#![feature(coerce_unsized)]
#![feature(dispatch_from_dyn)]
#![feature(new_uninit)]
Expand Down
3 changes: 1 addition & 2 deletions rust/kernel/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

//! String representations.

use crate::alloc::{flags::*, vec_ext::VecExt};
use alloc::alloc::AllocError;
use crate::alloc::{flags::*, vec_ext::VecExt, AllocError};
use alloc::vec::Vec;
use core::fmt::{self, Write};
use core::ops::{self, Deref, Index};
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/sync/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html

use crate::{
alloc::{box_ext::BoxExt, Flags},
alloc::{box_ext::BoxExt, AllocError, Flags},
bindings,
error::{self, Error},
init::{self, InPlaceInit, Init, PinInit},
Expand All @@ -25,7 +25,7 @@ use crate::{
};
use alloc::boxed::Box;
use core::{
alloc::{AllocError, Layout},
alloc::Layout,
fmt,
marker::{PhantomData, Unsize},
mem::{ManuallyDrop, MaybeUninit},
Expand Down
3 changes: 1 addition & 2 deletions rust/kernel/workqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@
//!
//! C header: [`include/linux/workqueue.h`](srctree/include/linux/workqueue.h)

use crate::alloc::Flags;
use crate::alloc::{AllocError, Flags};
use crate::{bindings, prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
use alloc::alloc::AllocError;
use alloc::boxed::Box;
use core::marker::PhantomData;
use core::pin::Pin;
Expand Down

0 comments on commit cdc13ea

Please sign in to comment.