On 3/19/24 2:32 AM, Philipp Stanner wrote:
...
+ if ret < 0 {
+ Err(Error::from_errno(ret))
+ } else {
+ guard.dismiss();
+ Ok(id as usize)
+ }
You could make this easier to read using to_result.
to_result(ret)?;
guard.dismiss();
Ok(id as usize)
My 2 cents, I'd go for classic kernel style:
if ret < 0 {
return Err(...);
}
guard.dismiss();
Ok(id as usize)
Yes.
As a "standard" C-based kernel person who is trying to move into Rust
for Linux, I hereby invoke my Rust-newbie powers to confirm that the
"clasic kernel style" above goes into my head much faster and easier,
yes. :)
I hope I'm not violating any "this is how Rust idioms must be"
conventions. But if not, then all other things being equal, it is of
course a nice touch to make the code more readable to the rest of the
kernel folks.
thanks,
--
John Hubbard
NVIDIA