public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs
@ 2026-01-06  3:52 John Hubbard
  2026-01-06  3:52 ` [PATCH v2 1/2] " John Hubbard
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: John Hubbard @ 2026-01-06  3:52 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	Edwin Peer, Zhi Wang, David Airlie, Simona Vetter, Bjorn Helgaas,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, nouveau, rust-for-linux, LKML, John Hubbard

Alex Courbot's "[PATCH v2 00/10] gpu: nova-core: miscellaneous
improvements" series [1] includes a similar patch as my patch 1 here,
but this one here goes further and deletes the entire util.rs file.

This is based upon the latest drm-rust-next.

Changes in v2:

1) added a second patch, as suggested by Joel Fernandes, to do a little
more cleanup.

2) Added Joel's reviewed-by tag to the first patch.

v1 is here:
    https://lore.kernel.org/20260103013438.247759-1-jhubbard@nvidia.com

[1] https://lore.kernel.org/20251216-nova-misc-v2-0-dc7b42586c04@nvidia.com

John Hubbard (2):
  gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs
  gpu: nova-core: use CStr::from_bytes_until_nul() in elf64_section()

John Hubbard (2):
  gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs
  gpu: nova-core: use CStr::from_bytes_until_nul() in elf64_section()

 drivers/gpu/nova-core/firmware/gsp.rs |  5 +----
 drivers/gpu/nova-core/gsp/commands.rs |  5 +++--
 drivers/gpu/nova-core/nova_core.rs    |  1 -
 drivers/gpu/nova-core/util.rs         | 16 ----------------
 4 files changed, 4 insertions(+), 23 deletions(-)
 delete mode 100644 drivers/gpu/nova-core/util.rs


base-commit: 7acc70476f14661149774ab88d3fe23d83ba4249
prerequisite-patch-id: df9c0cfe56901c27064ac88972dffe3a4314c2f8
--
2.52.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs
  2026-01-06  3:52 [PATCH v2 0/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs John Hubbard
@ 2026-01-06  3:52 ` John Hubbard
  2026-01-06  3:52 ` [PATCH v2 2/2] gpu: nova-core: use CStr::from_bytes_until_nul() in elf64_section() John Hubbard
  2026-01-07 18:46 ` [PATCH v2 0/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs Danilo Krummrich
  2 siblings, 0 replies; 4+ messages in thread
From: John Hubbard @ 2026-01-06  3:52 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	Edwin Peer, Zhi Wang, David Airlie, Simona Vetter, Bjorn Helgaas,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, nouveau, rust-for-linux, LKML, John Hubbard

The util.rs module contained a single helper function,
str_from_null_terminated(), which duplicated functionality that is now
available in core::ffi::CStr.

Specifically, CStr::from_bytes_until_nul() is available in the kernel's
minimum supported Rust version (1.78.0), so it time to stop using this
custom workaround.

Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 drivers/gpu/nova-core/gsp/commands.rs |  5 +++--
 drivers/gpu/nova-core/nova_core.rs    |  1 -
 drivers/gpu/nova-core/util.rs         | 16 ----------------
 3 files changed, 3 insertions(+), 19 deletions(-)
 delete mode 100644 drivers/gpu/nova-core/util.rs

diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
index 0425c65b5d6f..a11fe6018091 100644
--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -30,7 +30,6 @@
         },
     },
     sbuffer::SBufferIter,
-    util,
 };
 
 /// The `GspSetSystemInfo` command.
@@ -209,7 +208,9 @@ impl GetGspStaticInfoReply {
     /// Returns the name of the GPU as a string, or `None` if the string given by the GSP was
     /// invalid.
     pub(crate) fn gpu_name(&self) -> Option<&str> {
-        util::str_from_null_terminated(&self.gpu_name)
+        CStr::from_bytes_until_nul(&self.gpu_name)
+            .ok()
+            .and_then(|cstr| cstr.to_str().ok())
     }
 }
 
diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs
index b98a1c03f13d..c1121e7c64c5 100644
--- a/drivers/gpu/nova-core/nova_core.rs
+++ b/drivers/gpu/nova-core/nova_core.rs
@@ -16,7 +16,6 @@
 mod num;
 mod regs;
 mod sbuffer;
