Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13583717rwd; Sat, 24 Jun 2023 03:02:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XYVL1umh2xpHATkPbJw8gmoXRPXquUpePEIKbT/l8D+6g/jT+SLffuG6jZhpnAaqMEQ4K X-Received: by 2002:a05:6808:1390:b0:3a0:5772:e204 with SMTP id c16-20020a056808139000b003a05772e204mr10404198oiw.35.1687600924605; Sat, 24 Jun 2023 03:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687600924; cv=none; d=google.com; s=arc-20160816; b=DpZ797LSrCmK3UgWPgU+Uqw5hFHS8pLcsQ0umn/8ISji/rAdBFp8CnBiefPyy9L9RG kj/AAq9iU38KC6GIeya527MRN2ReJ+4jEMIlIMk43+2ojQqI73h7+B7bqqAizpN+V4nL Ar6ENkquR+4UhnHH2dBbhb8z14idlhTei+2+oYbSyupos/gpfJivAcsZG62PijzOTHia rcLyu9cRkDLPI5YDol0jRR1QpDxoj9EGt7DSlYkiRwHW4kJT5Y1eRzQotQd8B6lTqi0O yvXE+heX5VZZlzacZ3PlEEweSOh95HLvtbPpqZ+qAR2YV+gxJwAehz5lJh2sh7B1xMd5 5Dow== 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=MwlsAZeth2fh5s/kKCjOwcaQoR9NfdiNJqcnIsJP+QU=; fh=MjAOSe9N0TSmaKf+f9PeCP42XQuaAqCEgZCvUulmBUE=; b=lsWiZ2+U1Gj9lG/c6Oy3tdlWW/cH54mkoYdoUn3MR8gxiyQiHU/mpcJXc/+C6BOQ4l OZNM/d2qcOsNrKt4hGVRHcE8B2pgdEmd2n9R+doob+goJgdXDuvE3twWB4zPEVAsLRU6 H7WEr09XwTDrdEENW13kQQ1duHpHKXr0DhhQqNK+AtN01mv42ZNqk3Ka35Ys/LIWjK2X W2iqR3YTIHOZh7fbmaMcPSVochMCZTS+OAe5CYDJn/xkVcMy2KHgixpbtbTC5lmq3dpF 8GxfxeYfjU9G799oHEjoIFtM5BMLEZWCpr74wARkYc1TK2pcftsuD2Ta5Ys+pGZWgZCF m5PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=xkiqz2ubxjcrjarzt6h2fs2eda.protonmail header.b=RX1QAFc2; 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 r1-20020a170902be0100b001ae4c933bd4si948363pls.446.2023.06.24.03.01.46; Sat, 24 Jun 2023 03:02:04 -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=xkiqz2ubxjcrjarzt6h2fs2eda.protonmail header.b=RX1QAFc2; 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 S233017AbjFXJZu (ORCPT + 99 others); Sat, 24 Jun 2023 05:25:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232713AbjFXJZk (ORCPT ); Sat, 24 Jun 2023 05:25:40 -0400 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCEDB1FF0 for ; Sat, 24 Jun 2023 02:25:28 -0700 (PDT) Date: Sat, 24 Jun 2023 09:25:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=xkiqz2ubxjcrjarzt6h2fs2eda.protonmail; t=1687598726; x=1687857926; bh=MwlsAZeth2fh5s/kKCjOwcaQoR9NfdiNJqcnIsJP+QU=; 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=RX1QAFc2D7lJnNB8YIGMjffGX2FEKkrq6fmEfZflSEwkkwMLXzhsXN8ZLqMJFL9oW eaHYEK9ECgnIrEKj2hNjevL6+hEB1EsPWMmOxWnQQQE6XF/MEg/tpFrFaAMHfdB3ST YJhWTH9QJVe7q8dh8ykOd37SmZ6Za20e/jR7O8ztupEyl9TvSTMWqWr5+w7pB4Rd4h 8shd5T+lOMdD3IVD+VzW+zQ18TluwVoBqC8G9mZq4EtC2pMhy6AueT+OcOFRd04TW9 fpMkLLW3wmqrHR0wVHlpFOxMqX0pnYLjz0S0aR4lf7FsUsMOFju/QgLG68H3psY5b6 MVGAuvLNTqwuw== To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor From: Benno Lossin Cc: Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH 4/7] rust: init: wrap type checking struct initializers in a closure Message-ID: <20230624092330.157338-4-benno.lossin@proton.me> In-Reply-To: <20230624092330.157338-1-benno.lossin@proton.me> References: <20230624092330.157338-1-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 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 fields h= ave been mentioned exactly // once, this struct initializer will still be type-ch= ecked and complain with a // very natural error message if a field is forgotten/= mentioned more than once. - #[allow(unreachable_code, clippy::diverging_sub_expres= sion)] + #[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(), + ); + })(); } } Ok(__InitOk) -- 2.41.0