Skip to content

rust: add device::Data. #570

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

Merged
merged 1 commit into from
Nov 30, 2021
Merged

Conversation

wedsonaf
Copy link

@wedsonaf wedsonaf commented Nov 26, 2021

This allows access to registrations and io resources to be automatically
revoked when devices are removed, even if the ref count to their state
is non-zero.

This is the last piece needed by the PL061 driver.

Signed-off-by: Wedson Almeida Filho [email protected]

@wedsonaf
Copy link
Author

Rebased.

@wedsonaf
Copy link
Author

Fixed issues reported by bjorn3. PTAL.

Comment on lines 106 to 107
regs: RevocableMutex<Reg>,
res: Revocable<Res>,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe write these out fully? I initially confused regs for registers.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I'll make this change.

#[doc(hidden)]
#[macro_export]
macro_rules! new_device_data {
($reg:expr, $res:expr, $gen:expr, $name:literal) => {{
Copy link
Member

Choose a reason for hiding this comment

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

I think there is the potential for people to mess up the order of the fields. Maybe do

let data = new_device_data! {
    registration: reg,
    resource: res,
    general: gen,
    name: "foo",
};

? With a potential shorthand when the variable name matches the field name just like with struct.

Copy link
Author

Choose a reason for hiding this comment

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

The types are different and need to be spelled out elsewhere (as opposed to being inferred) because this is usually the Data type of a Driver trait. Here's an example of it being used: https://github.com/Rust-for-Linux/linux/pull/571/files#diff-0b4ec144d8f0479a497eca5a2e4ab8c1009b0debcdb00ece09f79e5baa8faac9R272

IOW, if people mess up the order, they'll get a compilation error.

@bjorn3
Copy link
Member

bjorn3 commented Nov 27, 2021

All unsafe code LGTM.

This allows access to registrations and io resources to be automatically
revoked when devices are removed, even if the ref count to their state
is non-zero.

This is the last piece needed by the PL061 driver.

Signed-off-by: Wedson Almeida Filho <[email protected]>
@wedsonaf wedsonaf merged commit c708e80 into Rust-for-Linux:rust Nov 30, 2021
@wedsonaf wedsonaf deleted the device-data branch November 30, 2021 12:43
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.

2 participants