From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CC28606D811 for ; Sun, 8 Nov 2026 22:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=HikLY+ss; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=YrCyJnaP DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Unsubscribe-Post:List-Owner; bh=LQBAQbfZQGFM3F/QuBDQvfstaiiOX63graQg91Fp+AM=; b=HikLY+ss4nbuO7WvqhFKCe4lfF o3skqLrvt6MBF8qI+J6k3IZzHKUA+gn07JHocE891LoPpDZyiEZRI6Gd+cZhgJvPctmS7B2InOdkG X2qZ2Me3hArOVG7aChm3MEK+wUTGkmiU5V4+X/pZ+S4t1qknpdsWb6DhxXsTQMqF1L8UIqw5YhO/g 9zCRpOdLo1o+JeEcfv/g75EEhqn/IcAsbAqep0m+9OA6x72IHSW52+tVNPVEa0vySzsBhAOTGVN6r 6w4yTWA16SFui5NlLSE1bmDl54aUQChiPKfO+4pSFmbXYuWmqBRXuSBzdiqvcb+KuZUvj4KjblGj0 /yREvlWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xQBYB-0000000GpxH-14zc; Sun, 08 Nov 2026 22:39:47 +0000 Received: from mail-dl1-x1247.google.com ([2607:f8b0:4864:20::1247]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xQBY7-0000000Gpw3-3kxQ for linux-mtd@lists.infradead.org; Sun, 08 Nov 2026 22:39:45 +0000 Received: by mail-dl1-x1247.google.com with SMTP id a92af1059eb24-1b0d864826cso1320182c88.1 for ; Sun, 08 Nov 2026 14:39:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1794177582; x=1794782382; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AHLMqwM6/67Zcd/LOxQ2+hhUbtfPU/BOw3z2THUGUxg=; b=YrCyJnaPJXFRwVHFq6tSt+7toBAgeIE9kuh6Z826al3HCcTkku8FW3NLx4iqqjLwYj CMDJiTpTjw9ZI15CXs9V9aPhs08NucGIBN8rRjATj2276Dy+x/MI1/3Ecwlqvf4G/mvv ZGxqquT6B/0n7R+cBLwpRI05kPDNWPJZaa2HDBtd5rQ+uhxsEQcUY7ayDWggBnKZQEUJ IoQP+ZONOoapPcJ5E/1RG75Oszbd64cAz8IQ9bDgSqbcRbf3rg38T1RnLwbmMioBGTRa lCkNyE2KToiOJf3gbOqWa1HohAPsOmhUNZuKiDGp9j69ps4BWctgGw0CzpETHh8BjTRw GZHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794177582; x=1794782382; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AHLMqwM6/67Zcd/LOxQ2+hhUbtfPU/BOw3z2THUGUxg=; b=DuETNGk//3rtgMQmQI8Z63DO5TiH9zhvy9oHmaxm1w3q6HUu+2ykHc2UDCUb7u4XFY RB1nnB/REmMLrgyrQ1R7Sb4J96BBQR8+aD2T1qR3g5j1rF49hyqBf5jbmaOb9y6lMxUK MxaXK52Q0Gfhj4ppDUXdO3G1CZaK+tny4rT1RUKbX45+Lu/mPs7MnNrKRATA1ZRw0Nyc RpAl/lcR1ky2l3EJ7FD7AHhXa0rDWG8ZkU37Ek8KLC1llJPcWxwErihehwE0JWYni3nk g7UUni9wW2ryDtPDOmlFyHoxyvAwXP5SWO7Z7cghGpAbCtyosQhCmMVxHTUjk3fO1tdQ dOxw== X-Forwarded-Encrypted: i=1; AL+hErGwxVHM+u6V8uRzTOap2JPl8FvLh1f9+MO/EFehca/Se6k57S+rsFcKgGfSkek7fmd2qQCtSG6a9DQ=@lists.infradead.org X-Gm-Message-State: APuU4Z/UkK72K9jzr0hNxa0/urk1yeDvTwdBcA06wSZxxfgy67Bp09xS UZXArBoL7W01dfX92IY0tAL84aexaIkzuVR6dih3mNcu/O+PSEAzo68EcvbzNgogcw4beizEhTb q1Ghgvwnwag== X-Received: from dlbox21.prod.google.com ([2002:a05:7022:1215:b0:1ab:fb55:f657]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:b884:b0:1b2:695b:79f0 with SMTP id a92af1059eb24-1b39fef03f3mr3576923c88.32.1794177581955; Sun, 08 Nov 2026 14:39:41 -0800 (PST) Date: Sun, 8 Nov 2026 14:39:05 -0800 In-Reply-To: <20261108223913.3624571-1-irogers@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261108223913.3624571-1-irogers@google.com> X-Mailer: git-send-email 2.56.0.455.g6c5a503b38-goog Message-ID: <20261108223913.3624571-2-irogers@google.com> Subject: [PATCH v3 1/9] Compiler Attributes: Add __must_init macro From: Ian Rogers To: Danilo Krummrich , Greg Kroah-Hartman , Kees Cook , Miguel Ojeda , "Rafael J . Wysocki" Cc: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Nayna Jain , Srish Srinivasan , Mimi Zohar , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Nathan Chancellor , Nick Desaulniers , Viresh Kumar , Zhongqiu Han , Alexander Aring , Felix Kuehling , "=?UTF-8?q?Christian=20K=C3=B6nig?=" , Zhihao Cheng , Sumanth Korikkar , Bill Wendling , Justin Stitt , driver-core@lists.linux.dev, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-sh@vger.kernel.org, linux-s390@vger.kernel.org, gfs2@lists.linux.dev, xen-devel@lists.xenproject.org, linux-mtd@lists.infradead.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261108_143943_940120_A5CA9CBE X-CRM114-Status: GOOD ( 12.85 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" X-Spam-Status: No, score=-21.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Clang supports the 'require_explicit_initialization' attribute on struct fields to indicate that a field must be initialized explicitly by the user when the object is constructed. When an aggregate initializer or uninitialized variable omits an annotated field, Clang emits a -Wuninitialized-explicit-init warning (enabled by default). Add the __must_init macro to include/linux/compiler_attributes.h (which is included by include/linux/compiler_types.h and include/linux/compiler.h) so kernel structs with error-prone initialization (such as mandatory callbacks or cleanup handlers) can enforce explicit initialization at compile time, as discussed at the Linux Plumbers Conference. The shorter __must_init spelling, rather than the attribute's full name, keeps annotated struct members readable and was suggested by Greg Kroah-Hartman. Note that Clang versions prior to the fix for https://github.com/llvm/llvm-project/issues/232483 do not diagnose file-scope objects declared without any initializer (initializers at file scope that omit the field are diagnosed). Also teach Sphinx (Documentation/conf.py), kernel-doc (tools/lib/python/kdoc/xforms_lists.py), and checkpatch.pl about the new attribute macro. Link: https://lpc.events/event/20/contributions/2392/ Link: https://lore.kernel.org/lkml/2026101532-fantastic-deafness-e04c@gregkh/ Acked-by: Miguel Ojeda Reviewed-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Acked-by: Greg Kroah-Hartman Reviewed-by: Kees Cook Signed-off-by: Ian Rogers --- Documentation/conf.py | 1 + include/linux/compiler_attributes.h | 12 ++++++++++++ scripts/checkpatch.pl | 1 + tools/lib/python/kdoc/xforms_lists.py | 1 + 4 files changed, 15 insertions(+) diff --git a/Documentation/conf.py b/Documentation/conf.py index 5ab26ce89daf..baaa4035258c 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -203,6 +203,7 @@ c_id_attributes = [ "__noreturn", "__packed", "__pure", + "__must_init", "__section", "__always_unused", "__maybe_unused", diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index 476c4c560d17..b9c0b56dd22e 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -322,6 +322,18 @@ */ #define __pure __attribute__((__pure__)) +/* + * Optional: not supported by gcc + * Optional: only supported since clang >= 20.0 + * + * clang: https://clang.llvm.org/docs/AttributeReference.html#require-explicit-initialization + */ +#if __has_attribute(__require_explicit_initialization__) +# define __must_init __attribute__((__require_explicit_initialization__)) +#else +# define __must_init +#endif + /* * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-section-function-attribute * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-section-variable-attribute diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b8b64f720191..6a091c45b1a1 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6888,6 +6888,7 @@ sub process { "noreturn" => "__noreturn", "packed" => "__packed", "pure" => "__pure", + "require_explicit_initialization" => "__must_init", "section" => "__section", "used" => "__used", "weak" => "__weak" diff --git a/tools/lib/python/kdoc/xforms_lists.py b/tools/lib/python/kdoc/xforms_lists.py index db23fb650ea8..42956b98aae3 100644 --- a/tools/lib/python/kdoc/xforms_lists.py +++ b/tools/lib/python/kdoc/xforms_lists.py @@ -36,6 +36,7 @@ class CTransforms: (CMatch("CRYPTO_MINALIGN_ATTR"), ""), (CMatch("__private"), ""), (CMatch("__rcu"), ""), + (CMatch("__must_init"), ""), (CMatch("____cacheline_aligned_in_smp"), ""), (CMatch("____cacheline_aligned"), ""), (CMatch("__cacheline_group_(?:begin|end)"), ""), -- 2.56.0.455.g6c5a503b38-goog ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/