From nobody Fri Jun 19 07:47:09 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53A9616F288 for ; Fri, 24 Apr 2026 06:45:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777013116; cv=none; b=bxXdB/0S/uTNlLCMlk46DepT+ywvdnhDw5VYJehUzzybO8o/CyBfQgFJ1QU3kvqNiH/721FrRsPSjx1ammYDoNIqTh+gByl3HZ8v1d4fFgx0KllxCC+vlam83u2SEhvqs1aMRKwnYY711jcK/S5vsCT5EFOKFJKL3aXYg2tPqc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777013116; c=relaxed/simple; bh=Prc4SN6K9n9uEQ2sXWlX9fAmLEOWBxJIHJ9Lk+N4WcU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lIz2ocNwF77UWvg9RZgoNQSlB6TS5PVVD07hobI2F5nWRliVyehM/S8rRXwSblX+HSC5BciGQ2bDWoa1X/DhiN6/iiXplN6JokMCMZMXGJuTs4LY+Sa79MmOQHQGklyIilKivjLrvjryK6GQ9derilCKO2qSGp+/hB/qEd0lcUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=O3Xh5Xfb; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O3Xh5Xfb" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2ad4d639db3so38173525ad.0 for ; Thu, 23 Apr 2026 23:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777013115; x=1777617915; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QeitggvRJhqpoo6Zt75xFK9Pxxp4BKwQty2a6KWXTS8=; b=O3Xh5Xfb1ylI9i2JlxNW6PhHo+gaCKGtwSnIAPyck6ESp+VmPs13+IX64WLCJS6PNM qsxCumTW/jzX3wa9dUYZ+98+hwi77H28zG0/AhBSok92FoieuWizE9AauS+O/s12sn+6 hJcB2xAZterpMCMvRQ6buwK0qKCVq5JxtBWALd6aHT5jj/MsDE5DW2tgPSnz9/Ju1sVP xha/4Ef1Eb7oHqu8vEHuhL2S91q3CXiDweMy+2gg6EhFH+QNd01WSKW3+FrioZsnuPgn inftAAmXv1/W1irnlIjkFmlqior8YLiZwZ0fnxIg2t55t6mX8uDEjL/zbjSlb66o6kEW 1GAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777013115; x=1777617915; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QeitggvRJhqpoo6Zt75xFK9Pxxp4BKwQty2a6KWXTS8=; b=ooat5FMpKS2l7L3UQgxQqZsYQvrV15t2jUd8sejsFIB8I17hHqPZ3+GXOpHzP9s8o7 1pOrm7BDjSNJjporAN4w6GBuL+8yHEoPde3ZuYW8ZHJLhHJyWY8yFC+bawNgnxoTE8MV hhm8loZpUA/V0xLULxp6L+aDbIOmRmOKj3ka563XjHbGFpGpbmBwB/x3kzhq0XvgdQJc lgCZCsRjFDOUCn+qAqOIbsRJxtahxHHvVkfmzw2/i7J9pU/XW+MPfFCpK7XwpCa7WFnu rBZRqKNl2QATFG+GUWOxWyL9yNfVR/AzbYL/Ou0WvNdOKk5kyCiIyDKOYE+g78SsUmEN Hwdg== X-Forwarded-Encrypted: i=1; AFNElJ8OpNabbM8iogA97voRmQBQ8d+yARHA+//MfTH+fj7REOjc7VTv3ZI55A7QFM/pPSfYJ/yCEok390bg6tI=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3hWjw1HeZgr2KamvPjo7IEp0qX3N0HAdJQ/WKpAwGeOG/PUNV h4ZFP4cZOso/mjNUGqxIm+9RdAWfj6IhG87UWBfqD52Mqg7ogOfm7exn X-Gm-Gg: AeBDiesYbGr4QVf7Y86hNAZZdpyUz4zmu+fa2QoiwXncxwpWdBXmzgUAsR+AmC59ZfX lKn3YDSjrSHJ9Y+edCXP68HfFpIXggrxGIK8IyO0y9HmvYGHtRDfIcvHq3jvdFwYyG+X0Za7hxT 79YtEJxYixxVT6MnOBN1SKjHO58RfLry6cV0yBEYXerWweF1AiUHb6jHSF0UC8Nn4/nv5iapVy+ fd2nl6e/QquKCVEfNTNWw8Luvyqeq2RC4TWwJihrM3+kpqaihUnIx0uIGFc/U9mfYRpoKjXt3U7 WiTP7imzQrDl3Y1yQokVtImiQe9u4QqyjHXh0OxqsrpUPQgQOm9J5VmXLcobU/Ennbo33nlKeuv 73DZwqMxW834LaGIvM0/QlRK/pWEsqatkSluGYspalYpHNJbDNRRZq7cOC2kJxKKpB8drtuABcn 4DZDDdkn77okDgQsGQLYszvfk/dw/VZGkIUzzsJ+QthtPLWKxDXaRuehD0tA== X-Received: by 2002:a17:903:2ec5:b0:2b2:5503:1b8c with SMTP id d9443c01a7336-2b5f9eebb7amr331003595ad.11.1777013114540; Thu, 23 Apr 2026 23:45:14 -0700 (PDT) Received: from localhost.localdomain ([49.213.140.88]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab20695sm212320285ad.56.2026.04.23.23.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 23:45:13 -0700 (PDT) From: Hsiu Che Yu To: Danilo Krummrich Cc: Hsiu Che Yu , Lorenzo Stoakes , Vlastimil Babka , "Liam R. Howlett" , Uladzislau Rezki , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] rust: alloc: add smoke test for zero-size realloc code path Date: Fri, 24 Apr 2026 14:44:43 +0800 Message-ID: <20260424064443.264504-1-yu.whisper.personal@gmail.com> X-Mailer: git-send-email 2.43.0 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" The `Allocator` trait documents that reallocating with a target size of zero must be equivalent to freeing the memory: "If the requested size is zero, `realloc` behaves equivalent to `free`." Add a smoke test to verify that `Kmalloc`, `Vmalloc`, and `KVmalloc` do not error or panic when reallocating with a zero target size. Note that the actual deallocation performed by the underlying C functions is not verified here. Link: https://lore.kernel.org/all/20260424052936.250238-1-yu.whisper.person= al@gmail.com Signed-off-by: Hsiu Che Yu --- v2: clarify that this is a smoke test and does not verify actual deallocation rust/kernel/alloc/allocator.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs index 63bfb91b3671..85606c30dab6 100644 --- a/rust/kernel/alloc/allocator.rs +++ b/rust/kernel/alloc/allocator.rs @@ -305,4 +305,29 @@ fn is_aligned_to(&self, align: usize) -> bool { =20 Ok(()) } + + #[test] + fn test_realloc_zero_size_does_not_error() -> Result { + // Note: this test only verifies that zero-size realloc completes = without + // error. The actual deallocation is performed by the underlying C= functions + // and is not verified here. + const INIT_SIZE: usize =3D 64; + + let old =3D Layout::from_size_align(INIT_SIZE, 1).unwrap(); + let new =3D Layout::from_size_align(0, 1).unwrap(); + + let existing =3D unsafe { Kmalloc::realloc(None, old, old, GFP_KER= NEL, NumaNode::NO_NODE)? }; + let existing_ptr =3D existing.cast::(); + unsafe { Kmalloc::realloc(Some(existing_ptr), new, old, GFP_KERNEL= , NumaNode::NO_NODE)? }; + + let existing =3D unsafe { Vmalloc::realloc(None, old, old, GFP_KER= NEL, NumaNode::NO_NODE)? }; + let existing_ptr =3D existing.cast::(); + unsafe { Vmalloc::realloc(Some(existing_ptr), new, old, GFP_KERNEL= , NumaNode::NO_NODE)? }; + + let existing =3D unsafe { KVmalloc::realloc(None, old, old, GFP_KE= RNEL, NumaNode::NO_NODE)? }; + let existing_ptr =3D existing.cast::(); + unsafe { KVmalloc::realloc(Some(existing_ptr), new, old, GFP_KERNE= L, NumaNode::NO_NODE)? }; + + Ok(()) + } } --=20 2.43.0