From nobody Thu Sep 19 01:06:34 2024 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 DEA0F157E9F; Tue, 23 Jul 2024 18:11:21 +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=1721758282; cv=none; b=JTzlgw2aCEAmWwxkQrVFqc2o9ITYd/OLmlqQZg+blMsNlNCGr8/PFRLzveVAmXjr76T64aroUUGynNacE7Kn2IdNwgR10+61hhiEnF7RNuIk923fzZABCt5+ECVit71g2X+mLFj+XuWEX4UhA8bVbM9WC/D7M+vnsgLvP2oSJ+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721758282; c=relaxed/simple; bh=/CAVj622i+EjUqJe9C6/xiYM7R6rhnj9Rb056J9W4L4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fjevPj6wxNXmKhlSCyMTF/uQcq1v1woEvDWqT/Ly/y/NX71UUHM5VcTmPB7hq6mdR5q+fvO0UGcE0Lm+UdFBv/XzbfJsbBeUqCUQcKIETwtBRgi7rVzqnmrPxPQ1YX0SRqsu7r0pcHWhUgMSIh+Nc+pKgWgqEf69GZ6D+KbVOf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KMGsYeNW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KMGsYeNW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A874C4AF0F; Tue, 23 Jul 2024 18:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721758281; bh=/CAVj622i+EjUqJe9C6/xiYM7R6rhnj9Rb056J9W4L4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMGsYeNW8i1peerLA/ZxLTXTQB9autbiVJPYjR+Z7R/ZSaXPgKMAOX82xJwY94ndK j6uF99PhRxWMBTW3xVh6hAyjUH8iSWR3Cqu5/pc6UVffMXJNCJyumJIBn131wOrlSe 8IFbhkCh1ORfxDTu/EGVqEmc0BgLW48bdJCypLh3aA4tHsvMaozfT/A9AYXOqgXpXJ 0cCRVVFRxfthxcjIODCObO9cZyV1r1/dBPiDqkIOB8F2MzBQ+PF3MQcjZCmS0SNVoV 1lYsPT8UEgprnAIv+APz1a2AhuCoGmxgUNwnbYiYShoWixYfSwlOobf+7ER2pcFhn8 DMVAdjIiCdnHA== From: Danilo Krummrich To: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@samsung.com, aliceryhl@google.com, akpm@linux-foundation.org Cc: daniel.almeida@collabora.com, faith.ekstrand@collabora.com, boris.brezillon@collabora.com, lina@asahilina.net, mcanal@igalia.com, zhiw@nvidia.com, acurrid@nvidia.com, cjia@nvidia.com, jhubbard@nvidia.com, airlied@redhat.com, ajanulgu@redhat.com, lyude@redhat.com, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Danilo Krummrich Subject: [PATCH v2 05/23] rust: alloc: add module `allocator_test` Date: Tue, 23 Jul 2024 20:09:54 +0200 Message-ID: <20240723181024.21168-6-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240723181024.21168-1-dakr@kernel.org> References: <20240723181024.21168-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" `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. Signed-off-by: Danilo Krummrich --- rust/kernel/alloc.rs | 9 +++++++-- rust/kernel/alloc/allocator_test.rs | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 rust/kernel/alloc/allocator_test.rs diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs index bf739ce65387..90ebe79e86cb 100644 --- a/rust/kernel/alloc.rs +++ b/rust/kernel/alloc.rs @@ -2,12 +2,17 @@ =20 //! Extensions to the [`alloc`] crate. =20 -#[cfg(not(test))] -#[cfg(not(testlib))] +#[cfg(not(any(test, testlib)))] pub mod allocator; pub mod box_ext; pub mod vec_ext; =20 +#[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; diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/alloca= tor_test.rs new file mode 100644 index 000000000000..3a0abe65491d --- /dev/null +++ b/rust/kernel/alloc/allocator_test.rs @@ -0,0 +1,21 @@ +// 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( + &self, + _old_ptr: *mut u8, + _old_size: usize, + _layout: Layout, + _flags: Flags, + ) -> Result, AllocError> { + panic!(); + } +} --=20 2.45.2