From: John Hubbard Date: Tue, 6 Jan 2026 03:52:26 +0000 (-0800) Subject: gpu: nova-core: use CStr::from_bytes_until_nul() in elf64_section() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d7b4a44fb768e1887e7e4cdd8b86817ccd9c3bf;p=thirdparty%2Fkernel%2Flinux.git gpu: nova-core: use CStr::from_bytes_until_nul() in elf64_section() 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 Signed-off-by: John Hubbard Link: https://patch.msgid.link/20260106035226.48853-3-jhubbard@nvidia.com Signed-off-by: Danilo Krummrich --- 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 @@ mod elf { // 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.