Received: by 2002:a05:6512:2355:0:0:0:0 with SMTP id p21csp206196lfu; Wed, 30 Mar 2022 20:56:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKW8ZsyMPk03Vcc23Y1ANYO1/SiV0KfzVwvTfVqSntaQ1lo38bbNFZoaoiZ6kIY3LBbcI2 X-Received: by 2002:a05:6a00:98e:b0:4fb:1162:b2a5 with SMTP id u14-20020a056a00098e00b004fb1162b2a5mr3187553pfg.12.1648698993699; Wed, 30 Mar 2022 20:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648698993; cv=none; d=google.com; s=arc-20160816; b=JOt7dynDRzHifgxefVRbuNYGQeFiOVd4ToBDCH7fgKnpKdb9ddreBIyr3490VTPchs jloxUAT0NdeeMwRXVREe90IpWUcFjjlesi6cKFFPjIzql/7kbt7KXEgYAp+mhjHeI0EF uwXw813A/s+yNaZ10WVlOXDsXgS/98ofCqTeC/c8g02NXAUlf3wssFiOoq5lHXXl7rDw T+2WGI/F2bDKN68bdvOI0oJw9esjZVWxmppiinjt+0tgRotbc+Z54/Jz+Ea8JaX9MBYu fCf/IwaT6pfcT9tc5HQnRZrr8skQT23vd4Nvdh+YKZ45ysKrQbLWDdmCM/l9n5IUPLzO ST8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QpqqAPwXMV7VT51UYWKaBPgknrObFDs8Es/GevAG7kU=; b=Ucomm6DXSeTnVahJZKXFJ4JZT9A6vBDvTjVB+ggv2O6zpTenKHHoH6Z2NUrf9rMfl3 +I4o3AhgpntEaCGfeU0Kv2F4gwGp64g3hwoqOglAbaBjmZM9+5W9Nb1nMR/zl9irn4Mh UwKHMbJ2oxyRXgiyJWOMJRkXgZDida7CY/YWfXSaYngVYCARkV7JvG7ET514XzL3f+zR 7SVQRPLHXyTezcgbGPfKGjPB098gXxBicJxPFipnZR1DNi/wcO6EXPg8sLA4rYlbSAj2 tVgaZdTD6ohS/jr8NqyWk+lHohjRPWdPngJUEYBUA/zUvdToUiqkK26jDRQMtuMhHavN HQxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VcDxO8qv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l18-20020a170903245200b00153b2d16639si3142996pls.577.2022.03.30.20.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 20:56:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VcDxO8qv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8BE8016C094; Wed, 30 Mar 2022 20:08:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240107AbiC2XYY (ORCPT + 99 others); Tue, 29 Mar 2022 19:24:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236635AbiC2XYW (ORCPT ); Tue, 29 Mar 2022 19:24:22 -0400 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 444B3185452; Tue, 29 Mar 2022 16:22:37 -0700 (PDT) Received: by mail-oi1-x22c.google.com with SMTP id w127so20516732oig.10; Tue, 29 Mar 2022 16:22:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QpqqAPwXMV7VT51UYWKaBPgknrObFDs8Es/GevAG7kU=; b=VcDxO8qvQWw5GbBfG73UfmNJXuF5cW5bBU2Mxd1Ye0e/wAvQp0V/4uLuI9mi4aFOvi 8rLVNAbCFXzaez+GOUvJnkbmxtauuKUojy0PS5ee1RKtoNiigjLsy6sZkBcJmlhp06gz LspK2FG0NrGx7KMkZW+F2leRMEOMmE+yor5d+5hVYOG/5B4IjN5iItf4xKBh8aSKtfMd XaL5FtVJ7KOHhye0b0JeiMuBmswZjq1bh5O/25ODjo1cWhQCtI99+462rOWTj3H5zNBT V2y2a/6TVQwwdVjfRXPfdrVXKpUWZ0/092pGazQtTP0t7MCCAZ07srzkIYxxNstGGMVo X07Q== 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=QpqqAPwXMV7VT51UYWKaBPgknrObFDs8Es/GevAG7kU=; b=IRnvPvNj+iNxB+MyVdlIvTreGkpC68edPLFquqQQtaD++U2Hb8vKIMNCIdzIEDbqDj Q/uylxszRtXvItvKuILO07bJ/N0UE3PfXZU+gRotonXCO/ZzdDrQTGOG52PETto3buM2 pQUzhZLw3flZZqrVbry4sby1WBbfKqR7U8F/FyzK9nHDZk2U2Q1W1mr8vRp4AyhffFtl 99x/DprRdFYwj8dfQoEfIH84Qh856nop7QKaiSv/ypBn33GryvRsuTg3upM5o+7x+jOP WtgDlrEJfia0qUqwx+F6vl4Wvj+7AXWpauCXEmziePoX0KmKY+gdHNN4Igc7K5L63S2g WkAw== X-Gm-Message-State: AOAM532c/L/teu7f+HlFx17wS8N+pnPYg/W2WwII1k8W1jwGmJkTetzp EhYPMcnBiDw3JWqRejtS9k8GpuT9/76ZNA== X-Received: by 2002:a05:6808:140b:b0:2ec:f41e:a4c6 with SMTP id w11-20020a056808140b00b002ecf41ea4c6mr674496oiv.17.1648596156540; Tue, 29 Mar 2022 16:22:36 -0700 (PDT) Received: from marsc.168.1.7 ([2804:d57:1503:f300:282c:2283:f732:e1c7]) by smtp.gmail.com with ESMTPSA id u22-20020a4ae696000000b0032158ab4ce9sm9231964oot.26.2022.03.29.16.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 16:22:36 -0700 (PDT) Date: Tue, 29 Mar 2022 20:22:30 -0300 From: Marcelo Schmitt To: corbet@lwn.net, mchehab+huawei@kernel.org, dlatypov@google.com, davidgow@google.com Cc: linux-doc@vger.kernel.org, linux-sparse@vger.kernel.org, cocci@inria.fr, smatch@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, dan.carpenter@oracle.com, julia.lawall@inria.fr Subject: [PATCH v2 1/2] Documentation: dev-tools: Add a section for static analysis tools Message-ID: <9b8233e89227617a2cb47d85c654603c6583323d.1648593132.git.marcelo.schmitt1@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 Complement the Kernel Testing Guide documentation page by adding a section about static analysis tools. Signed-off-by: Marcelo Schmitt Acked-by: Daniel Latypov Acked-by: Dan Carpenter Reviewed-by: David Gow Reviewed-by: Shuah Khan --- Change log: - Brought generic tool characteristics to the intro paragraph - Made explicit that these tools run at compile time - Added a note of caution about false positives - Updated Coccinelle info to make it sound better and be more skimmable Documentation/dev-tools/testing-overview.rst | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Documentation/dev-tools/testing-overview.rst b/Documentation/dev-tools/testing-overview.rst index 65feb81edb14..b5e02dd3fd94 100644 --- a/Documentation/dev-tools/testing-overview.rst +++ b/Documentation/dev-tools/testing-overview.rst @@ -115,3 +115,34 @@ that none of these errors are occurring during the test. Some of these tools integrate with KUnit or kselftest and will automatically fail tests if an issue is detected. +Static Analysis Tools +===================== + +In addition to testing a running kernel, one can also analyze kernel source code +directly (**at compile time**) using **static analysis** tools. The tools +commonly used in the kernel allow one to inspect the whole source tree or just +specific files within it. They make it easier to detect and fix problems during +the development process. + +Sparse can help test the kernel by performing type-checking, lock checking, +value range checking, in addition to reporting various errors and warnings while +examining the code. See the Documentation/dev-tools/sparse.rst documentation +page for details on how to use it. + +Smatch extends Sparse and provides additional checks for programming logic +mistakes such as missing breaks in switch statements, unused return values on +error checking, forgetting to set an error code in the return of an error path, +etc. Smatch also has tests against more serious issues such as integer +overflows, null pointer dereferences, and memory leaks. See the project page at +http://smatch.sourceforge.net/. + +Coccinelle is another static analyzer at our disposal. Coccinelle is often used +to aid refactoring and collateral evolution of source code, but it can also help +to avoid certain bugs that occur in common code patterns. The types of tests +available include API tests, tests for correct usage of kernel iterators, checks +for the soundness of free operations, analysis of locking behavior, and further +tests known to help keep consistent kernel usage. See the +Documentation/dev-tools/coccinelle.rst documentation page for details. + +Beware, though, that static analysis tools suffer from **false positives**. +Errors and warns need to be evaluated carefully before attempting to fix them. -- 2.35.1