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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB00CC4332F for ; Wed, 30 Mar 2022 08:04:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244064AbiC3IG2 (ORCPT ); Wed, 30 Mar 2022 04:06:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238594AbiC3IG0 (ORCPT ); Wed, 30 Mar 2022 04:06:26 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CFB99FE3; Wed, 30 Mar 2022 01:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=UxW2mD5WrICDvibAp5foCegbS/EQTtzvOwwvmmQ2hgk=; b=YcNRZzjsrXHrXNzg16ojqkJ8iqhLmsvXBJAxBShDwvZh0fnvAH4KQISA 3YwsV/SqmfC4w9S9UrSHmdFORW1S5lcqW0Ot4zMsN38fWtpwM7JtA8tK5 io94IeIb+7SFszSh+4lU6idrt9kaOhYBiuvGIkQLt6fmQoJJuEhwnrF8H E=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="5.90,222,1643670000"; d="scan'208";a="29029302" Received: from dt-lawall.paris.inria.fr ([128.93.67.65]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2022 10:04:35 +0200 Date: Wed, 30 Mar 2022 10:04:31 +0200 (CEST) From: Julia Lawall X-X-Sender: julia@hadrien To: Marcelo Schmitt cc: corbet@lwn.net, mchehab+huawei@kernel.org, dlatypov@google.com, davidgow@google.com, 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: Re: [PATCH v2 1/2] Documentation: dev-tools: Add a section for static analysis tools In-Reply-To: <9b8233e89227617a2cb47d85c654603c6583323d.1648593132.git.marcelo.schmitt1@gmail.com> Message-ID: References: <9b8233e89227617a2cb47d85c654603c6583323d.1648593132.git.marcelo.schmitt1@gmail.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Tue, 29 Mar 2022, Marcelo Schmitt wrote: > 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 Acked-by: Julia Lawall > --- > 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 > >