Message ID | 20221110164152.26136-12-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 l7csp251707wru; Thu, 10 Nov 2022 08:44:33 -0800 (PST) X-Google-Smtp-Source: AMsMyM579WSp0rajVZnYsV7CnUSIEMArWdXDjlw17L02zL2S36QEqXwdE8314F3IXg/OpOUTQQuH X-Received: by 2002:aa7:dcd5:0:b0:461:5fad:4215 with SMTP id w21-20020aa7dcd5000000b004615fad4215mr65947611edu.332.1668098672985; Thu, 10 Nov 2022 08:44:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668098672; cv=none; d=google.com; s=arc-20160816; b=phqLfo4N8yN0hI8uSDdnDmFWkOOMjYmpUvmS2+RasxuTzFvCNFlUMVDqiLkGqMyxPT CA4KgEsNg1sKlV8e+6JAbYNHx9gJLyUoCmFmJGgWMuZDaEdQxLvLeBhrodbB+KGaS8MN XTlV8unU7XIIJhLW6Ef6m9aaGIFkgAuWDWalEG6yUyWiqA+h2OI+w/M/VK8iFFf1PDC6 f/+o96XQ0t8LroDM0rT+pF/TisYF0sNy3yCFik+nYAHGukFwjzGQpOilUEuHot2JbHRK VfOd18SWGwSiyty8Pg3bVN56PGkF0YnOtJmw4zqjkt2y28fkTcnt0WQD0GOzwRA5Wm8Z VzMQ== 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=kjyB0L3v/WSt6i3VJ0y38bLFmB3YWf7Yg6UXFfhxsTw=; b=GXMF8sJ70EF8ALPQ07ThQ3M7jr+ataQGln5uKKVDaLhmK7Gw9WffP/roS8yAAaczBq BzUUTRJcMpo/Ucq3lqyOjZSeFE848T8Vqam3aNUTGJ3QCGFKmiP7Ztmv5lCdAfWHL1iz EWt8Fyk+fim4AStzYxbp8zpTUEO2/TStoCJY8tmQvH1D/C0306xQYpLcJWhNtHxzj4tU 8KHcuM1EHIipaOb5pvMX1AS+Pd+XNkjxYll5BKxo+iw9Iuf+o+GSHvm6tvFscOghBZmx YzpuSTwAYYB4Inm7J31dDu6AHUgxoL1aOXPeKPgBkYbfVdSjasCu3oYGs4VllT8Km9BD 8idg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uSw9Fyis; 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 gn15-20020a1709070d0f00b0078239e3f846si20827528ejc.1.2022.11.10.08.44.08; Thu, 10 Nov 2022 08:44:32 -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=uSw9Fyis; 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 S232282AbiKJQnj (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Thu, 10 Nov 2022 11:43:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232269AbiKJQnJ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 10 Nov 2022 11:43:09 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D9FE45A3E; Thu, 10 Nov 2022 08:42:54 -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 ams.source.kernel.org (Postfix) with ESMTPS id 0DA30B82248; Thu, 10 Nov 2022 16:42:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC6DFC43150; Thu, 10 Nov 2022 16:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668098571; bh=J+cwd2iu48BeHn73Bu4PeBxaaHkYRYafz2YHSK3Yjjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uSw9FyisDjfN09jEGFqMNicm0MJQe4gjqoQHUcw0zW8s3zbT71HkF7coKOTFDAIEF KeUAeyvy+trgzIGFr7nvNIJdho1rG3qLM/6MeFCQJqonH9iAMxHZEaf7CaQDsl5rHi pxtgrv2vNzqPZqfvKpIhhVcLd816IsfyaBZLV9ifPgsgwe3XSmr3EDC7dRb1HiPUqj 87PKmFi2DHO5LxTg+sErRFR9xN0Oe2rM1unhtzfDoibHtxRMWvP08FALvX7eyqz+WA 7pp60pskFP9ppg3E1HOuKdgPqGDGrpXKlpe9CFOfIvdIVxUZQwwF8eI9GK1CgQVA1w MUqryAoSBk9HQ== 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 Subject: [PATCH v1 11/28] rust: prelude: add `error::code::*` constant items Date: Thu, 10 Nov 2022 17:41:23 +0100 Message-Id: <20221110164152.26136-12-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?1749128233980016970?= X-GMAIL-MSGID: =?utf-8?q?1749128233980016970?= |
Series |
Rust core additions
|
|
Commit Message
Miguel Ojeda
Nov. 10, 2022, 4:41 p.m. UTC
From: Wedson Almeida Filho <wedsonaf@gmail.com> It is convenient to have all the `Error` constant items (such as `EINVAL`) available as-is everywhere (i.e. for code using the kernel prelude such as kernel modules). Therefore, add all of them to the prelude. For instance, this allows to write `Err(EINVAL)` to create a kernel `Result`: fn f() -> Result<...> { ... Err(EINVAL) } Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda <ojeda@kernel.org> --- rust/kernel/prelude.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, 10 Nov 2022 17:41:23 +0100 Miguel Ojeda <ojeda@kernel.org> wrote: > From: Wedson Almeida Filho <wedsonaf@gmail.com> > > It is convenient to have all the `Error` constant items (such as > `EINVAL`) available as-is everywhere (i.e. for code using the kernel > prelude such as kernel modules). > > Therefore, add all of them to the prelude. Personally, I would prefer to have all error codes as associated constants of the `kernel::Error` type so the code below would use `Err(Error::EINVAL)` (more "Rusty" way of writing things). But IIRC that we settled on the current approach because it's more similar to existing C code. > > For instance, this allows to write `Err(EINVAL)` to create > a kernel `Result`: > > fn f() -> Result<...> { > ... > Err(EINVAL) > } > > Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> > [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/prelude.rs | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs > index 7c4c35bf3c66..1e08b08e9420 100644 > --- a/rust/kernel/prelude.rs > +++ b/rust/kernel/prelude.rs > @@ -19,6 +19,6 @@ pub use macros::{module, vtable}; > > pub use super::{pr_alert, pr_crit, pr_debug, pr_emerg, pr_err, pr_info, pr_notice, pr_warn}; > > -pub use super::error::{Error, Result}; > +pub use super::error::{code::*, Error, Result}; > > pub use super::ThisModule;
diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs index 7c4c35bf3c66..1e08b08e9420 100644 --- a/rust/kernel/prelude.rs +++ b/rust/kernel/prelude.rs @@ -19,6 +19,6 @@ pub use macros::{module, vtable}; pub use super::{pr_alert, pr_crit, pr_debug, pr_emerg, pr_err, pr_info, pr_notice, pr_warn}; -pub use super::error::{Error, Result}; +pub use super::error::{code::*, Error, Result}; pub use super::ThisModule;