@@ -6,10 +6,9 @@
use crate::{
bindings,
- str::CStr,
types::{ARef, Opaque},
};
-use core::{fmt, ptr};
+use core::{ffi::CStr, fmt, ptr};
#[cfg(CONFIG_PRINTK)]
use crate::str::CStrExt as _;
@@ -6,8 +6,8 @@
//! register using the [`Registration`] class.
use crate::error::{Error, Result};
-use crate::{device, init::PinInit, of, str::CStr, try_pin_init, types::Opaque, ThisModule};
-use core::pin::Pin;
+use crate::{device, init::PinInit, of, try_pin_init, types::Opaque, ThisModule};
+use core::{ffi::CStr, pin::Pin};
use macros::{pin_data, pinned_drop};
/// The [`RegistrationOps`] trait serves as generic interface for subsystems (e.g., PCI, Platform,
@@ -4,11 +4,9 @@
//!
//! C header: [`include/uapi/asm-generic/errno-base.h`](srctree/include/uapi/asm-generic/errno-base.h)
-use crate::{
- alloc::{layout::LayoutError, AllocError},
- str::CStr,
-};
+use crate::alloc::{layout::LayoutError, AllocError};
+use core::ffi::CStr;
use core::fmt;
use core::num::NonZeroI32;
use core::num::TryFromIntError;
@@ -4,7 +4,8 @@
//!
//! C header: [`include/linux/firmware.h`](srctree/include/linux/firmware.h)
-use crate::{bindings, device::Device, error::Error, error::Result, str::CStr};
+use crate::{bindings, device::Device, error::Error, error::Result};
+use core::ffi::CStr;
use core::ptr::NonNull;
/// # Invariants
@@ -56,10 +56,10 @@ macro_rules! kunit_assert {
break 'out;
}
- static NAME: &'static $crate::str::CStr = $crate::c_str_avoid_literals!($name);
- static FILE: &'static $crate::str::CStr = $crate::c_str_avoid_literals!($file);
+ static NAME: &'static core::ffi::CStr = $crate::c_str_avoid_literals!($name);
+ static FILE: &'static core::ffi::CStr = $crate::c_str_avoid_literals!($file);
static LINE: i32 = core::line!() as i32 - $diff;
- static CONDITION: &'static $crate::str::CStr =
+ static CONDITION: &'static core::ffi::CStr =
$crate::c_str_avoid_literals!(stringify!($condition));
// SAFETY: FFI call without safety requirements.
@@ -132,7 +132,7 @@ fn init(module: &'static ThisModule) -> impl init::PinInit<Self, error::Error> {
/// Metadata attached to a [`Module`] or [`InPlaceModule`].
pub trait ModuleMetadata {
/// The name of the module as specified in the `module!` macro.
- const NAME: &'static crate::str::CStr;
+ const NAME: &'static core::ffi::CStr;
}
/// Equivalent to `THIS_MODULE` in the C API.
@@ -16,10 +16,9 @@
fs::File,
prelude::*,
seq_file::SeqFile,
- str::CStr,
types::{ForeignOwnable, Opaque},
};
-use core::{marker::PhantomData, mem::MaybeUninit, pin::Pin};
+use core::{ffi::CStr, marker::PhantomData, mem::MaybeUninit, pin::Pin};
/// Options for creating a misc device.
#[derive(Copy, Clone)]
@@ -2,7 +2,8 @@
//! Device Tree / Open Firmware abstractions.
-use crate::{bindings, device_id::RawDeviceId, prelude::*};
+use crate::{bindings, device_id::RawDeviceId};
+use core::ffi::CStr;
/// IdTable type for OF drivers.
pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<DeviceId, T>;
@@ -13,11 +13,10 @@
error::{to_result, Result},
io::Io,
io::IoRaw,
- str::CStr,
types::{ARef, ForeignOwnable, Opaque},
ThisModule,
};
-use core::{ops::Deref, ptr::addr_of_mut};
+use core::{ffi::CStr, ops::Deref, ptr::addr_of_mut};
use kernel::prelude::*;
/// An adapter for the registration of PCI drivers.
@@ -9,12 +9,11 @@
error::{to_result, Result},
of,
prelude::*,
- str::CStr,
types::{ARef, ForeignOwnable, Opaque},
ThisModule,
};
-use core::ptr::addr_of_mut;
+use core::{ffi::CStr, ptr::addr_of_mut};
/// An adapter for the registration of platform drivers.
pub struct Adapter<T: Driver>(T);
@@ -34,10 +34,7 @@
pub use super::error::{code::*, Error, Result};
-pub use super::{
- str::{CStr, CStrExt as _},
- ThisModule,
-};
+pub use super::{str::CStrExt as _, ThisModule};
pub use super::init::{InPlaceInit, InPlaceWrite, Init, PinInit};
@@ -3,6 +3,7 @@
//! String representations.
use crate::alloc::{flags::*, AllocError, KVec};
+use core::ffi::CStr;
use core::fmt::{self, Write};
use core::ops::{Deref, DerefMut};
@@ -177,8 +178,6 @@ macro_rules! b_str {
}};
}
-pub use core::ffi::CStr;
-
/// Returns a C pointer to the string.
// It is a free function rather than a method on an extension trait because:
//
@@ -381,7 +380,7 @@ fn as_ref(&self) -> &BStr {
///
/// ```
/// # use kernel::c_str_avoid_literals;
-/// # use kernel::str::CStr;
+/// # use core::ffi::CStr;
/// const MY_CSTR: &CStr = c_str_avoid_literals!(concat!(file!(), ":", line!(), ": My CStr!"));
/// ```
#[macro_export]
@@ -391,13 +390,13 @@ macro_rules! c_str_avoid_literals {
// too limiting to macro authors, so we rely on the name as a hint instead.
($str:expr) => {{
const S: &'static str = concat!($str, "\0");
- const C: &'static $crate::str::CStr =
- match $crate::str::CStr::from_bytes_with_nul(S.as_bytes()) {
- Ok(v) => v,
- Err(core::ffi::FromBytesWithNulError { .. }) => {
- panic!("string contains interior NUL")
- }
- };
+ const C: &'static core::ffi::CStr = match core::ffi::CStr::from_bytes_with_nul(S.as_bytes())
+ {
+ Ok(v) => v,
+ Err(core::ffi::FromBytesWithNulError { .. }) => {
+ panic!("string contains interior NUL")
+ }
+ };
C
}};
}
@@ -10,11 +10,12 @@
ffi::{c_int, c_long},
init::PinInit,
pin_init,
- str::{CStr, CStrExt as _},
+ str::CStrExt as _,
task::{MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE, TASK_NORMAL, TASK_UNINTERRUPTIBLE},
time::Jiffies,
types::Opaque,
};
+use core::ffi::CStr;
use core::marker::PhantomPinned;
use core::ptr;
use macros::pin_data;
@@ -9,10 +9,10 @@
use crate::{
init::PinInit,
pin_init,
- str::{CStr, CStrExt as _},
+ str::CStrExt as _,
types::{NotThreadSafe, Opaque, ScopeGuard},
};
-use core::{cell::UnsafeCell, marker::PhantomPinned};
+use core::{cell::UnsafeCell, ffi::CStr, marker::PhantomPinned};
use macros::pin_data;
pub mod mutex;
@@ -5,13 +5,14 @@
//! Support for defining statics containing locks.
use crate::{
- str::{CStr, CStrExt as _},
+ str::CStrExt as _,
sync::lock::{Backend, Guard, Lock},
sync::{LockClassKey, LockedBy},
types::Opaque,
};
use core::{
cell::UnsafeCell,
+ ffi::CStr,
marker::{PhantomData, PhantomPinned},
};
@@ -266,7 +267,7 @@ macro_rules! global_lock {
$pub enum $name {}
impl $crate::sync::lock::GlobalLockBackend for $name {
- const NAME: &'static $crate::str::CStr =
+ const NAME: &'static core::ffi::CStr =
$crate::c_str_avoid_literals!(::core::stringify!($name));
type Item = $valuety;
type Backend = $crate::global_lock_inner!(backend $kind);
@@ -11,6 +11,7 @@
sync::{CondVar, LockClassKey},
types::Opaque,
};
+use core::ffi::CStr;
use core::ops::Deref;
/// Creates a [`PollCondVar`] initialiser with the given name and a newly-created lock class.
@@ -135,6 +135,7 @@
use crate::alloc::{AllocError, Flags};
use crate::{prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
+use core::ffi::CStr;
use core::marker::PhantomData;
/// Creates a [`Work`] initialiser with the given name and a newly-created lock class.
@@ -229,7 +229,7 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
}};
impl kernel::ModuleMetadata for {type_} {{
- const NAME: &'static kernel::str::CStr = c\"{name}\";
+ const NAME: &'static core::ffi::CStr = c\"{name}\";
}}
// Double nested modules, since then nobody can access the public items inside.
Clean up references to `kernel::str::CStr`. Signed-off-by: Tamir Duberstein <tamird@gmail.com> --- rust/kernel/device.rs | 3 +-- rust/kernel/driver.rs | 4 ++-- rust/kernel/error.rs | 6 ++---- rust/kernel/firmware.rs | 3 ++- rust/kernel/kunit.rs | 6 +++--- rust/kernel/lib.rs | 2 +- rust/kernel/miscdevice.rs | 3 +-- rust/kernel/of.rs | 3 ++- rust/kernel/pci.rs | 3 +-- rust/kernel/platform.rs | 3 +-- rust/kernel/prelude.rs | 5 +---- rust/kernel/str.rs | 19 +++++++++---------- rust/kernel/sync/condvar.rs | 3 ++- rust/kernel/sync/lock.rs | 4 ++-- rust/kernel/sync/lock/global.rs | 5 +++-- rust/kernel/sync/poll.rs | 1 + rust/kernel/workqueue.rs | 1 + rust/macros/module.rs | 2 +- 18 files changed, 36 insertions(+), 40 deletions(-)