-
Notifications
You must be signed in to change notification settings - Fork 465
rust: miscdev: support names created at runtime #677
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
Conversation
af4b226
to
f45ee97
Compare
rust/kernel/miscdev.rs
Outdated
Options::new().register_new(name, open_data) | ||
} | ||
|
||
/// Registers a miscellaneous device with the rest of the kernel. | ||
/// | ||
/// It must be pinned because the memory block that represents the registration is | ||
/// self-referential. | ||
pub fn register(self: Pin<&mut Self>, name: &'static CStr, open_data: T::OpenData) -> Result { | ||
pub fn register(self: Pin<&mut Self>, name: fmt::Arguments<'_>, open_data: T::OpenData) -> Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe accept Cow<'static, CStr>
instead? That allows avoiding an allocation in the common case of the name being constant. Or impl Into<Cow<'static, CStr>>
to allow directly passing in both a CStr
and CString
without having to construct a Cow<CStr>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to leave this as is now, and once #678 is done (or as part of it) we can optimise this avoid the allocation when using a &'static CStr
f45ee97
to
3838d81
Compare
The registration now holds an owned C string while the miscdev is registered, and frees it on drop. Now names are formatted with the `fmt` macro instead of being static C strings. This enables scenarios when the device name is constructed at runtime, i.e., where a static C string does not exist. Signed-off-by: Wedson Almeida Filho <[email protected]>
3838d81
to
df111f3
Compare
Rebased now that all dependencies are merged. |
Yes, definitely. Do you expect people will generate names dynamically for hwrng? |
Then I'm working on this.
Actually, this is the case in the trng driver already. The name for hwrng driver is set to the name of pdev. |
The registration now holds an owned C string while the miscdev is
registered, and frees it on drop.
Now names are formatted with the
fmt
macro instead of being staticC strings. This enables scenarios when the device name is constructed at
runtime, i.e., where a static C string does not exist.
Signed-off-by: Wedson Almeida Filho [email protected]