Skip to content

Commit cde4370

Browse files
committed
rust: remove instances of Pin<Ref<T>>.
Since `Ref<T>` is already pinned, there is no need to wrap it in `Pin`. Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent 4946eec commit cde4370

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

drivers/android/process.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ unsafe impl Send for Process {}
260260
unsafe impl Sync for Process {}
261261

262262
impl Process {
263-
fn new(ctx: Ref<Context>) -> Result<Pin<Ref<Self>>> {
264-
Ok(Ref::pinned(Ref::try_new_and_init(
263+
fn new(ctx: Ref<Context>) -> Result<Ref<Self>> {
264+
Ref::try_new_and_init(
265265
Self {
266266
ctx,
267267
task: Task::current().group_leader().clone(),
@@ -278,7 +278,7 @@ impl Process {
278278
let pinned = unsafe { process.as_mut().map_unchecked_mut(|p| &mut p.node_refs) };
279279
kernel::mutex_init!(pinned, "Process::node_refs");
280280
},
281-
)?))
281+
)
282282
}
283283

284284
/// Attemps to fetch a work item from the process queue.
@@ -797,7 +797,7 @@ impl FileOpener<Ref<Context>> for Process {
797797
}
798798

799799
impl FileOperations for Process {
800-
type Wrapper = Pin<Ref<Self>>;
800+
type Wrapper = Ref<Self>;
801801

802802
kernel::declare_file_operations!(ioctl, compat_ioctl, mmap, poll);
803803

rust/kernel/sync/arc.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,6 @@ impl<T: ?Sized> Ref<T> {
159159
ptr::eq(a.ptr.as_ptr(), b.ptr.as_ptr())
160160
}
161161

162-
/// Returns a pinned version of a given `Ref` instance.
163-
pub fn pinned(obj: Self) -> Pin<Self> {
164-
// SAFETY: The type invariants guarantee that the value is pinned.
165-
unsafe { Pin::new_unchecked(obj) }
166-
}
167-
168162
/// Deconstructs a [`Ref`] object into a raw pointer.
169163
///
170164
/// It can be reconstructed once via [`Ref::from_raw`].

samples/rust/rust_miscdev.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ struct SharedState {
3636
}
3737

3838
impl SharedState {
39-
fn try_new() -> Result<Pin<Ref<Self>>> {
40-
Ok(Ref::pinned(Ref::try_new_and_init(
39+
fn try_new() -> Result<Ref<Self>> {
40+
Ref::try_new_and_init(
4141
Self {
4242
// SAFETY: `condvar_init!` is called below.
4343
state_changed: unsafe { CondVar::new() },
@@ -52,20 +52,20 @@ impl SharedState {
5252
let pinned = unsafe { state.as_mut().map_unchecked_mut(|s| &mut s.inner) };
5353
kernel::mutex_init!(pinned, "SharedState::inner");
5454
},
55-
)?))
55+
)
5656
}
5757
}
5858

5959
struct Token;
6060

61-
impl FileOpener<Pin<Ref<SharedState>>> for Token {
62-
fn open(shared: &Pin<Ref<SharedState>>) -> Result<Self::Wrapper> {
61+
impl FileOpener<Ref<SharedState>> for Token {
62+
fn open(shared: &Ref<SharedState>) -> Result<Self::Wrapper> {
6363
Ok(shared.clone())
6464
}
6565
}
6666

6767
impl FileOperations for Token {
68-
type Wrapper = Pin<Ref<SharedState>>;
68+
type Wrapper = Ref<SharedState>;
6969

7070
kernel::declare_file_operations!(read, write);
7171

@@ -129,7 +129,7 @@ impl FileOperations for Token {
129129
}
130130

131131
struct RustMiscdev {
132-
_dev: Pin<Box<miscdev::Registration<Pin<Ref<SharedState>>>>>,
132+
_dev: Pin<Box<miscdev::Registration<Ref<SharedState>>>>,
133133
}
134134

135135
impl KernelModule for RustMiscdev {

0 commit comments

Comments
 (0)