// SPDX-License-Identifier: GPL-2.012/// Converts a null-terminated byte slice to a string, or `None` if the array does not3/// contains any null byte or contains invalid characters.4///5/// Contrary to [`kernel::str::CStr::from_bytes_with_nul`], the null byte can be anywhere in the6/// slice, and not only in the last position.7pub(crate) fn str_from_null_terminated(bytes: &[u8]) -> Option<&str> {8use kernel::str::CStr;910bytes11.iter()12.position(|&b| b == 0)13.and_then(|null_pos| CStr::from_bytes_with_nul(&bytes[..=null_pos]).ok())14.and_then(|cstr| cstr.to_str().ok())15}161718