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

Conversation

aliceinwire
Copy link

clippy error: if you would like to reborrow, try removing &*: self

Signed-off-by: Alice Ferrazzi [email protected]
Reviewed-by: Luca Barbato [email protected]

clippy error: if you would like to reborrow, try removing `&*`: `self`

Signed-off-by: Alice Ferrazzi <[email protected]>
Reviewed-by: Luca Barbato <[email protected]>
@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants