Skip to content

rust: kernel: workqueue: deref on an immutable reference #900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: rust
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/kernel/workqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl Work {
// SAFETY: When the work was queued, a call to `into_raw` was made. We just canceled
// the work without it having the chance to run, so we need to explicitly destroy this
// reference (which would have happened in `work_func` if it did run).
unsafe { Ref::from_raw(&*self) };
unsafe { Ref::from_raw(self) };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing, but I think this is actually wrong. Work is not the thing put in a Ref, but the type containing Work. As such self should be value containing Work. Could you please take a look @wedsonaf?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, we need to do the same pointer arithmetic we do in work_func below to get to the right ptr.

Nice catch, @bjorn3

Now we don't have the type here anymore, so we either need to make Work generic or just store the offset is some field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option would be to change the function signature to fn cancel<A: WorkAdapter>(obj: Ref<A::Target>) I think.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that would be unsafe. Users could use the wrong adapter.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, sorry, I see now that it's passing the outer object.

}
}

Expand Down