From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21BA6C433F5 for ; Fri, 10 Sep 2021 20:47:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C6CB561205 for ; Fri, 10 Sep 2021 20:47:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C6CB561205 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1CCC06B0071; Fri, 10 Sep 2021 16:47:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17C036B0072; Fri, 10 Sep 2021 16:47:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06BAB900002; Fri, 10 Sep 2021 16:47:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id EDB1B6B0071 for ; Fri, 10 Sep 2021 16:47:21 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A111F3A8CE for ; Fri, 10 Sep 2021 20:47:21 +0000 (UTC) X-FDA: 78572849082.09.02451BF Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf27.hostedemail.com (Postfix) with ESMTP id 3130F700009B for ; Fri, 10 Sep 2021 20:47:21 +0000 (UTC) Received: by mail-pl1-f173.google.com with SMTP id n4so1907306plh.9 for ; Fri, 10 Sep 2021 13:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jM+qEDzV8z1FXH3RUwoyikfs2oyeSaMBgU7hO9za93o=; b=aVnAxYC1ytnqQuDagnrkIpgfpb83mtjRmFAOfJM8/R6agWgAuQpC/dSzoHvWYCgyFa r9zclDc3g3HnZ6K3hyj/wzsjh/4AyIFvXs39HnMxyvtiXYNzgNDd7XsTLBRAZbZO7pOS aDmeAZSreE7W/dcCYImcFWQ/6Wq6oxEgsioXs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jM+qEDzV8z1FXH3RUwoyikfs2oyeSaMBgU7hO9za93o=; b=PI/sZT2+wDWtD8fx0dTLiJU6MWIR+m3XuJUCxT9bMpXfc22x64QXx/SN0RZZ1wQYFr HUqqkdYJHyGB7dTh0O5QDlWYTm2wgAHXOkudkZo5U+smdr9hbi2hxHTE/9QqLT93bgft lFBagKISoMiHyamxAnhxlbpfHZXq7JbJC6c55djhAZxsSijC8Z/SvegXcG2nWXck9Z3E sgH8Tzhj8fE5NQbI0ADUZZUn0APmNHmoImEL/PRgLwYQ6Kh+o9JWXUO/aOo7kZSz6A9V KJ07otXgGD/SkqQ2EoLHdLCrxFaIb6xPJWVsICLoSl0IWsa2h/6JGi2oq/RGpybleeqZ frbg== X-Gm-Message-State: AOAM530yym3I34sw7YzoR/1rSEMLvHzEgEUkvfBQ8TjeoR3qG/WS3Bo9 8qTo2BEcisDbG//fzl+wElzAgQ== X-Google-Smtp-Source: ABdhPJyHP5iWm8OLvlNsQWrl7F2u8MMOQt/OjdeAvIsG/mRKr4WRljqHsRafm6/Wd9c8LQOeRAiCtA== X-Received: by 2002:a17:90a:4b4d:: with SMTP id o13mr11395331pjl.236.1631306840093; Fri, 10 Sep 2021 13:47:20 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id j128sm5977624pfd.38.2021.09.10.13.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:47:19 -0700 (PDT) Date: Fri, 10 Sep 2021 13:47:18 -0700 From: Kees Cook To: Linus Torvalds Cc: Nick Desaulniers , Andrew Morton , apw@canonical.com, Christoph Lameter , Daniel Micay , Dennis Zhou , dwaipayanray1@gmail.com, Joonsoo Kim , Joe Perches , Linux-MM , Lukas Bulwahn , mm-commits@vger.kernel.org, Nathan Chancellor , Miguel Ojeda , Pekka Enberg , David Rientjes , Tejun Heo , Vlastimil Babka Subject: Re: [patch 9/9] mm/vmalloc: add __alloc_size attributes for better bounds checking Message-ID: <202109101341.1BA94A0F5@keescook> References: <20210909200948.090d4e213ca34b5ad1325a7e@linux-foundation.org> <20210910031046.G76dQvPhV%akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: z9838a998947gkx4b3tk13db3dy8rqbu Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=aVnAxYC1; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf27.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.173 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3130F700009B X-HE-Tag: 1631306841-684631 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Sep 10, 2021 at 01:16:00PM -0700, Linus Torvalds wrote: > So to a close approximation > > - "storage class" goes first, so "static inline" etc. > > - return type next (including attributes directly related to the > returned value - like "__must_check") > > - then function name and argument declaration > > - and finally the "function argument type attributes" at the end. I'm going to eventually forget this thread, so I want to get it into our coding style so I can find it again more easily. :) How does this look? diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst index 42969ab37b34..3c72f0232f02 100644 --- a/Documentation/process/coding-style.rst +++ b/Documentation/process/coding-style.rst @@ -487,6 +487,29 @@ because it is a simple way to add valuable information for the reader. Do not use the ``extern`` keyword with function prototypes as this makes lines longer and isn't strictly necessary. +.. code-block:: c + + static __always_inline __must_check void *action(enum magic value, + size_t size, u8 count, + char *buffer) + __alloc_size(2, 3) + { + ... + } + +When writing a function prototype, keep the order of elements regular. The +desired order is "storage class", "return type attributes", "return +type", name, arguments (as described earlier), followed by "function +argument attributes". In the ``action`` function example above, ``static +__always_inline`` is the "storage class" (even though ``__always_inline`` +is an attribute, it is treated like ``inline``). ``__must_check`` is +a "return type attribute" (describing ``void *``). ``void *`` is the +"return type". ``action`` is the function name, followed by the function +arguments. Finally ``__alloc_size(2,3)`` is an "function argument attribute", +describing things about the function arguments. Some attributes, like +``__malloc``, describe the behavior of the function more than they +describe the function return type, and are more appropriately included +in the "function argument attributes". 7) Centralized exiting of functions ----------------------------------- -- Kees Cook