Skip to content
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

Simple Rust driver that touches real hardware: PR 3/6 #301

Merged
merged 2 commits into from
May 27, 2021

Conversation

TheSven73
Copy link
Collaborator

Simple Rust driver that touches real h/w: step 3 of 6

@alex and @ojeda suggested that #254 should be split into smaller PRs, so they can be reviewed and merged individually.

Roadmap:

  • platform_device
  • devicetree (of) matching
  • probe (you are here)
  • DrvData
  • regmap/iomem
  • finally the actual hwrng driver

Sven Van Asbroeck added 2 commits May 26, 2021 16:25
Add the `PlatformDriver` trait, which driver writers may implement
in order to define a platform driver in the kernel.

For sake of simplicity and ease of review, `PlatformDriver` consists
of two functions for now - `probe()` and `remove()`.

Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
Implement this in the simplest possible way: by printing a
`pr_info` log message on `probe()`/`remove()`.

Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
@ksquirrel
Copy link
Member

Review of fa6f1bac3c6a:

  • ✔️ Commit 22fe6d2: Looks fine!
  • ✔️ Commit fa6f1ba: Looks fine!

Copy link
Member

@alex alex left a comment

Choose a reason for hiding this comment

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

Is it right that follow up PRs will allow probe to return state?

@TheSven73
Copy link
Collaborator Author

Absolutely! That will happen in the DrvData step.

@TheSven73
Copy link
Collaborator Author

This PR should be relatively straightforward, to give everyone involved a well-deserved break :)
The DrvData PR will be intense, and possibly controversial.

Copy link
Member

@alex alex left a comment

Choose a reason for hiding this comment

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

Excellent :-)

@alex alex merged commit 698569d into Rust-for-Linux:rust May 27, 2021
@TheSven73
Copy link
Collaborator Author

That was quick ! Thank you !! 💯

@TheSven73 TheSven73 deleted the rust-for-linux-pdev-pr3 branch May 27, 2021 14:37

/// Trait for implementers of platform drivers.
///
/// Implement this trait whenever you create a platform driver.

Choose a reason for hiding this comment

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

Super nit: here you're using the imperative mode "Implement this [...]" while in the functions below you use the indicative mode "Implementers should attempt [...]".

I think we should be consistent and use the same structure in both cases. Personally, I favor the indicative because we are providing information to the reader, not giving them orders. (Though admittedly opinions vary here.)

Copy link
Collaborator Author

@TheSven73 TheSven73 May 27, 2021

Choose a reason for hiding this comment

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

Agreed ! And these are probably more important than super-nits. Please do provide that info, so I can improve my "internal algorithm".

struct RngDriver;

impl PlatformDriver for RngDriver {
fn probe(device_id: i32) -> Result {

Choose a reason for hiding this comment

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

Is it correct to assume that we'll eventually provide more information than device_id?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Absolutely!! device_id is just a placeholder. Watch this space :)

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.

4 participants