[PATCH 7/9] rust: pin-init: use `kernel::{fmt,prelude::fmt!}`

Tamir Duberstein posted 9 patches 2 months, 4 weeks ago
There is a newer version of this series
[PATCH 7/9] rust: pin-init: use `kernel::{fmt,prelude::fmt!}`
Posted by Tamir Duberstein 2 months, 4 weeks ago
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 rust/kernel/init.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
index 8d228c237954..aa3fc90d32d1 100644
--- a/rust/kernel/init.rs
+++ b/rust/kernel/init.rs
@@ -68,7 +68,7 @@
 //!
 //! ```rust,ignore
 //! # #![allow(unreachable_pub, clippy::disallowed_names)]
-//! use kernel::{prelude::*, types::Opaque};
+//! use kernel::{fmt, prelude::*, types::Opaque};
 //! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin};
 //! # mod bindings {
 //! #     #![allow(non_camel_case_types)]
@@ -81,7 +81,7 @@
 //! # trait FromErrno {
 //! #     fn from_errno(errno: core::ffi::c_int) -> Error {
 //! #         // Dummy error that can be constructed outside the `kernel` crate.
-//! #         Error::from(core::fmt::Error)
+//! #         Error::from(fmt::Error)
 //! #     }
 //! # }
 //! # impl FromErrno for Error {}

-- 
2.50.0
Re: [PATCH 7/9] rust: pin-init: use `kernel::{fmt,prelude::fmt!}`
Posted by Benno Lossin 2 months, 4 weeks ago
On Wed Jul 9, 2025 at 10:00 PM CEST, Tamir Duberstein wrote:
> Reduce coupling to implementation details of the formatting machinery by
> avoiding direct use for `core`'s formatting traits and macros.
>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> ---
>  rust/kernel/init.rs | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

I usually prefix patches to init.rs with `rust: init`. I'll fix it up
when picking the patch or Miguel can do it if he takes it:

Acked-by: Benno Lossin <lossin@kernel.org>

---
Cheers,
Benno
Re: [PATCH 7/9] rust: pin-init: use `kernel::{fmt,prelude::fmt!}`
Posted by Tamir Duberstein 2 months, 4 weeks ago
On Wed, Jul 9, 2025 at 4:18 PM Benno Lossin <lossin@kernel.org> wrote:
>
> On Wed Jul 9, 2025 at 10:00 PM CEST, Tamir Duberstein wrote:
> > Reduce coupling to implementation details of the formatting machinery by
> > avoiding direct use for `core`'s formatting traits and macros.
> >
> > Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> > Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> > ---
> >  rust/kernel/init.rs | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
>
> I usually prefix patches to init.rs with `rust: init`. I'll fix it up
> when picking the patch or Miguel can do it if he takes it:
>
> Acked-by: Benno Lossin <lossin@kernel.org>

Actually, squinting at this patch more closely now, I think this isn't
what you had in mind. The comment says "Dummy error that can be
constructed outside the `kernel` crate." but the error now comes from
the kernel crate :(

Perhaps you could suggest a different modification that would both
meet the original intent and allow references to core::fmt to
disappear?
Re: [PATCH 7/9] rust: pin-init: use `kernel::{fmt,prelude::fmt!}`
Posted by Benno Lossin 2 months, 4 weeks ago
On Wed Jul 9, 2025 at 11:01 PM CEST, Tamir Duberstein wrote:
> On Wed, Jul 9, 2025 at 4:18 PM Benno Lossin <lossin@kernel.org> wrote:
>>
>> On Wed Jul 9, 2025 at 10:00 PM CEST, Tamir Duberstein wrote:
>> > Reduce coupling to implementation details of the formatting machinery by
>> > avoiding direct use for `core`'s formatting traits and macros.
>> >
>> > Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> > Reviewed-by: Alice Ryhl <aliceryhl@google.com>
>> > Signed-off-by: Tamir Duberstein <tamird@gmail.com>
>> > ---
>> >  rust/kernel/init.rs | 4 ++--
>> >  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> I usually prefix patches to init.rs with `rust: init`. I'll fix it up
>> when picking the patch or Miguel can do it if he takes it:
>>
>> Acked-by: Benno Lossin <lossin@kernel.org>
>
> Actually, squinting at this patch more closely now, I think this isn't
> what you had in mind. The comment says "Dummy error that can be
> constructed outside the `kernel` crate." but the error now comes from
> the kernel crate :(

It's a re-export, so the comment still holds.

> Perhaps you could suggest a different modification that would both
> meet the original intent and allow references to core::fmt to
> disappear?

The code comes from a time when `Error::from_errno` was `pub(crate)`,
but that was changed some time ago... Now we can just remove the
`FromErrno` trait entirely from that example. Feel free to do that in
this series or as a standalone patch.

---
Cheers,
Benno
Re: [PATCH 7/9] rust: pin-init: use `kernel::{fmt,prelude::fmt!}`
Posted by Tamir Duberstein 2 months, 4 weeks ago
On Wed, Jul 9, 2025 at 5:58 PM Benno Lossin <lossin@kernel.org> wrote:
>
> On Wed Jul 9, 2025 at 11:01 PM CEST, Tamir Duberstein wrote:
> > On Wed, Jul 9, 2025 at 4:18 PM Benno Lossin <lossin@kernel.org> wrote:
> >>
> >> On Wed Jul 9, 2025 at 10:00 PM CEST, Tamir Duberstein wrote:
> >> > Reduce coupling to implementation details of the formatting machinery by
> >> > avoiding direct use for `core`'s formatting traits and macros.
> >> >
> >> > Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> > Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> >> > Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> >> > ---
> >> >  rust/kernel/init.rs | 4 ++--
> >> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> I usually prefix patches to init.rs with `rust: init`. I'll fix it up
> >> when picking the patch or Miguel can do it if he takes it:
> >>
> >> Acked-by: Benno Lossin <lossin@kernel.org>
> >
> > Actually, squinting at this patch more closely now, I think this isn't
> > what you had in mind. The comment says "Dummy error that can be
> > constructed outside the `kernel` crate." but the error now comes from
> > the kernel crate :(
>
> It's a re-export, so the comment still holds.
>
> > Perhaps you could suggest a different modification that would both
> > meet the original intent and allow references to core::fmt to
> > disappear?
>
> The code comes from a time when `Error::from_errno` was `pub(crate)`,
> but that was changed some time ago... Now we can just remove the
> `FromErrno` trait entirely from that example. Feel free to do that in
> this series or as a standalone patch.

Ack, sent https://lore.kernel.org/all/20250709-init-remove-old-workaround-v1-1-a922d32338d2@gmail.com/.

With that patch, this one can be dropped (since it is just a comment).
Re: [PATCH 7/9] rust: pin-init: use `kernel::{fmt,prelude::fmt!}`
Posted by Tamir Duberstein 2 months, 4 weeks ago
On Wed, Jul 9, 2025 at 6:36 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
>
> Ack, sent https://lore.kernel.org/all/20250709-init-remove-old-workaround-v1-1-a922d32338d2@gmail.com/.

Messed it up, sent v2:
https://lore.kernel.org/all/20250709-init-remove-old-workaround-v2-0-a3b1be8fd490@gmail.com/.