Skip to content

Commit e2df391

Browse files
authored
Merge pull request #552 from wedsonaf/pin-ref
rust: remove instances of `Pin<Ref<T>>`.
2 parents b65c684 + cde4370 commit e2df391

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
@@ -34,8 +34,8 @@ struct SharedState {
3434
}
3535

3636
impl SharedState {
37-
fn try_new() -> Result<Pin<Ref<Self>>> {
38-
Ok(Ref::pinned(Ref::try_new_and_init(
37+
fn try_new() -> Result<Ref<Self>> {
38+
Ref::try_new_and_init(
3939
Self {
4040
// SAFETY: `condvar_init!` is called below.
4141
state_changed: unsafe { CondVar::new() },
@@ -50,20 +50,20 @@ impl SharedState {
5050
let pinned = unsafe { state.as_mut().map_unchecked_mut(|s| &mut s.inner) };
5151
kernel::mutex_init!(pinned, "SharedState::inner");
5252
},
53-
)?))
53+
)
5454
}
5555
}
5656

5757
struct Token;
5858

59-
impl FileOpener<Pin<Ref<SharedState>>> for Token {
60-
fn open(shared: &Pin<Ref<SharedState>>) -> Result<Self::Wrapper> {
59+
impl FileOpener<Ref<SharedState>> for Token {
60+
fn open(shared: &Ref<SharedState>) -> Result<Self::Wrapper> {
6161
Ok(shared.clone())
6262
}
6363
}
6464

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

6868
kernel::declare_file_operations!(read, write);
6969

@@ -127,7 +127,7 @@ impl FileOperations for Token {
127127
}
128128

129129
struct RustMiscdev {
130-
_dev: Pin<Box<miscdev::Registration<Pin<Ref<SharedState>>>>>,
130+
_dev: Pin<Box<miscdev::Registration<Ref<SharedState>>>>,
131131
}
132132

133133
impl KernelModule for RustMiscdev {

0 commit comments

Comments
 (0)