Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1961606rwl; Sat, 8 Apr 2023 05:27:19 -0700 (PDT) X-Google-Smtp-Source: AKy350bh1k96Rt3H3zVfWRoy5R0rJuKJ27RFTlfhSvxtVTN21nLcH/siZC4PFYMjZ/qSCQPdG/lP X-Received: by 2002:a05:6402:785:b0:502:9a5b:206e with SMTP id d5-20020a056402078500b005029a5b206emr1071630edy.9.1680956839087; Sat, 08 Apr 2023 05:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680956839; cv=none; d=google.com; s=arc-20160816; b=CmXPfFx0TI31zLZ4JPhXvoH7rXdx/8PLVKGZgCK5xpx79LZ/F0DIyyyxhZteqBKGHb kllPoCk14gXB5niymO89+tMCGMhD2CVkTxHkJOot4JN1xUgvcT44qLNVwKKsDlS5X4ad jfFTHMHd5qrQgs/xuCkECHI+K/wL+eUj3D3HfjEW/i/In2px5GFYP+8HspLTX8Uh6xAy DBuZo63BWBXNCwlkDIqrLd6BGS2UrHtjI1uohqgZ2MSrPneKda6m82z2bc99wbdyVbbc ysZ6N7aMA5aIEx1eH8h5PnySsvb+XjKzG2mJLH/VKMvIH4U9biGFKW/c2ZLvR0KX/RLY 6EcA== 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 :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=/3m6gBMij6Ax7PcQaOILDRRx86A/6McrrYe3eb+j60U=; b=FIdiVgtuiORwqA4H1EEdUgjLwja4M0Rg6XWNelCC2Xzu3V1Se2Q9X3eOWlWal0PEZJ 5Cj3uiri2SBhtgCTD3HLNHIUIrUDG8JZdHjCrMOZdi8FFBlKaM0m8v6WKdPqQ6SziOMA yRsvvBiy7KhJU4N/CJ3AumhV3aLrqfnPKweSGWKlDD38xkqh9DRSFi6M4/hZ7faTwAlZ +r1YEqdUlI5FYa+1P7stubDo8VykiqjZW3Pm5XITa6O0Z3wXPgi3tBFYedlFPMYjc4e9 h1oka8mz/giRALxzK4ZccShoqwXCjP2y11V0xa6iNOzYnk9W/Cq/k5nME6uQdhZ1tl0H qQtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=gmiZT8rE; 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=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bt1-20020a0564020a4100b00501ea9c03cbsi553587edb.656.2023.04.08.05.26.51; Sat, 08 Apr 2023 05:27:19 -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=@protonmail.com header.s=protonmail3 header.b=gmiZT8rE; 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=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbjDHMZl (ORCPT + 99 others); Sat, 8 Apr 2023 08:25:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbjDHMZh (ORCPT ); Sat, 8 Apr 2023 08:25:37 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 184BCFF2B for ; Sat, 8 Apr 2023 05:25:35 -0700 (PDT) Date: Sat, 08 Apr 2023 12:25:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680956734; x=1681215934; bh=/3m6gBMij6Ax7PcQaOILDRRx86A/6McrrYe3eb+j60U=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=gmiZT8rEZ4T5b4rbZc4Llt40scAmwCy+zVC8Goi1+xfTTA9TQHB1/7NRbEODLxbNA ElegjFBERD91wYJVeZDAb4KnE58lNeyBvLG/lQ4Xs+7hMcKoUxbkz+CPDc/3LtBPhV DPRIA1MjRFy2kbfL+ISWZ0IKcBdFkoYMAA4lMiAl6pk0PagRKCCOX4P+0xCZG8rPqI /A9OKveMcD3pSPSNPv0rilXwCGcpG9Pr0wjs5rgu7Hvh0jY/trkFRh/FI8mM90jErr Uipnf+KhJnLI9hiVsHxtaq2Ky+ECE8HjwlaBxhWTF/VGA4tg5kEzsuoJ0vKnN/OyUx lTyx1YV3J2Idw== To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Alice Ryhl , Andreas Hindborg From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Benno Lossin , Andreas Hindborg , Alice Ryhl Subject: [PATCH v7 03/15] rust: sync: change error type of constructor functions Message-ID: <20230408122429.1103522-4-y86-dev@protonmail.com> In-Reply-To: <20230408122429.1103522-1-y86-dev@protonmail.com> References: <20230408122429.1103522-1-y86-dev@protonmail.com> Feedback-ID: 40624463:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 Change the error type of the constructors of `Arc` and `UniqueArc` to be `AllocError` instead of `Error`. This makes the API more clear as to what can go wrong when calling `try_new` or its variants. Signed-off-by: Benno Lossin Reviewed-by: Andreas Hindborg Reviewed-by: Alice Ryhl Reviewed-by: Gary Guo --- rust/kernel/sync/arc.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index f2f1c83d72ba..aa7135f0f238 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -17,11 +17,11 @@ use crate::{ bindings, - error::Result, types::{ForeignOwnable, Opaque}, }; use alloc::boxed::Box; use core::{ + alloc::AllocError, marker::{PhantomData, Unsize}, mem::{ManuallyDrop, MaybeUninit}, ops::{Deref, DerefMut}, @@ -149,7 +149,7 @@ unsafe impl Sync for Arc {} impl Arc { /// Constructs a new reference counted instance of `T`. - pub fn try_new(contents: T) -> Result { + pub fn try_new(contents: T) -> Result { // INVARIANT: The refcount is initialised to a non-zero value. let value =3D ArcInner { // SAFETY: There are no safety requirements for this FFI call. @@ -469,7 +469,7 @@ pub struct UniqueArc { impl UniqueArc { /// Tries to allocate a new [`UniqueArc`] instance. - pub fn try_new(value: T) -> Result { + pub fn try_new(value: T) -> Result { Ok(Self { // INVARIANT: The newly-created object has a ref-count of 1. inner: Arc::try_new(value)?, @@ -477,7 +477,7 @@ impl UniqueArc { } /// Tries to allocate a new [`UniqueArc`] instance whose contents are = not initialised yet. - pub fn try_new_uninit() -> Result>> { + pub fn try_new_uninit() -> Result>, AllocErro= r> { Ok(UniqueArc::> { // INVARIANT: The newly-created object has a ref-count of 1. inner: Arc::try_new(MaybeUninit::uninit())?, -- 2.39.2