Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp14207295rwd; Sat, 24 Jun 2023 14:35:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5e8MZC5utfPvZmu4o7casnoQskPGzuGzdRvmB3g+QCdD4MXT2YvMaBHfq/Ru4C2dtYIvwu X-Received: by 2002:a17:902:b208:b0:1b0:4205:8501 with SMTP id t8-20020a170902b20800b001b042058501mr2630866plr.6.1687642529765; Sat, 24 Jun 2023 14:35:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687642529; cv=none; d=google.com; s=arc-20160816; b=CJzXv1qgfasc4J0u2ZgQxLbGBRdRe7pUrT5txLKhruLjWTd4H/TAA9upCoVfyR3gRK B/rRmnpDAr9A8Etr4CzHAPc8NwK5vJhjU+zkbReyZkLxpmGPXkUtIlW/r65B8xXj1gQW e+w+euJquyQF4EhFGp4o51QbFhcjJIHKNK2/GZ9IIBRoaEqcF8nW8BPdsbAZoB268AyO 4FCg4u2yQjYexsnPk2OfuUcEY2iNJtc5tHUBauDJGVWFvLjIoogWcPkqcPWFp+CIXE3B 7Y6Cnc37dwDQfw/101w721AMELLJyCFlq1NBjQ4jjTn9zKChmYQzkjI+DzTLL5i96Tmn su0Q== 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=+s2qFVdzSz1dpYq79TE2KMsy1jB2F75QErlkZyaVuak=; fh=jke91CklCuKu4Rkg1EiG0M1ovo/+g6epdlDRlNcakVU=; b=vA8dfuQGYA0D1Nq7wXx0IvEX2SzjSX+HIuCQzuK3i4BPUJFQ7dtPRkRIULOUuhzjQj vc8UL0xd3/4NmVEYvdOxtpbkYPshFNA1ta5AooGcTucix0u+JeZmu1LLYmDrHRVQYAup CnIiARk6StP0eIMBsRho0DCRr35xDCk5CAySLz6nsNqEtscbB7e2ushktV8Ui7baVYxz PGfdYm9JQHybGSh+nwHL8lXRSe6UCHCOijrE2OCpuStF9janlP4h3sMQntcYimX02L7k M53IyQokP8tq3GgcL6ZnTOC6gDQo0TBFw+/qm+Owm2/tz39+maQMgsEI1+qeudPsmrHY nwJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=Ig2IeD3a; 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=proton.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a17090322c900b001b697cc43ffsi2075119plg.433.2023.06.24.14.35.08; Sat, 24 Jun 2023 14:35:29 -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=@proton.me header.s=protonmail header.b=Ig2IeD3a; 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=proton.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229611AbjFXVFn (ORCPT + 99 others); Sat, 24 Jun 2023 17:05:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjFXVFm (ORCPT ); Sat, 24 Jun 2023 17:05:42 -0400 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87FA9171A for ; Sat, 24 Jun 2023 14:05:36 -0700 (PDT) Date: Sat, 24 Jun 2023 21:05:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1687640733; x=1687899933; bh=+s2qFVdzSz1dpYq79TE2KMsy1jB2F75QErlkZyaVuak=; 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=Ig2IeD3atLhIkkOEdLwbcZrefkSYwpRAza/XJ8Zjwi7uQQgg5TxKoeg/QTY1oLqOX VZ4fU8tSo+C26sC++G1cQFInRO8rhBGnLSi+HlFq++l/1fvbtyUw5ffP4NnCuMj45+ 6+i12Yy9qwDXVtLAdp7ijVvJNpiDtt53cfZaO7m+YCLn3OpW/ymLZ7KDyTseGu2N68 axvv90ptAztRXM8R48NZ1FpMyXOg3onvAfccJBVLoKOQ6WXzrstHeDhjUuIQdKilTO 86XOEBOkcmNe41KuTR8VerYbOlhB56agJrcaRcPJb9tlM/+5y2ZHEFBHaG5cB0Ks33 V6npSjhBlx+9A== To: =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= From: Benno Lossin Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , Alice Ryhl , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH 4/7] rust: init: wrap type checking struct initializers in a closure Message-ID: In-Reply-To: References: <20230624092330.157338-1-benno.lossin@proton.me> <20230624092330.157338-4-benno.lossin@proton.me> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 6/24/23 17:03, Bj=C3=B6rn Roy Baron wrote: > On Saturday, June 24th, 2023 at 11:25, Benno Lossin wrote: >=20 >> In the implementation of the init macros there is a `if false` statement >> that type checks the initializer to ensure every field is initialized. >> Since the next patch has a stack variable to store the struct, the >> function might allocate too much memory on debug builds. Putting the >> struct into a closure ensures that even in debug builds no stack >> overflow error is caused. In release builds this was not a problem since >> the code was optimized away due to the `if false`. >> >> Signed-off-by: Benno Lossin >> --- >> rust/kernel/init/macros.rs | 18 +++++++++++------- >> 1 file changed, 11 insertions(+), 7 deletions(-) >> >> diff --git a/rust/kernel/init/macros.rs b/rust/kernel/init/macros.rs >> index df4281743175..1e0c4aca055a 100644 >> --- a/rust/kernel/init/macros.rs >> +++ b/rust/kernel/init/macros.rs >> @@ -1037,14 +1037,18 @@ macro_rules! __init_internal { >> // We use unreachable code to ensure that all fiel= ds have been mentioned exactly >> // once, this struct initializer will still be typ= e-checked and complain with a >> // very natural error message if a field is forgot= ten/mentioned more than once. >> - #[allow(unreachable_code, clippy::diverging_sub_exp= ression)] >> + #[allow(unreachable_code, >> + clippy::diverging_sub_expression, >> + clippy::redundant_closure_call)] >> if false { >> - $crate::__init_internal!(make_initializer: >> - @slot(slot), >> - @type_name($t), >> - @munch_fields($($fields)*,), >> - @acc(), >> - ); >> + (|| { >> + $crate::__init_internal!(make_initializer: >> + @slot(slot), >> + @type_name($t), >> + @munch_fields($($fields)*,), >> + @acc(), >> + ); >> + })(); >=20 > Is it necessary to call this closure? Typechecking of the closure should = happen even without calling it. You are right, I do not need to call it. Will fix. --=20 Cheers, Benno >=20 >> } >> } >> Ok(__InitOk) >> -- >> 2.41.0 >=20 > Cheers, > Bj=C3=B6rn