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=unavailable 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 24630C433FE for ; Fri, 10 Sep 2021 20:47:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07EDD61208 for ; Fri, 10 Sep 2021 20:47:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233733AbhIJUsd (ORCPT ); Fri, 10 Sep 2021 16:48:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233384AbhIJUsb (ORCPT ); Fri, 10 Sep 2021 16:48:31 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B7D0C061574 for ; Fri, 10 Sep 2021 13:47:20 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id j10-20020a17090a94ca00b00181f17b7ef7so2353466pjw.2 for ; Fri, 10 Sep 2021 13:47:20 -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=4C+SQZKlJXAcD8a6vyozLJ3j9eeGALeTBT7JQXsqC72KT0wIBpuXYFQWgwL7FYbBIP 2yUoZ6/0pPk3C/Jbasruxbj8530odkofAkJpvh5p2NNjibY2hXJRhYgFvKWj3Yvz+czF ghDqbvJ6nh4hyGXlqmw4OYu47y+QynCJwW+Ir6es2uyqRqZNMqdULsxAjnKgpBkHrIAb HgtgEzhlut9vL8YZNoW4LHyhXBnxVj4x/qvyrSEnmkUsimOxzXkJH8UOrGOch4gHlcGN vfHdwqQcpDlHPYX9dAZHzNj++blrjMCMu7m8duxHrMh6vGAXeKh9obFNFZhcIwVyutu2 0LGA== X-Gm-Message-State: AOAM5310QMwgeNZcCh8SPErg+BRC2QBZLwmsnRzKnKtNEMAL+c7x/fK0 Oji4vsJoBHcp3nXqEDGTSn0bPw== 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: Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org 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