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

Print out errname in impl Debug for Error #287

Merged
merged 1 commit into from
May 26, 2021
Merged

Conversation

nbdd0121
Copy link
Member

@nbdd0121 nbdd0121 commented May 22, 2021

Depends on #273 Merged

@ksquirrel

This comment has been minimized.

@nbdd0121 nbdd0121 mentioned this pull request May 22, 2021
@@ -61,6 +63,26 @@ impl Error {
}
}

impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Copy link
Member

Choose a reason for hiding this comment

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

I like the idea that we could have names instead of values for the Debug::fmt of Error. However, I think it's better that we don't need to call errname if we already have the corresponding const, e.g. Error::EINVAL, because having the const actually means we have names for the error numbers at Rust side.

Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't currently have constants for all errors defined in Rust. Plus, defining them in Rust essentially requires us to have a giant match, or define a lookup table like errname.c did. It might be better just to reuse errname, C side needs it anyway.

@nbdd0121
Copy link
Member Author

nbdd0121 commented May 24, 2021

I think there are a few further improvements that can be made to Error.

  1. We might want to drop all negatives. All C side macros define error codes as positive, and it's only used as negative values to tell part between success and failure. Rust side shouldn't use that pattern at all and should use Result exclusively anyway, so negative values are not meaningful.
  2. Error should #[derive(Clone, Copy, PartialEq, Eq)] included in the PR
  3. We will need to make sure that no Error with out of range error code can be constructed (e.g. 0, > MAX_ERROR), as otherwise it might be a soundness hole (with the use of from_kernel_result for example).
  4. After 3 is fixed, we can probably use NonZeroI16 as the inner type. This allows Result<()> to fit in 16-bit, instead of 64-bit as it is now.

@ksquirrel

This comment has been minimized.

@TheSven73
Copy link
Collaborator

  1. After 3 is fixed, we can probably use NonZeroI16 as the inner type. This allows Result<()> to fit in 16-bit, instead of 64-bit as it is now.

I like this. Moving to a more constrained type would eliminate at least one human "proof" elsewhere. That's probably a Good Thing(tm).

@ksquirrel

This comment has been minimized.

rust/kernel/error.rs Outdated Show resolved Hide resolved
rust/kernel/error.rs Outdated Show resolved Hide resolved
rust/kernel/error.rs Outdated Show resolved Hide resolved
rust/kernel/error.rs Outdated Show resolved Hide resolved
@ksquirrel
Copy link
Member

Review of 34c1d99a247f:

  • ✔️ Commit 34c1d99: Looks fine!

@ojeda
Copy link
Member

ojeda commented May 26, 2021

LGTM.

@ojeda
Copy link
Member

ojeda commented May 26, 2021

We could put some of #287 (comment) as an issue, perhaps a "good first issue".

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.

5 participants