From patchwork Fri Dec 2 16:14:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 28983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp948519wrr; Fri, 2 Dec 2022 08:19:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4P3n+yXOaC7LwOqnW8CiS8JwmVBG6PGebFFerAvaNIoitFWNvJhfOUWD8rA6i8GC7oHlSo X-Received: by 2002:a17:902:d652:b0:189:a770:6eab with SMTP id y18-20020a170902d65200b00189a7706eabmr15248718plh.135.1669997999364; Fri, 02 Dec 2022 08:19:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669997999; cv=none; d=google.com; s=arc-20160816; b=XKIto/yMfK8zVT0zEdXfk/A7Zb2TRmzFWJjy5tTD7REGMsA+n7kMQMHoWN/prUdD3T RgCkCiHNdL20S78SP7n03BWEkQRXaTQwDUvT5Q5IQf+L/wBAZXzUvxhmfmUSsNgk745z 6Z49IIiv72cYSTVXfi3pUX5x4MwhXVerr5JdXTEsNUVy1wOn9fDmcE2HpIOxnMwFnPjF 1kUdo1TVecZHpdmppxFJ0ZrUkQ/JsNlRddCUsmN4V8jdm6Xt6HNXUcXBiq1R7PUt3uYZ oZ36FC1n7TXzxema9+1evC07/Xml83PPQI3fojSxjAZ4yODfW90YFRTJ6HTrAJyvbtO7 FtRw== 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=5lTc7/D3JX8xntYefWsiTSlrCd646eqIcghNpHLHPlE=; b=AXFDLFiSDEkrajPSFAnaY/mArWAFcCPmqMWrYdEGHd2tZVymjN5PyizR9aGLPWKKO0 7ALY35yYkdbzKK2CY8GRDRbHAy1/jDWXL1lOyopOPLDkv48C0D/YbpDJnuhuHnSf5sid LqhZxYumlo0pPQtc7HGImV6CE3dnShYCa67FaPOtGMQAHPPR2b16ZGHwxaTX2Kl/XkV4 ChZP0brJecL6ZC476NB+4ehwGD76ej1qTn2GyMHOTbLYcAK5BBMeoclGzOpUGSdqtvgF 9tp3rlgLafo6FhpwiCCKJno/PEX5HX/MTDtxhM5JMKkdCqop9SMnI7BKFv266ZrRznnh zB8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XrlQLClC; 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 nk11-20020a17090b194b00b0020a755f2b83si10310662pjb.100.2022.12.02.08.19.37; Fri, 02 Dec 2022 08:19:59 -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=XrlQLClC; 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 S233932AbiLBQQq (ORCPT + 99 others); Fri, 2 Dec 2022 11:16:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233877AbiLBQQK (ORCPT ); Fri, 2 Dec 2022 11:16:10 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FF46BF67C; Fri, 2 Dec 2022 08:15:53 -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 9E7EF62331; Fri, 2 Dec 2022 16:15:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB730C433D7; Fri, 2 Dec 2022 16:15:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669997752; bh=3ozUOhrx52YHTps33arj4MB6UyVgxyGlHJRWzGu7eJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XrlQLClCl6lfpp1Axk7H9bFmwhtWQUtAGk45+2MVLgUfucuVL18toqPILDZqakMEa q4xgxTxkPKcVEnR0ei12ZpVF5v/5KQJN95pGG057rOFV8OHNC0F1sCPQYCUL7Gm2aC wKGHcsNz8rLyKzXdBcbB4tfsWHLI1dZ+DsoEJA8Uw9htPCOgbyRp3UmA90bFBysBvU 06Fuw2TDtnG1pWBBPQkchyWi6t9Mkz6GNIVDFQs4S90BBbDjn3cPwJktAlOd/3AcOZ G/J0pvRKUlBjyAtKsYF/bPGO74BvwLz1phTne5YnvFDUZ4jhXZ/mMbf683kZjvaJlN emn0duyZHTbug== From: ojeda@kernel.org To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Finn Behrens Subject: [PATCH v2 08/28] rust: error: declare errors using macro Date: Fri, 2 Dec 2022 17:14:39 +0100 Message-Id: <20221202161502.385525-9-ojeda@kernel.org> In-Reply-To: <20221202161502.385525-1-ojeda@kernel.org> References: <20221202161502.385525-1-ojeda@kernel.org> MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751119822180405600?= X-GMAIL-MSGID: =?utf-8?q?1751119822180405600?= From: Finn Behrens 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 Reviewed-by: Gary Guo [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda --- 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.