[PATCH 05/10] rust: drm: use `core::ffi::CStr` method names

Tamir Duberstein posted 10 patches 2 months, 4 weeks ago
There is a newer version of this series
[PATCH 05/10] rust: drm: use `core::ffi::CStr` method names
Posted by Tamir Duberstein 2 months, 4 weeks ago
Prepare for `core::ffi::CStr` taking the place of `kernel::str::CStr` by
avoid methods that only exist on the latter.

Link: https://github.com/Rust-for-Linux/linux/issues/1075
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/drm/device.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
index b7ee3c464a12..998b942b6dd8 100644
--- a/rust/kernel/drm/device.rs
+++ b/rust/kernel/drm/device.rs
@@ -83,8 +83,8 @@ impl<T: drm::Driver> Device<T> {
         major: T::INFO.major,
         minor: T::INFO.minor,
         patchlevel: T::INFO.patchlevel,
-        name: T::INFO.name.as_char_ptr().cast_mut(),
-        desc: T::INFO.desc.as_char_ptr().cast_mut(),
+        name: crate::str::as_char_ptr_in_const_context(T::INFO.name).cast_mut(),
+        desc: crate::str::as_char_ptr_in_const_context(T::INFO.desc).cast_mut(),
 
         driver_features: drm::driver::FEAT_GEM,
         ioctls: T::IOCTLS.as_ptr(),

-- 
2.50.0
Re: [PATCH 05/10] rust: drm: use `core::ffi::CStr` method names
Posted by Danilo Krummrich 2 months, 3 weeks ago
On Wed Jul 9, 2025 at 9:58 PM CEST, Tamir Duberstein wrote:
> Prepare for `core::ffi::CStr` taking the place of `kernel::str::CStr` by
> avoid methods that only exist on the latter.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1075
> 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/drm/device.rs | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
> index b7ee3c464a12..998b942b6dd8 100644
> --- a/rust/kernel/drm/device.rs
> +++ b/rust/kernel/drm/device.rs
> @@ -83,8 +83,8 @@ impl<T: drm::Driver> Device<T> {
>          major: T::INFO.major,
>          minor: T::INFO.minor,
>          patchlevel: T::INFO.patchlevel,
> -        name: T::INFO.name.as_char_ptr().cast_mut(),
> -        desc: T::INFO.desc.as_char_ptr().cast_mut(),
> +        name: crate::str::as_char_ptr_in_const_context(T::INFO.name).cast_mut(),
> +        desc: crate::str::as_char_ptr_in_const_context(T::INFO.desc).cast_mut(),

Maybe looks slightly cleaner to import this function, not a blocker though.
Re: [PATCH 05/10] rust: drm: use `core::ffi::CStr` method names
Posted by Tamir Duberstein 2 months, 3 weeks ago
On Mon, Jul 14, 2025 at 7:09 AM Danilo Krummrich <dakr@kernel.org> wrote:
>
> On Wed Jul 9, 2025 at 9:58 PM CEST, Tamir Duberstein wrote:
> > Prepare for `core::ffi::CStr` taking the place of `kernel::str::CStr` by
> > avoid methods that only exist on the latter.
> >
> > Link: https://github.com/Rust-for-Linux/linux/issues/1075
> > 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/drm/device.rs | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
> > index b7ee3c464a12..998b942b6dd8 100644
> > --- a/rust/kernel/drm/device.rs
> > +++ b/rust/kernel/drm/device.rs
> > @@ -83,8 +83,8 @@ impl<T: drm::Driver> Device<T> {
> >          major: T::INFO.major,
> >          minor: T::INFO.minor,
> >          patchlevel: T::INFO.patchlevel,
> > -        name: T::INFO.name.as_char_ptr().cast_mut(),
> > -        desc: T::INFO.desc.as_char_ptr().cast_mut(),
> > +        name: crate::str::as_char_ptr_in_const_context(T::INFO.name).cast_mut(),
> > +        desc: crate::str::as_char_ptr_in_const_context(T::INFO.desc).cast_mut(),
>
> Maybe looks slightly cleaner to import this function, not a blocker though.

I don't feel strongly. I think I chose not to import it because of the
potential for conflicts.

See also https://github.com/rust-lang/rfcs/pull/3490 which would
obviate the need for this method.