From patchwork Mon Apr 3 15:44:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y86-dev X-Patchwork-Id: 78613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2416160vqo; Mon, 3 Apr 2023 09:10:24 -0700 (PDT) X-Google-Smtp-Source: AK7set8Wq8PuODBQ6f1OWtOT1tDnVdzlFQqGSPgDPjbR6YR1HP9MF1kE7lToiS9i73uKr7BwyIDJ X-Received: by 2002:a05:6a20:38a5:b0:d9:fc6c:51fa with SMTP id n37-20020a056a2038a500b000d9fc6c51famr26574497pzf.32.1680538223942; Mon, 03 Apr 2023 09:10:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680538223; cv=none; d=google.com; s=arc-20160816; b=jmqXnmMfFDPvVyFLQ9Rqib4ATIyfQIlkMdkbkp9uW9KAykOhfUXfgMIBJsDEcvADHP rWyFuSOtTVoKsWqiTUtnYuHZzg/B5rZPaupcoslZ9dCDYWEVxu1lBA2uvs8T/fkdOSC+ vApBRoi0lNAmmpVIgP2yn3mLnccGjTIJeDL2sj2GkVHTYALQB//2JusjtmlUbtiE0fU2 eKBwIwfnZUmiI43hOZQSADyV8pwLYn8ePecAWkTtumNkfUekfVkUAPJmUJ44cHUWm6Zp ZGXt6J1E8gxHBpzHjDvf2fR+OQQVtrJKJPofzKx9s1qquaaciZPEuDeINNL0a4dpB5ww 5laA== 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=NOtOxMB2O2qfeH9Un+9EFwj4vLjfj5tD+KDIQcfJKm8=; b=CLjTYFg8/wObKaZHCQcSImHeQNIvluwE2tlmfwiSu4crAVkqNSc//uK//D+ozWybFz fEaXHXyMXKqwMTj0HB08/n9rrOq7aXn6k6sd+UzvFZVfpzuKDSzN5sIlE1beH7CfRmYo ZVwNGM+X2IiYsoMO8nWzRvWArWfLbqxk0fVF+afcXyrybA4dn8EHyNBPX3wz2htFvmI2 rgfvWVpoe/a03tv6Bcbe7SqzaowqE1qRysltAFHT0qtxfGCZtvtaffpUSwnCbTIYERZ0 gqui95b+kjm3GlD4v0a0gO/F/lrjeML02PQ0bHkqnbs/UYhzV1WYhLjb/mH6CxVg8qfi 1G8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=Kc1mKsi1; 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 f10-20020a63de0a000000b00513f070aa08si2236754pgg.611.2023.04.03.09.10.10; Mon, 03 Apr 2023 09:10:23 -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=Kc1mKsi1; 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 S232988AbjDCPpm (ORCPT + 99 others); Mon, 3 Apr 2023 11:45:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232204AbjDCPpb (ORCPT ); Mon, 3 Apr 2023 11:45:31 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47FFD3A99; Mon, 3 Apr 2023 08:45:13 -0700 (PDT) Date: Mon, 03 Apr 2023 15:44:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680536711; x=1680795911; bh=NOtOxMB2O2qfeH9Un+9EFwj4vLjfj5tD+KDIQcfJKm8=; 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=Kc1mKsi1EvChhlr+Hwv9ESwI6XrDrz59+80MK5y+srICbJj3Iyqt3j9WKmqUy55cT 3ReN/JTZwA+EW11d4LmcW391LGo5uIetEYXEN8UKX3SPJOKKHTYwypvgEMOGHHt7Ap DfrqbMjuY5SRN6LXqPmGw6kk7Sj7qQaBX54KFAXarPhO2bE09bn6tCnh0OKJDN9g8P Ajvy1fqYT4xzYh4Hs2BjBlhpivyKAFzEw/agEE5MfJw2JLzzVXDIM8fB3hzTFS2dtr Ovp5RUvygyq+2DflraBsuTI3JxSzOeoBdS6Kx0RRk4ptf20y/vyOZ6ZaI8OkHAgf38 d8yaP6h8Wdnhw== To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Alice Ryhl 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 v5 03/15] rust: sync: change error type of constructor functions Message-ID: <20230403154422.168633-4-y86-dev@protonmail.com> In-Reply-To: <20230403154422.168633-1-y86-dev@protonmail.com> References: <20230403154422.168633-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?1762172048779681653?= X-GMAIL-MSGID: =?utf-8?q?1762172048779681653?= 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 Cc: Gary Guo Cc: Alice Ryhl Reviewed-by: Alice Ryhl Reviewed-by: Gary Guo --- 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())?,