-mod util;
 mod vbios;
 
 pub(crate) const MODULE_NAME: &kernel::str::CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
diff --git a/drivers/gpu/nova-core/util.rs b/drivers/gpu/nova-core/util.rs
deleted file mode 100644
index 4b503249a3ef..000000000000
--- a/drivers/gpu/nova-core/util.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-/// Converts a null-terminated byte slice to a string, or `None` if the array does not
-/// contains any null byte or contains invalid characters.
-///
-/// Contrary to [`kernel::str::CStr::from_bytes_with_nul`], the null byte can be anywhere in the
-/// slice, and not only in the last position.
-pub(crate) fn str_from_null_terminated(bytes: &[u8]) -> Option<&str> {
-    use kernel::str::CStr;
-
-    bytes
-        .iter()
-        .position(|&b| b == 0)
-        .and_then(|null_pos| CStr::from_bytes_with_nul(&bytes[..=null_pos]).ok())
-        .and_then(|cstr| cstr.to_str().ok())
-}
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] gpu: nova-core: use CStr::from_bytes_until_nul() in elf64_section()
  2026-01-06  3:52 [PATCH v2 0/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs John Hubbard
  2026-01-06  3:52 ` [PATCH v2 1/2] " John Hubbard
@ 2026-01-06  3:52 ` John Hubbard
  2026-01-07 18:46 ` [PATCH v2 0/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs Danilo Krummrich
  2 siblings, 0 replies; 4+ messages in thread
From: John Hubbard @ 2026-01-06  3:52 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	Edwin Peer, Zhi Wang, David Airlie, Simona Vetter, Bjorn Helgaas,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, nouveau, rust-for-linux, LKML, John Hubbard

Instead of open-coding the steps for extracting a null-terminated
string, use the newly available CStr::from_bytes_until_nul().

Suggested-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 drivers/gpu/nova-core/firmware/gsp.rs | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index da97814cf859..1025b7f746eb 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -93,10 +93,7 @@ pub(super) fn elf64_section<'a, 'b>(elf: &'a [u8], name: &'b str) -> Option<&'a
 
             // Get the start of the name.
             elf.get(name_idx..)
-                // Stop at the first `0`.
-                .and_then(|nstr| nstr.get(0..=nstr.iter().position(|b| *b == 0)?))
-                // Convert into CStr. This should never fail because of the line above.
-                .and_then(|nstr| CStr::from_bytes_with_nul(nstr).ok())
+                .and_then(|nstr| CStr::from_bytes_until_nul(nstr).ok())
                 // Convert into str.
                 .and_then(|c_str| c_str.to_str().ok())
                 // Check that the name matches.
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs
  2026-01-06  3:52 [PATCH v2 0/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs John Hubbard
  2026-01-06  3:52 ` [PATCH v2 1/2] " John Hubbard
  2026-01-06  3:52 ` [PATCH v2 2/2] gpu: nova-core: use CStr::from_bytes_until_nul() in elf64_section() John Hubbard
@ 2026-01-07 18:46 ` Danilo Krummrich
  2 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-01-07 18:46 UTC (permalink / raw)
  To: John Hubbard
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	Edwin Peer, Zhi Wang, David Airlie, Simona Vetter, Bjorn Helgaas,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, nouveau, rust-for-linux, LKML

On Tue Jan 6, 2026 at 4:52 AM CET, John Hubbard wrote:
> John Hubbard (2):
>   gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs
>   gpu: nova-core: use CStr::from_bytes_until_nul() in elf64_section()

Applied to drm-rust-next, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-07 18:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-06  3:52 [PATCH v2 0/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs John Hubbard
2026-01-06  3:52 ` [PATCH v2 1/2] " John Hubbard
2026-01-06  3:52 ` [PATCH v2 2/2] gpu: nova-core: use CStr::from_bytes_until_nul() in elf64_section() John Hubbard
2026-01-07 18:46 ` [PATCH v2 0/2] gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox