From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD9F518DB24; Mon, 10 Mar 2025 17:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741627173; cv=none; b=P5Y7sovuY3SIy5BCrDkHKH055pvISyKkJ3cgBKSSf77AA1mF2OGqR19NvZq97BiMZC5NlhqIxaYmA7gmN/ITRYbqrFePRGEel6Zc6JXkIXou06vh28SwyUV4EyZ+uOo3/IRPUhOnUZz5xUh9r53sF4apRXUXUGFmC2BBZ6rMVbs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741627173; c=relaxed/simple; bh=nN8JNFtlDE3lheQhPQUelGBhTCDE42KiMurAnIiRIiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s5xg/VinC+0Agit+fd4LX3Of2QkHyZP5DxdbpUTPoEQZuEize6OkXg0iIPGUuBzVSziRPKicIAWlKBD6DT8SB1a7fSPKJ/dEbzX/H4rsz5Ne5HRsceTcUR4xpEL4NO1tZG1kB5ji+Ch2Q1JsA/kNDsU8FRuZqBztYEoViTd5ySw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sFNzjw3Q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sFNzjw3Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51DC0C4CEE5; Mon, 10 Mar 2025 17:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741627173; bh=nN8JNFtlDE3lheQhPQUelGBhTCDE42KiMurAnIiRIiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sFNzjw3QLq0BqduHMgjKtpemuUwUUje8U9SRNrysk2o+Chx4b/ZEVQ853ZvThYQJr pvgAA1v/6+0788/Bl+Kv4DAs6r9rZ+7d52L8PkcU0Gb9FWWKHmu2dwtN6skdWiwlGM T632xkS5qlYUs9B1dOx5qet/hT9U13ULvekEcjRY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alice Ryhl , Benno Lossin , Gary Guo , Danilo Krummrich , Miguel Ojeda Subject: [PATCH 6.12 037/269] rust: alloc: add module `allocator_test` Date: Mon, 10 Mar 2025 18:03:10 +0100 Message-ID: <20250310170459.198285127@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250310170457.700086763@linuxfoundation.org> References: <20250310170457.700086763@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Danilo Krummrich commit 5a888c28e3b4ff6f54a53fca33951537d135e7f1 upstream. `Allocator`s, such as `Kmalloc`, will be used by e.g. `Box` and `Vec` in subsequent patches, and hence this dependency propagates throughout the whole kernel. Add the `allocator_test` module that provides an empty implementation for all `Allocator`s in the kernel, such that we don't break the `rusttest` make target in subsequent patches. Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin Reviewed-by: Gary Guo Signed-off-by: Danilo Krummrich Link: https://lore.kernel.org/r/20241004154149.93856-8-dakr@kernel.org [ Added missing `_old_layout` parameter as discussed. - Miguel ] Signed-off-by: Miguel Ojeda Signed-off-by: Greg Kroah-Hartman --- rust/kernel/alloc.rs | 9 +++++++-- rust/kernel/alloc/allocator_test.rs | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 rust/kernel/alloc/allocator_test.rs --- a/rust/kernel/alloc.rs +++ b/rust/kernel/alloc.rs @@ -2,12 +2,17 @@ //! Extensions to the [`alloc`] crate. -#[cfg(not(test))] -#[cfg(not(testlib))] +#[cfg(not(any(test, testlib)))] pub mod allocator; pub mod box_ext; pub mod vec_ext; +#[cfg(any(test, testlib))] +pub mod allocator_test; + +#[cfg(any(test, testlib))] +pub use self::allocator_test as allocator; + /// Indicates an allocation error. #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub struct AllocError; --- /dev/null +++ b/rust/kernel/alloc/allocator_test.rs @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 + +#![allow(missing_docs)] + +use super::{AllocError, Allocator, Flags}; +use core::alloc::Layout; +use core::ptr::NonNull; + +pub struct Kmalloc; + +unsafe impl Allocator for Kmalloc { + unsafe fn realloc( + _ptr: Option>, + _layout: Layout, + _old_layout: Layout, + _flags: Flags, + ) -> Result, AllocError> { + panic!(); + } +}