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: remove `RawWriter`

`RawWriter` is now dead code, so remove it.

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-9-b5212cc89b98@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Andreas Hindborg and committed by
Jens Axboe
f52689fc c3a54220

-57
-1
rust/kernel/block/mq.rs
··· 89 89 90 90 pub mod gen_disk; 91 91 mod operations; 92 - mod raw_writer; 93 92 mod request; 94 93 mod tag_set; 95 94
-56
rust/kernel/block/mq/raw_writer.rs
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - 3 - use core::fmt::{self, Write}; 4 - 5 - use crate::error::Result; 6 - use crate::prelude::EINVAL; 7 - 8 - /// A mutable reference to a byte buffer where a string can be written into. 9 - /// 10 - /// # Invariants 11 - /// 12 - /// `buffer` is always null terminated. 13 - pub(crate) struct RawWriter<'a> { 14 - buffer: &'a mut [u8], 15 - pos: usize, 16 - } 17 - 18 - impl<'a> RawWriter<'a> { 19 - /// Create a new `RawWriter` instance. 20 - fn new(buffer: &'a mut [u8]) -> Result<RawWriter<'a>> { 21 - *(buffer.last_mut().ok_or(EINVAL)?) = 0; 22 - 23 - // INVARIANT: We null terminated the buffer above. 24 - Ok(Self { buffer, pos: 0 }) 25 - } 26 - 27 - #[expect(dead_code)] 28 - pub(crate) fn from_array<const N: usize>( 29 - a: &'a mut [crate::ffi::c_char; N], 30 - ) -> Result<RawWriter<'a>> { 31 - Self::new( 32 - // SAFETY: the buffer of `a` is valid for read and write as `u8` for 33 - // at least `N` bytes. 34 - unsafe { core::slice::from_raw_parts_mut(a.as_mut_ptr().cast::<u8>(), N) }, 35 - ) 36 - } 37 - } 38 - 39 - impl Write for RawWriter<'_> { 40 - fn write_str(&mut self, s: &str) -> fmt::Result { 41 - let bytes = s.as_bytes(); 42 - let len = bytes.len(); 43 - 44 - // We do not want to overwrite our null terminator 45 - if self.pos + len > self.buffer.len() - 1 { 46 - return Err(fmt::Error); 47 - } 48 - 49 - // INVARIANT: We are not overwriting the last byte 50 - self.buffer[self.pos..self.pos + len].copy_from_slice(bytes); 51 - 52 - self.pos += len; 53 - 54 - Ok(()) 55 - } 56 - }