Message ID | 20221110164152.26136-9-ojeda@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp251534wru; Thu, 10 Nov 2022 08:44:06 -0800 (PST) X-Google-Smtp-Source: AMsMyM4BxtU0avBUjSPWUVFQSEdhi+gQNAuEbdFFtoFgPX8Xmaiudi8tphUmk0PKZ5ydkUy1AHpY X-Received: by 2002:a05:6402:c87:b0:459:9dd3:2217 with SMTP id cm7-20020a0564020c8700b004599dd32217mr2589667edb.163.1668098646706; Thu, 10 Nov 2022 08:44:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668098646; cv=none; d=google.com; s=arc-20160816; b=XVmxTaUVCxwSlW/HKfqDfnak1PW0yswxpGIMHuqy6EqmEscyGjhHfqUNWxzGtXXAv9 Zz5hea+vrpQ4kB8zCdbZB4HAGhQmZKlMQrS/EA8rOUmY8DENgS6U1TtoYPC5YFdhgzqL Rj7VJsbzBu2Gi5FPFicbvJxThwkyBEWCflba3V58eKcFRnHm1cK/xNwQK/AdyA4iFbqT Bb3yvGEb1xVm06R9DTwTSSRSYUIGmdjUeivkL5h39F6wHodAJIOI7zrmvGd2iBDi59fI B+65ZBNaB/Teo8JkX1C65KCIeFbBZzKiPo7p6tyxI0iejRFEMb27HEY8mJTco45eI6N4 fAsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g5cVh0xSq3jaNRDqfhMMQW4dkxnGleN2X+5zgROr4jI=; b=TXKQ7SfZGsAhEHVAwl9rJlhsX+STn3XraFNMBRBkgedUhbfpa6Zcx6UeU7UJYSd6HV l67ZocYQBOFflI8GWJ+5wSvf0LGlHGXo+lwRxaVyuaNKI82GpRV0sh762SOF9CBSpfTy uVthyYm3FkXM6zOfyPyWSypf/giSmfwXw5NQ2aNC0MWsc8O7qULy9axhO6vACxaVALpo DDk0WkSX1oNKRdWi/HWxAw95tqbWj36jBFjT3HieQ3BLgUHjDS4f27Oa/xFJqb3Z7GWX 7Lp4ZNLMMpvYknlVbDR36M2U2yDOYT7YN0ZaP4sKRSMmFX3om2yeAYvpjfKHl5mccMTz C+xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G1+TkYS8; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr14-20020a1709073f8e00b0078d878d8fb7si19213852ejc.920.2022.11.10.08.43.42; Thu, 10 Nov 2022 08:44:06 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=G1+TkYS8; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232115AbiKJQnO (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Thu, 10 Nov 2022 11:43:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232145AbiKJQm6 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 10 Nov 2022 11:42:58 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97387450A0; Thu, 10 Nov 2022 08:42:43 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2FE5161BCD; Thu, 10 Nov 2022 16:42:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DC79C433D7; Thu, 10 Nov 2022 16:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668098562; bh=6C+J3CqClsIGimlHszB691qkxwmrQJQgf22GuHYX/4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G1+TkYS81fI6KSg3uG+BjrvTTqwlFukFJRj2LwmIc/PY+4bu15wKIHNVRoMKmd2w3 fOILmAK9tfxfkhrj1mZCLHN67XlwCgHTuFOTQtgog4E1l1DZijE51REMWOHUKX+AgU Cf6Cl+PmHmrNUfwGYynRW6v35tV6JQ8m47tEE1noO0kLk3P4GpQDeLriy/uMxv8jCZ 8EH6wHcR5p2rdvqVYomwjKh4SreNFMlss2KEl0EdqsrU1t90p8SuY3Kuet8yilSJ6s /Amoxx4CaUbgEQ5q6nVtIIkC6vyTWt/zaw3fEq7ZGmCqORj1UXaSXE+1FYnYfbnWw5 lXJ435A+AMdog== From: Miguel Ojeda <ojeda@kernel.org> To: Miguel Ojeda <ojeda@kernel.org>, Wedson Almeida Filho <wedsonaf@gmail.com>, Alex Gaynor <alex.gaynor@gmail.com>, Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com> Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Finn Behrens <me@kloenk.dev> Subject: [PATCH v1 08/28] rust: error: declare errors using macro Date: Thu, 10 Nov 2022 17:41:20 +0100 Message-Id: <20221110164152.26136-9-ojeda@kernel.org> In-Reply-To: <20221110164152.26136-1-ojeda@kernel.org> References: <20221110164152.26136-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749128206695513604?= X-GMAIL-MSGID: =?utf-8?q?1749128206695513604?= |
Series |
Rust core additions
|
|
Commit Message
Miguel Ojeda
Nov. 10, 2022, 4:41 p.m. UTC
From: Finn Behrens <me@kloenk.dev> Add a macro to declare errors, which simplifies the work needed to add each one, avoids repetition of the code and makes it easier to change the way they are declared. Signed-off-by: Finn Behrens <me@kloenk.dev> [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda <ojeda@kernel.org> --- rust/kernel/error.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
Comments
On Thu, 10 Nov 2022 17:41:20 +0100 Miguel Ojeda <ojeda@kernel.org> wrote: > From: Finn Behrens <me@kloenk.dev> > > Add a macro to declare errors, which simplifies the work needed to > add each one, avoids repetition of the code and makes it easier to > change the way they are declared. > > Signed-off-by: Finn Behrens <me@kloenk.dev> > [Reworded, adapted for upstream and applied latest changes] > Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Reviewed-by: Gary Guo <gary@garyguo.net> > --- > rust/kernel/error.rs | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs > index 466b2a8fe569..b843f3445483 100644 > --- a/rust/kernel/error.rs > +++ b/rust/kernel/error.rs > @@ -8,8 +8,16 @@ use alloc::collections::TryReserveError; > > /// Contains the C-compatible error codes. > pub mod code { > - /// Out of memory. > - pub const ENOMEM: super::Error = super::Error(-(crate::bindings::ENOMEM as i32)); > + macro_rules! declare_err { > + ($err:tt $(,)? $($doc:expr),+) => { > + $( > + #[doc = $doc] > + )* > + pub const $err: super::Error = super::Error(-(crate::bindings::$err as i32)); > + }; > + } > + > + declare_err!(ENOMEM, "Out of memory."); > } > > /// Generic integer kernel error.
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 466b2a8fe569..b843f3445483 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -8,8 +8,16 @@ use alloc::collections::TryReserveError; /// Contains the C-compatible error codes. pub mod code { - /// Out of memory. - pub const ENOMEM: super::Error = super::Error(-(crate::bindings::ENOMEM as i32)); + macro_rules! declare_err { + ($err:tt $(,)? $($doc:expr),+) => { + $( + #[doc = $doc] + )* + pub const $err: super::Error = super::Error(-(crate::bindings::$err as i32)); + }; + } + + declare_err!(ENOMEM, "Out of memory."); } /// Generic integer kernel error.