Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: block: use `NullTerminatedFormatter`

Use the new `NullTerminatedFormatter` to write the name of a `GenDisk` to
the name buffer. This new formatter automatically adds a trailing null
marker after the written characters, so we don't need to append that at the
call site any longer.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Link: https://lore.kernel.org/r/20250902-rnull-up-v6-16-v7-8-b5212cc89b98@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Andreas Hindborg and committed by
Jens Axboe
c3a54220 f4b72f15

+8 -6
+7 -5
rust/kernel/block/mq/gen_disk.rs
··· 7 7 8 8 use crate::{ 9 9 bindings, 10 - block::mq::{raw_writer::RawWriter, Operations, TagSet}, 10 + block::mq::{Operations, TagSet}, 11 11 error::{self, from_err_ptr, Result}, 12 + prelude::*, 12 13 static_lock_class, 14 + str::NullTerminatedFormatter, 13 15 sync::Arc, 14 16 }; 15 17 use core::fmt::{self, Write}; ··· 145 143 // SAFETY: `gendisk` is a valid pointer as we initialized it above 146 144 unsafe { (*gendisk).fops = &TABLE }; 147 145 148 - let mut raw_writer = RawWriter::from_array( 146 + let mut writer = NullTerminatedFormatter::new( 149 147 // SAFETY: `gendisk` points to a valid and initialized instance. We 150 148 // have exclusive access, since the disk is not added to the VFS 151 149 // yet. 152 150 unsafe { &mut (*gendisk).disk_name }, 153 - )?; 154 - raw_writer.write_fmt(name)?; 155 - raw_writer.write_char('\0')?; 151 + ) 152 + .ok_or(EINVAL)?; 153 + writer.write_fmt(name)?; 156 154 157 155 // SAFETY: `gendisk` points to a valid and initialized instance of 158 156 // `struct gendisk`. `set_capacity` takes a lock to synchronize this
+1
rust/kernel/block/mq/raw_writer.rs
··· 24 24 Ok(Self { buffer, pos: 0 }) 25 25 } 26 26 27 + #[expect(dead_code)] 27 28 pub(crate) fn from_array<const N: usize>( 28 29 a: &'a mut [crate::ffi::c_char; N], 29 30 ) -> Result<RawWriter<'a>> {
-1
rust/kernel/str.rs
··· 886 886 887 887 impl<'a> NullTerminatedFormatter<'a> { 888 888 /// Create a new [`Self`] instance. 889 - #[expect(dead_code)] 890 889 pub(crate) fn new(buffer: &'a mut [u8]) -> Option<NullTerminatedFormatter<'a>> { 891 890 *(buffer.first_mut()?) = 0; 892 891