From patchwork Fri Mar 31 21:52:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y86-dev X-Patchwork-Id: 77994 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp862880vqo; Fri, 31 Mar 2023 14:58:40 -0700 (PDT) X-Google-Smtp-Source: AKy350Y+LeENFy9aVQ2BGMJI2fyZf+qemaL1eqDJ4Blur4ObtYX3M9ZHl8q3GFxOWs0KTYzdzhla X-Received: by 2002:aa7:9e0b:0:b0:62d:b7ad:8071 with SMTP id y11-20020aa79e0b000000b0062db7ad8071mr10443734pfq.15.1680299920460; Fri, 31 Mar 2023 14:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680299920; cv=none; d=google.com; s=arc-20160816; b=h6WM/69v4rtRekUfUZWf0jddL6liX1B0f1vgVa+GphDi/prlow3g/ym2KUDZkKGQ1M KvstmoQ60v5tazS2kdkMyQRK/nHkLxVrp61R1dQetRWUWyGE1S4K/15tn48rKlQWXVEA LdpDYurmTpekNwtYGsE0Pz4y/DfvyrtZvcjyYfrr+5NpN+abtz6hAfTGV0g+o7qTnMjZ gV9dJGtFuFxtNdQVg9jrK8rNXjzbF1VJm+e9xOdAVFpgFxDkuBVXJe8sealU2hnrfirD 2OgiDRDmTNjUR5xeexuDxHE1KSKqqq3yMgH5jZykVeU1zaPKogoqEK8VlNY34HC3Jqyd wN9A== 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=cIYxRs7yWpZ2jDriBGlcgcMewm6UvtEXri4X8Q7xEW0=; b=VavJ2RBNK7t75kQ5FXZ6DNNieNF7MGp3pmerI/ivH/eX2+hU1cOMsIkdbxc3NbGov6 xKft9F4130R1mAv4/752eIxJnNOyRzEsQWr6BBLeCrKjESSbz8Cgq9HL9OiH567NKHA1 dJ5eBmwC31vzSFATA2rrEKmCOdE1nmeYpZohtdaaXTUUBZu/LVaVz2pm0qFO4EXNNcAP Pxg0/Ds9uZfvAv9eve/BeF3V2Ib0C7AivVMMNCl/hf9y/MHE1dzk8A+YAXYnsaNQeK5K jEgzKP1CW00q5+K8vBVhDQ5/WjCCq7td1AhfiM3GeG6yx9TfLuaR0opJzRR9dSeTjS1l +ogw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=otNFDXXl; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t185-20020a635fc2000000b004fc21da0340si3506974pgb.129.2023.03.31.14.58.28; Fri, 31 Mar 2023 14:58:40 -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=otNFDXXl; 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 S233280AbjCaVxf (ORCPT + 99 others); Fri, 31 Mar 2023 17:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233169AbjCaVxZ (ORCPT ); Fri, 31 Mar 2023 17:53:25 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C55EC24AD6 for ; Fri, 31 Mar 2023 14:52:53 -0700 (PDT) Date: Fri, 31 Mar 2023 21:52:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680299544; x=1680558744; bh=cIYxRs7yWpZ2jDriBGlcgcMewm6UvtEXri4X8Q7xEW0=; 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=otNFDXXlhG/gIl3RnMg0DdR5n16yctHA1VzqcPrlB7o+CsGPpwgavkyaYyKarynGQ 6MP0mgMTeMSckx2GtHfTjFWSPIVuDj1lt1Xvbpes7Qa4GMet7B6BARbVJyMaOqH9Cg E+3shMdvvKd5ark4ZiS65dcSyxMsgq4T8IkY4nNuA9oCDq+fAj4gKeJG72FAQito86 DRHbH1ZNLfrGnOBxum0t5Vk8Ziscs12OIlBBOuxnAbWNq+E0D9YmPfIMpp4f+8KGtZ YaGk0KGSrDjmqQ/MEouXNEeI/nLhkL9KN2aPUnB6JMTKhL3Hxb3hM5nOBgt17arcgl kf8jjfDp6QbGg== To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Alice Ryhl From: y86-dev@protonmail.com Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Benno Lossin , Andreas Hindborg , Alice Ryhl Subject: [PATCH v4 03/15] rust: sync: change error type of constructor functions Message-ID: <20230331215053.585759-4-y86-dev@protonmail.com> In-Reply-To: <20230331215053.585759-1-y86-dev@protonmail.com> References: <20230331215053.585759-1-y86-dev@protonmail.com> Feedback-ID: 40624463:user:proton MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761922169706307379?= X-GMAIL-MSGID: =?utf-8?q?1761922169706307379?= From: Benno Lossin 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 Cc: Gary Guo Cc: Andreas Hindborg Cc: Alice Ryhl Reviewed-by: Andreas Hindborg --- rust/kernel/sync/arc.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.39.2 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 = 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>, AllocError> { Ok(UniqueArc::> { // INVARIANT: The newly-created object has a ref-count of 1. inner: Arc::try_new(MaybeUninit::uninit())?,