Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2312600rwl; Thu, 30 Mar 2023 08:40:30 -0700 (PDT) X-Google-Smtp-Source: AKy350abqkFhnIK0g9UhRI29jJadKNfxwMHTkbcTN4Z7K9V5hydyuShv3YqEl86TPimoFF57yMBQ X-Received: by 2002:a17:906:297:b0:932:170:e07b with SMTP id 23-20020a170906029700b009320170e07bmr1976668ejf.7.1680190830573; Thu, 30 Mar 2023 08:40:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680190830; cv=none; d=google.com; s=arc-20160816; b=DEhcyacnx4BkGWyKXG4m6lDlRrnXj+E6wg0N616oJ31Vh4nfTQ30NpBKPELIcDRxxh SB4CM+r/bdKFG9YxUT/asJqMSOcM5YmdgqZyRKoYfZzf3t+LbehIxozkKEwgJ/UPzLII IM5DgSfNih89THV63ys7Cm20XeQZRG16xlPOUcc70zg9ZbSj3Vjg+Fy0YEwG/Y2LQYCe U9LlR6D/ueof9yz8xRf4kHI2IOKzbtefI//H63z3JzTEb4O/HOVoRrsECqOfreNKkUjH QyTqZDTQ2fFXHWqik/rGMyEVL7pKEnNu3ccSYmq/AQpalQP1QnbBEspuNvyHaDA6Hl2D LjCQ== 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=78dr7bQ+n1CF5BDMkt72hk6Mu6tYllNVNQReiUB0IjI=; b=ZT8Q/D3aOyxEvoTbNDZTJ3PEa1ZOZY7g1+YbeQ5+RtsHj2cDTbw2L2/+blJmm09mAs UU2lnhy/qZY1VIrqJUoibKt29ri5VN98BKyYBFbkF8Px2Qk75ErDKH14q0Tw45TSH82A rSv8GgjG0SQ/nvUmZlJQGMD11r7hLegK/bnwPNQ+iMrYFMGsSEECnDMnGVaogYP85IFk 05McUpXqF5NI/uuZYDyW7hL/QUF/PrpSxg3wrF0vsIUTM0mu/BWxp6zyP5+sbSFrj1iF xbmULYx6FW4YfbTrIkY/SOw/4h/MksW1HldZ12y6GaB2FGfeXOE6Sz/0V2nkgXjNI1y4 0A8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=JGzM4eUk; 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 qw1-20020a1709066a0100b00932a6c68268si19957759ejc.806.2023.03.30.08.39.44; Thu, 30 Mar 2023 08:40:30 -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=JGzM4eUk; 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 S232871AbjC3Pj2 (ORCPT + 99 others); Thu, 30 Mar 2023 11:39:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233153AbjC3Pj0 (ORCPT ); Thu, 30 Mar 2023 11:39:26 -0400 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49EF883E7 for ; Thu, 30 Mar 2023 08:39:07 -0700 (PDT) Date: Thu, 30 Mar 2023 15:38:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680190744; x=1680449944; bh=78dr7bQ+n1CF5BDMkt72hk6Mu6tYllNVNQReiUB0IjI=; 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=JGzM4eUkMb2oKzbtBusmrJvRD2L8QnkKxZtArCmw0bGeVW/gzfBagKYDIOFvMXgTX zzqdOjM5qc/ZysddzD8REBjEkoimegRnJnqNn3MuBjtOiWcX+yicS69x2D02Z8RXfW k1woEYcHMUsdNKJrhyv4gF4ZWKeibAh0kBlHugsy7p2OcwtlXSVx2TYZI6YQ94xu0u OcmOPeXjPvGFba00XAH6u4xUYZA2wzCHw8JpcvJgYB9O8POjE3tVVaXkTAUO7Utbv/ p9+CijLBTzJRZ/THBoUMPfnzRsmj2P/qrp+V+Rc0v1fQwEzYbgjvFnXGO3UYpNd/9q 9xBbAy0ia7lLA== To: Alice Ryhl From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= Subject: Re: [PATCH v3 05/13] rust: init: add initialization macros Message-ID: <226e4772-0e10-6593-7cfe-e1e290a0216c@protonmail.com> In-Reply-To: References: <20230329223239.138757-1-y86-dev@protonmail.com> <20230329223239.138757-6-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 On 30.03.23 16:21, Alice Ryhl wrote: > On 3/30/23 00:33, y86-dev@protonmail.com wrote: >> From: Benno Lossin >> >> Add the following initializer macros: >> - `#[pin_data]` to annotate structurally pinned fields of structs, >> needed for `pin_init!` and `try_pin_init!` to select the correct >> initializer of fields. >> - `pin_init!` create a pin-initializer for a struct with the >> `Infallible` error type. >> - `try_pin_init!` create a pin-initializer for a struct with a custom >> error type (`kernel::error::Error` is the default). >> - `init!` create an in-place-initializer for a struct with the >> `Infallible` error type. >> - `try_init!` create an in-place-initializer for a struct with a custom >> error type (`kernel::error::Error` is the default). >> >> Also add their needed internal helper traits and structs. >> >> Co-developed-by: Gary Guo >> Signed-off-by: Gary Guo >> Signed-off-by: Benno Lossin > > Reviewed-by: Alice Ryhl > >> +/// ```rust >> +/// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] >> +/// # use kernel::{init, pin_init, prelude::*, init::*}; >> +/// # use core::pin::Pin; >> +/// # #[pin_data] >> +/// # struct Foo { >> +/// # a: usize, >> +/// # b: Bar, >> +/// # } >> +/// # #[pin_data] >> +/// # struct Bar { >> +/// # x: u32, >> +/// # } >> +/// >> +/// impl Foo { >> +/// fn new() -> impl PinInit { > > I would remove the empty line above `impl Foo` so that the example > doesn't start with an empty line when rendered. Sure. > >> +/// # Syntax >> +/// >> +/// As already mentioned in the examples above, inside of `pin_init!` a= `struct` initializer with >> +/// the following modifications is expected: >> +/// - Fields that you want to initialize in-place have to use `<-` inst= ead of `:`. >> +/// - In front of the initializer you can write `&this in` to have acce= ss to a [`NonNull`] >> +/// pointer named `this` inside of the initializer. >> +/// >> +/// For instance: >> +/// >> +/// ```rust >> +/// # use kernel::pin_init; >> +/// # use macros::pin_data; >> +/// # use core::{ptr::addr_of_mut, marker::PhantomPinned}; >> +/// #[pin_data] >> +/// struct Buf { >> +/// ptr: *mut u8, > > I'd add a comment on the `ptr` field saying "points at `buf`". Sure. > >> +/// impl BigBuf { >> +/// fn new() -> impl PinInit { >> +/// try_pin_init!(Self { >> +/// big: { >> +/// let zero =3D Box::try_new_zeroed()?; >> +/// unsafe { zero.assume_init() } >> +/// }, > > Is there a reason for not using `Box::init(kernel::init::zeroed())?` here= ? No, this was probably designed prior to `zeroed`, will change it. -- Cheers, Benno