of: resolves TODO for copy_from_slice
Subsystems (2)
PATCH 1/1 of: resolves TODO for copy_from_slice
From: elle <[email protected]>
Replaces the copy loop with copy_from_slice which became const in stable Rust with version 1.87.0.
--- rust/kernel/of.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
rust/kernel/of.rs +1 -6
@@ -39,12 +39,7 @@ impl DeviceId {// SAFETY: FFI type is valid to be zero-initialized. let mut of: bindings::of_device_id =unsafe { core::mem::zeroed () }; -// TODO: Use `copy_from_slice` once stabilized for `const`. -let mut i =0 ; -while i < src.len () { - of.compatible[i] = src[i]; - i +=1 ; - } + of.compatible.copy_from_slice (src);Self (of) }
Signature · 1 line
2.49.1
Quoted 6 lines · ~_xllx_
From: elle <[email protected]>
Replaces the copy loop with
copy_from_slicewhich becameconstin stable Rust with version1.87.0.Authored-by elle <[email protected]>
This isn't a normal kernel tag, the "From:" line guarantes this, please no need to repeat it again.
Also, we need a full name please, as per our documentation.
thanks,
greg k-h
I'll clean this up in future patches, thanks for letting me know.
Quoted 20 lines · Greg KH
Quoted 6 lines · ~xllx
From: elle [email protected]
Replaces the copy loop with
copy_from_slicewhich becameconstin stable Rust with version1.87.0.Authored-by elle [email protected]This isn't a normal kernel tag, the "From:" line guarantes this, please no need to repeat it again.
Also, we need a full name please, as per our documentation.
thanks,
greg k-h
Alice Ryhl
reviewerQuoted 8 lines · ~_xllx_
From: elle <[email protected]>
Replaces the copy loop with
copy_from_slicewhich becameconstin stable Rust with version1.87.0.Authored-by elle <[email protected]>Signed-off-by elle <[email protected]>
We still support rustc 1.78 and forward.
Alice
I tried to find the MSRV before sending the patch, sorry for the noise.
Since this is a pretty low-priority patch, guess it can just hang out until the MSRV bump to 1.87.x?
Quoted 16 lines · Alice Ryhl
Quoted 7 lines · On Mon, Aug 11, 2025 at 8:38 AM ~xllx [email protected] wrote:
From: elle [email protected]
Replaces the copy loop with
copy_from_slicewhich becameconstin stable Rust with version1.87.0.Authored-by elle [email protected]Signed-off-by elle [email protected]We still support rustc 1.78 and forward.
Alice
Quoted 4 lines · Elle
I tried to find the MSRV before sending the patch, sorry for the noise.
Since this is a pretty low-priority patch, guess it can just hang out until the MSRV bump to 1.87.x?
Yes, but that will likely take more than a year, so we will forget about it, or the code may change anyway.
The other option is using the unstable feature, if it is really useful etc., but for that we also need to wait until 1.85.0, since that is where const_copy_from_slice was available. Luckily, 1.85.0 is possibly our next minimum, due to Debian Trixie.
Thanks!
(By the way, please try to avoid top-posting on the mailing list:
https://docs.kernel.org/process/submitting-patches.html#use-trimmed-interleaved-replies-in-email-discussions
:)
Cheers,
Miguel
kernel test robot
build botkernel test robot noticed the following build errors:
Hi ~_xllx_,
kernel test robot noticed the following build errors:
[auto build test ERROR on linux/master]
url: https://github.com/intel-lab-lkp/linux/commits/_xllx_/of-resolves-TODO-for-copy_from_slice/20250811-144924 base: linux/master patch link: https://lore.kernel.org/r/175489428990.9320.6825335165759789458-0%40git.sr.ht patch subject: [PATCH linux] of: resolves TODO for copy_from_slice config: x86_64-rhel-9.4-rust (https://download.01.org/0day-ci/archive/20250812/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) rustc: rustc 1.88.0 (6b00bc388 2025-06-23) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250812/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> error[E0080]: evaluation of constant value failed
--> rust/doctests_kernel_generated.rs:6978:11
|
6978 | (of::DeviceId::new(c_str!("test,device")), ())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: copy_from_slice: source slice length does not match destination slice length
|
note: inside rust_doctest_kernel_alloc_kbox_rs_7::kernel::of::DeviceId::new --> rust/kernel/of.rs:42:9
|
42 | of.compatible.copy_from_slice(src);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the failure occurred here
--
>> error[E0080]: evaluation of constant value failed
--> samples/rust/rust_driver_platform.rs:88:7
|
88 | [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: copy_from_slice: source slice length does not match destination slice length
|
note: inside kernel::of::DeviceId::new
--> rust/kernel/of.rs:42:9
|
42 | of.compatible.copy_from_slice(src);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the failure occurred here
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki