* [PATCH v3 0/1] make `from_errno` use `try_from_errno`
@ 2024-11-23 10:48 Daniel Sedlak
2024-11-23 10:48 ` [PATCH v3] rust: error: modify `from_errno` to " Daniel Sedlak
2024-11-23 13:37 ` [PATCH v3 0/1] make `from_errno` " Miguel Ojeda
0 siblings, 2 replies; 11+ messages in thread
From: Daniel Sedlak @ 2024-11-23 10:48 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, rust-for-linux,
Guilherme Augusto Martins da Silva, Daniel Sedlak
Currently, there are three patches for this issue. There was a race condition between
me [1] and Guilherme [2] because we both picked it up as a "good first issue" without
knowing that one of us had started working on it. We both agreed that one of us would
be the main author and the other one would be noted in "Codeveloped-by." However,
Guilherme has kept radio silence since [3]. So, I am resubmitting the patch, which
builds on top of [3].
Link: https://lore.kernel.org/rust-for-linux/20241104185135.18974-1-daniel@sedlak.dev/ [1]
Link: https://lore.kernel.org/rust-for-linux/20241104200014.12996-1-guilhermev2huehue@gmail.com/ [2]
Link: https://lore.kernel.org/rust-for-linux/20241105114819.14051-1-guilhermev2huehue@gmail.com/ [3]
Daniel Sedlak (1):
rust: error: modify `from_errno` to use `try_from_errno`
rust/kernel/error.rs | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
--
2.47.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3] rust: error: modify `from_errno` to use `try_from_errno`
2024-11-23 10:48 [PATCH v3 0/1] make `from_errno` use `try_from_errno` Daniel Sedlak
@ 2024-11-23 10:48 ` Daniel Sedlak
2024-11-23 13:45 ` Miguel Ojeda
2024-11-25 9:01 ` Alice Ryhl
2024-11-23 13:37 ` [PATCH v3 0/1] make `from_errno` " Miguel Ojeda
1 sibling, 2 replies; 11+ messages in thread
From: Daniel Sedlak @ 2024-11-23 10:48 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, rust-for-linux,
Guilherme Augusto Martins da Silva, Daniel Sedlak
Modify the from_errno function to use try_from_errno to
reduce code duplication while still maintaining all existing
behavior and error handling and also reduces unsafe code.
Link: https://github.com/Rust-for-Linux/linux/issues/1125
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Co-developed-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com>
Signed-off-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com>
Signed-off-by: Daniel Sedlak <daniel@sedlak.dev>
---
rust/kernel/error.rs | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index 52c502432447..236b3e4719e6 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -100,20 +100,17 @@ impl Error {
///
/// It is a bug to pass an out-of-range `errno`. `EINVAL` would
/// be returned in such a case.
- pub fn from_errno(errno: crate::ffi::c_int) -> Error {
- if errno < -(bindings::MAX_ERRNO as i32) || errno >= 0 {
+ pub fn from_errno(errno: core::ffi::c_int) -> Error {
+ if let Some(error) = Self::try_from_errno(errno) {
+ error
+ } else {
// TODO: Make it a `WARN_ONCE` once available.
crate::pr_warn!(
"attempted to create `Error` with out of range `errno`: {}",
errno
);
- return code::EINVAL;
+ code::EINVAL
}
-
- // INVARIANT: The check above ensures the type invariant
- // will hold.
- // SAFETY: `errno` is checked above to be in a valid range.
- unsafe { Error::from_errno_unchecked(errno) }
}
/// Creates an [`Error`] from a kernel error code.
--
2.47.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v3] rust: error: modify `from_errno` to use `try_from_errno`
2024-11-23 10:48 ` [PATCH v3] rust: error: modify `from_errno` to " Daniel Sedlak
@ 2024-11-23 13:45 ` Miguel Ojeda
2024-11-23 19:08 ` Daniel Sedlak
2024-11-25 9:01 ` Alice Ryhl
1 sibling, 1 reply; 11+ messages in thread
From: Miguel Ojeda @ 2024-11-23 13:45 UTC (permalink / raw)
To: Daniel Sedlak
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, rust-for-linux, Guilherme Augusto Martins da Silva
On Sat, Nov 23, 2024 at 11:49 AM Daniel Sedlak <daniel@sedlak.dev> wrote:
>
> Modify the from_errno function to use try_from_errno to
> reduce code duplication while still maintaining all existing
> behavior and error handling and also reduces unsafe code.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1125
> Suggested-by: Miguel Ojeda <ojeda@kernel.org>
> Co-developed-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com>
> Signed-off-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com>
> Signed-off-by: Daniel Sedlak <daniel@sedlak.dev>
Usually, when you have a cover letter, the title of the patch would
have been "[PATCH v3 1/1]", to indicate there was a cover letter. Did
`git format-patch` not generate it?
It is not important, of course, but I thought I would mention it in
case it helps.
> + pub fn from_errno(errno: core::ffi::c_int) -> Error {
> + if let Some(error) = Self::try_from_errno(errno) {
> + error
> + } else {
`let ... else` would work here, but given we just return the `error`
rather than having a long function afterwards, it is true it does not
really help.
Thanks for the patch to both Guilherme and you, and for navigating the
race condition on submitting it!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v3] rust: error: modify `from_errno` to use `try_from_errno`
2024-11-23 13:45 ` Miguel Ojeda
@ 2024-11-23 19:08 ` Daniel Sedlak
2024-11-23 19:12 ` Miguel Ojeda
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Sedlak @ 2024-11-23 19:08 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, rust-for-linux, Guilherme Augusto Martins da Silva
On 11/23/24 2:45 PM, Miguel Ojeda wrote:
> On Sat, Nov 23, 2024 at 11:49 AM Daniel Sedlak <daniel@sedlak.dev> wrote:
>>
>> Modify the from_errno function to use try_from_errno to
>> reduce code duplication while still maintaining all existing
>> behavior and error handling and also reduces unsafe code.
>>
>> Link: https://github.com/Rust-for-Linux/linux/issues/1125
>> Suggested-by: Miguel Ojeda <ojeda@kernel.org>
>> Co-developed-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com>
>> Signed-off-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com>
>> Signed-off-by: Daniel Sedlak <daniel@sedlak.dev>
>
> Usually, when you have a cover letter, the title of the patch would
> have been "[PATCH v3 1/1]", to indicate there was a cover letter. Did
> `git format-patch` not generate it?
Ops, I may used wrong series of commands, and this slipped away. Should
I resend the patch with correct numbering?
>
> It is not important, of course, but I thought I would mention it in
> case it helps.
>
>> + pub fn from_errno(errno: core::ffi::c_int) -> Error {
>> + if let Some(error) = Self::try_from_errno(errno) {
>> + error
>> + } else {
>
> `let ... else` would work here, but given we just return the `error`
> rather than having a long function afterwards, it is true it does not
> really help.
Thank you for the feedback and tip. Should I dig more into this and try
to improve it more?
>
> Thanks for the patch to both Guilherme and you, and for navigating the
> race condition on submitting it!
>
> Cheers,
> Miguel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v3] rust: error: modify `from_errno` to use `try_from_errno`
2024-11-23 19:08 ` Daniel Sedlak
@ 2024-11-23 19:12 ` Miguel Ojeda
0 siblings, 0 replies; 11+ messages in thread
From: Miguel Ojeda @ 2024-11-23 19:12 UTC (permalink / raw)
To: Daniel Sedlak
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, rust-for-linux, Guilherme Augusto Martins da Silva
On Sat, Nov 23, 2024 at 8:08 PM Daniel Sedlak <daniel@sedlak.dev> wrote:
>
> Ops, I may used wrong series of commands, and this slipped away. Should
> I resend the patch with correct numbering?
>
> Thank you for the feedback and tip. Should I dig more into this and try
> to improve it more?
No, no worries, it is all fine :)
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] rust: error: modify `from_errno` to use `try_from_errno`
2024-11-23 10:48 ` [PATCH v3] rust: error: modify `from_errno` to " Daniel Sedlak
2024-11-23 13:45 ` Miguel Ojeda
@ 2024-11-25 9:01 ` Alice Ryhl
2024-11-25 9:27 ` Miguel Ojeda
1 sibling, 1 reply; 11+ messages in thread
From: Alice Ryhl @ 2024-11-25 9:01 UTC (permalink / raw)
To: Daniel Sedlak
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, rust-for-linux, Guilherme Augusto Martins da Silva
On Sat, Nov 23, 2024 at 11:49 AM Daniel Sedlak <daniel@sedlak.dev> wrote:
>
> Modify the from_errno function to use try_from_errno to
> reduce code duplication while still maintaining all existing
> behavior and error handling and also reduces unsafe code.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1125
> Suggested-by: Miguel Ojeda <ojeda@kernel.org>
> Co-developed-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com>
> Signed-off-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com>
> Signed-off-by: Daniel Sedlak <daniel@sedlak.dev>
> ---
> - pub fn from_errno(errno: crate::ffi::c_int) -> Error {
> + pub fn from_errno(errno: core::ffi::c_int) -> Error {
This changes crate::ffi to core::ffi, but the correct thing is to use
crate::ffi.
Alice
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v3] rust: error: modify `from_errno` to use `try_from_errno`
2024-11-25 9:01 ` Alice Ryhl
@ 2024-11-25 9:27 ` Miguel Ojeda
2024-11-25 11:31 ` Daniel Sedlak
0 siblings, 1 reply; 11+ messages in thread
From: Miguel Ojeda @ 2024-11-25 9:27 UTC (permalink / raw)
To: Alice Ryhl
Cc: Daniel Sedlak, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, rust-for-linux, Guilherme Augusto Martins da Silva
On Mon, Nov 25, 2024 at 10:01 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> This changes crate::ffi to core::ffi, but the correct thing is to use
> crate::ffi.
Indeed, this seems to come from a bad rebase on top of the latest `rust-next`.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] rust: error: modify `from_errno` to use `try_from_errno`
2024-11-25 9:27 ` Miguel Ojeda
@ 2024-11-25 11:31 ` Daniel Sedlak
2024-11-25 11:42 ` Alice Ryhl
2024-11-25 15:03 ` Miguel Ojeda
0 siblings, 2 replies; 11+ messages in thread
From: Daniel Sedlak @ 2024-11-25 11:31 UTC (permalink / raw)
To: Miguel Ojeda, Alice Ryhl
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, rust-for-linux, Guilherme Augusto Martins da Silva
On 11/25/24 10:27 AM, Miguel Ojeda wrote:
> On Mon, Nov 25, 2024 at 10:01 AM Alice Ryhl <aliceryhl@google.com> wrote:
>>
>> This changes crate::ffi to core::ffi, but the correct thing is to use
>> crate::ffi.
>
> Indeed, this seems to come from a bad rebase on top of the latest `rust-next`.
You are right, I was developing this on top of `rust-next`. I get it
that I should be developing on top of `rust-dev` right? If yes, should I
also include the base commit id because of possible conflicts?
>
> Cheers,
> Miguel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] rust: error: modify `from_errno` to use `try_from_errno`
2024-11-25 11:31 ` Daniel Sedlak
@ 2024-11-25 11:42 ` Alice Ryhl
2024-11-25 15:03 ` Miguel Ojeda
1 sibling, 0 replies; 11+ messages in thread
From: Alice Ryhl @ 2024-11-25 11:42 UTC (permalink / raw)
To: Daniel Sedlak
Cc: Miguel Ojeda, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, rust-for-linux, Guilherme Augusto Martins da Silva
On Mon, Nov 25, 2024 at 12:31 PM Daniel Sedlak <daniel@sedlak.dev> wrote:
>
>
>
> On 11/25/24 10:27 AM, Miguel Ojeda wrote:
> > On Mon, Nov 25, 2024 at 10:01 AM Alice Ryhl <aliceryhl@google.com> wrote:
> >>
> >> This changes crate::ffi to core::ffi, but the correct thing is to use
> >> crate::ffi.
> >
> > Indeed, this seems to come from a bad rebase on top of the latest `rust-next`.
>
> You are right, I was developing this on top of `rust-next`. I get it
> that I should be developing on top of `rust-dev` right? If yes, should I
> also include the base commit id because of possible conflicts?
No. Developing on top of rust-next is preferable to rust-dev.
Alice
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] rust: error: modify `from_errno` to use `try_from_errno`
2024-11-25 11:31 ` Daniel Sedlak
2024-11-25 11:42 ` Alice Ryhl
@ 2024-11-25 15:03 ` Miguel Ojeda
1 sibling, 0 replies; 11+ messages in thread
From: Miguel Ojeda @ 2024-11-25 15:03 UTC (permalink / raw)
To: Daniel Sedlak
Cc: Alice Ryhl, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, rust-for-linux, Guilherme Augusto Martins da Silva
On Mon, Nov 25, 2024 at 12:31 PM Daniel Sedlak <daniel@sedlak.dev> wrote:
>
> You are right, I was developing this on top of `rust-next`. I get it
> that I should be developing on top of `rust-dev` right? If yes, should I
What I meant is that it seemed like the line changed by `rust-next`
got overwritten when you resolved the conflict (since that line was
not a change in your original patch, just part of the context). In
other words, it seemed to me the mistake happened at rebase time, when
solving the conflict.
Using `rust-next` is perfectly fine and expected, as Alice mentioned.
You may also want to use other bases, like a mainline tag, as long as
you don't require the changes in `rust-next` (e.g. it is a fix that
will not go through that branch).
> also include the base commit id because of possible conflicts?
Please always include the base commit, it can save a lot of
time/confusion later on. Sometimes even when it is based on an
out-of-tree branch it is helpful (as long as it is published and
mentioned, of course). It can also spot submitting mistakes if nobody
knows what the hash is :)
Cheers,
Miguel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 0/1] make `from_errno` use `try_from_errno`
2024-11-23 10:48 [PATCH v3 0/1] make `from_errno` use `try_from_errno` Daniel Sedlak
2024-11-23 10:48 ` [PATCH v3] rust: error: modify `from_errno` to " Daniel Sedlak
@ 2024-11-23 13:37 ` Miguel Ojeda
1 sibling, 0 replies; 11+ messages in thread
From: Miguel Ojeda @ 2024-11-23 13:37 UTC (permalink / raw)
To: Daniel Sedlak
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, rust-for-linux, Guilherme Augusto Martins da Silva
On Sat, Nov 23, 2024 at 11:49 AM Daniel Sedlak <daniel@sedlak.dev> wrote:
>
> Currently, there are three patches for this issue. There was a race condition between
> me [1] and Guilherme [2] because we both picked it up as a "good first issue" without
> knowing that one of us had started working on it. We both agreed that one of us would
> be the main author and the other one would be noted in "Codeveloped-by." However,
> Guilherme has kept radio silence since [3]. So, I am resubmitting the patch, which
> builds on top of [3].
Sounds good, thanks!
(By the way, if you have a single patch, you can avoid a cover letter
to simplify by writing this right below the first `---` line in the
patch.)
Cheers,
Miguel
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-11-25 15:03 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-23 10:48 [PATCH v3 0/1] make `from_errno` use `try_from_errno` Daniel Sedlak
2024-11-23 10:48 ` [PATCH v3] rust: error: modify `from_errno` to " Daniel Sedlak
2024-11-23 13:45 ` Miguel Ojeda
2024-11-23 19:08 ` Daniel Sedlak
2024-11-23 19:12 ` Miguel Ojeda
2024-11-25 9:01 ` Alice Ryhl
2024-11-25 9:27 ` Miguel Ojeda
2024-11-25 11:31 ` Daniel Sedlak
2024-11-25 11:42 ` Alice Ryhl
2024-11-25 15:03 ` Miguel Ojeda
2024-11-23 13:37 ` [PATCH v3 0/1] make `from_errno` " Miguel Ojeda
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.