From patchwork Fri Jul 14 09:17:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asahi Lina X-Patchwork-Id: 120374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2383124vqm; Fri, 14 Jul 2023 02:40:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlEoeo+eXv4ZVBZ9HMhmLrv1HXWE6iefJHH3KVOLSEO0ZeEyszZYos7QXQtD9GfLYQrXx+Wg X-Received: by 2002:a17:906:1014:b0:993:ec0b:1a27 with SMTP id 20-20020a170906101400b00993ec0b1a27mr4240473ejm.24.1689327638419; Fri, 14 Jul 2023 02:40:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689327638; cv=none; d=google.com; s=arc-20160816; b=Dxe1DfSuTJ0p3BfoOrRa8zC1Dd0SvOEAUh33TsdlGXUbchHsN2RGUs3qAmMYcEHrS3 kpSk46Y9MCk1SJmg3AJGk1UjB6M8pfR7ZV6hfN6YfT5uNrp+101yxcnNzRzg4vAZW+qp 40H2FpTY/U8sj7XK8T1hsYJfO3UTuy8Mu3iSApiva7cvozRB4tpwhsPhvjBOaEU4LcvE Hz+4iSxoiFKpSuhBD34w3MLmFo4phAowGlR3Lvx5jghg5koQSJxZaVfqIBp2VbkV6A6C qAgqr4Q/jUyNLHQzsNpHpqep94bHXRb0CjNaHjYkMekMcvBLb3G7sLATmF/nZjw8vsQY 1IgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=vnWMdwXLuP/aW30w25z0wSaV7u89d26BeaMjl35zF+g=; fh=o3iEvnwkVOkfgoKDkKIpCOf8FpHXfOw5wgWullwJWLk=; b=wy3dboGCBvh0wY5zKNe0/M8EjVfjzpGP+bRwiAfOg3e9KjTeZF+5cEK8GPPDNwgBSJ QVedIFjrp7STXkTV373rWxebu9K869CLpg7eIpvi4F0S6p4TTExVefboWP8/92EVP+uM 9aM7BZTRhDl2lFIVSP2MwRh6dfOdyOa0OTMLiumSF4UrtHWyFIOt0rIjsgJjuREEPPdn D4qOYSK4U0ROTXDrpQ7uLI6sOf/qswxW+vB4tzPeWsfFl/br8x3cm+G0d8NWx/zRoQDB iPGOZgA7hDoleF6mD2rjGZa4er6mJxv3RXID99UVHrVOiJHnhdepGny2hXtxErOguixj aY5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=ASk5n4Cn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a170906938c00b00991b9b54b2asi1000102ejx.135.2023.07.14.02.40.13; Fri, 14 Jul 2023 02:40:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=ASk5n4Cn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbjGNJg0 (ORCPT + 99 others); Fri, 14 Jul 2023 05:36:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235743AbjGNJgI (ORCPT ); Fri, 14 Jul 2023 05:36:08 -0400 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8D533590; Fri, 14 Jul 2023 02:36:06 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: linasend@asahilina.net) by mail.marcansoft.com (Postfix) with ESMTPSA id 81EFA5BC9B; Fri, 14 Jul 2023 09:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1689326244; bh=qJo7mYZ92ZVzEhgvxpERMJP/merzZqrWhb59Z8XEN0k=; h=From:Date:Subject:To:Cc; b=ASk5n4CnvsESI2z/tecTRAvXqRKZ4wFHacuFAWJHfM38PBGB0zWdtQnwgt/EZun6s A1oLjkZMXu4htW+YOLmyGuwUYv8A4iafoJjlgVjI9djMSnDpYGwc6iJgUkNQNIeynB 6ORsj8QMo7XJfCACQdbxCNEAQsD5qKzxUVkgjHxAIkUsJl9HxnF5wLSmE/aCo+Hp4M 6lMW9O7xK3HW56xlh7mxLmI84iIXfd0jwStYSZEdLf6DNdr5PW909xo1YK9qIxrlkB e++xCU4LZUqad22/hevlsdN9hNxid6MOXAL95MHdqdRmd/+rmBumi5fV4VWshBX7vQ cg1CogqR45Iyg== From: Asahi Lina Date: Fri, 14 Jul 2023 18:17:16 +0900 Subject: [PATCH] rust: init: Implement Zeroable::zeroed() MIME-Version: 1.0 Message-Id: <20230714-zeroed-v1-1-494d6820d61b@asahilina.net> X-B4-Tracking: v=1; b=H4sIAJsSsWQC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI2MDc0MT3arUovzUFN2UFAPTpGRzY/M0C1MloOKCotS0zAqwQdGxtbUAjkp eH1gAAAA= To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Asahi Lina X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689326241; l=1060; i=lina@asahilina.net; s=20230221; h=from:subject:message-id; bh=qJo7mYZ92ZVzEhgvxpERMJP/merzZqrWhb59Z8XEN0k=; b=/0R7QoF0o5fRt1iGDE6jPrr2eE28drfWrZESrdhNbNwynMxHwuBVKvZKSoPzlgKPC6hNC8jWy heVaSsDCaPlCGkQ8LqGPG2nsisyLGbN3LrdUTiQZbyJt2ztAXZgdURV X-Developer-Key: i=lina@asahilina.net; a=ed25519; pk=Qn8jZuOtR1m5GaiDfTrAoQ4NE1XoYVZ/wmt5YtXWFC4= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771388417725256613 X-GMAIL-MSGID: 1771388417725256613 By analogy to Default::default(), this just returns the zeroed representation of the type directly. init::zeroed() is the version that returns an initializer. Signed-off-by: Asahi Lina --- rust/kernel/init.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5 change-id: 20230714-zeroed-dd05bc737f85 Thank you, ~~ Lina diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs index b4332a4ec1f4..c300ce39ac10 100644 --- a/rust/kernel/init.rs +++ b/rust/kernel/init.rs @@ -1354,7 +1354,14 @@ pub unsafe trait PinnedDrop: __internal::HasPinData { /// ```rust,ignore /// let val: Self = unsafe { core::mem::zeroed() }; /// ``` -pub unsafe trait Zeroable {} +pub unsafe trait Zeroable: core::marker::Sized { + /// Create a new zeroed T. + /// + /// Directly returns a zeroed T, analogous to Default::default(). + fn zeroed() -> Self { + unsafe { core::mem::zeroed() } + } +} /// Create a new zeroed T. ///