Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1523880pxk; Tue, 1 Sep 2020 00:19:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEPcMrTT5ogdCnpGtUWhQfUWnYI2RRUo4On/r8Ro9xpF34aLDLzX+EBbanopY+6CK9kdgi X-Received: by 2002:a17:906:a209:: with SMTP id r9mr296279ejy.413.1598944762235; Tue, 01 Sep 2020 00:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598944762; cv=none; d=google.com; s=arc-20160816; b=Zyij3pOAC8chR0+DSYenZjoXEDbWVYYTBdZO/7aV8JUdvrMwekwC5HDFxJXDgKlNTr 8GCm9kf4sI/Ci9zuCGBDHo3e/Y5bG7cLwh08OGl4pgw1MK289rmpaQnCFbkw0tmzzpOV q4nf8ZIUNioeiyMCG8xXgUbwbAECxfm4oulb/lUxAacl34shVtgyd65gyK0nlbN4tq+s RLA6/kx6md0MP5Ea08fgVYyevNiXn/EYpd1J8GSYXKaLcpGg+rH4gwwUgC+D8LySv+Pm HZUzF3KZUpyfJCIJrjuAcB5f8kfzFalkSyQyu+tWVn1zHL3vgy+pzvGNk47xIaTrmt6x jdnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Co9oqe1Y6OTWYaD/3lckLQ7GP6ZEbdv5SQNbrFyFhyg=; b=l6m0SBzoQc1znakSi1WvwZpgagWF7FOAJpVdJcyeVrindLTow2svR/MdgVCXOIWEbU BQDW+m5jbh64tj0BP/sQixspDQWX80oNj5GXuvRroD1HGP+BO9ELtdCwYyRhoAku5E3P mMHxWGRb+cGORy/eeo99/Pd43E3P+IzGSvF3yl4fMwxIuP7aapR9YacCjX9Jx/O4UbXG i/xMeUkOTK2xgrVqCS6gZal5UwAi/tp1Mkb8FxAMjcRFaa4eaZ96jNGDwJ0/VBeznT/h GBBl1c5G3RSsSdhTxz2aOkTVFokVhtbCFIav9qKow2M6XPQ/CNNd8eIh/ozM+1+dgk8F 0Y6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt21si223789ejc.664.2020.09.01.00.18.58; Tue, 01 Sep 2020 00:19:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726406AbgIAHPs (ORCPT + 99 others); Tue, 1 Sep 2020 03:15:48 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:46207 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726006AbgIAHPs (ORCPT ); Tue, 1 Sep 2020 03:15:48 -0400 Received: by mail-lf1-f67.google.com with SMTP id u27so153841lfm.13 for ; Tue, 01 Sep 2020 00:15:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Co9oqe1Y6OTWYaD/3lckLQ7GP6ZEbdv5SQNbrFyFhyg=; b=bHBLkAIj/shjSTJTJFtG1bZ0qV/uGEZtAipagrz3c1YSrkdWAGyGalIlLDVYm6QQWp i5iP17XmjS7SfRCFPBrBo3uxFd3AB2uqbd7XM6wIZH5zidvEoGf90d2C4EVJ5O5Pln9l Xp0WKlW3xoO/byamoHzaFTpzzuQq4av+z3TlPzm1uzsE3ZVsoIpGIHYyKzzgfzwC9ZzG 9d0ZrtcG1xROelOVotQ87eevrtR3TLe6I9hyD8TcIM2B8ZAthKocRZICkWJfYH4IrgVi FMHXYQLaeyCunbE92LO+4AsrWnDU2aiU+GsBszXpLsaOeIeMMJnRZY/Ni3ctsVLwFhBc TO/g== X-Gm-Message-State: AOAM532sMeUZTZTrPPsr0qH0WH530aNck35oqDMmK2jX7ROVQlGuiKV1 kWZVMqKW/nT862L1q94QH0g= X-Received: by 2002:a19:f808:: with SMTP id a8mr468287lff.62.1598944545980; Tue, 01 Sep 2020 00:15:45 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-38-130.ip.moscow.rt.ru. [37.110.38.130]) by smtp.googlemail.com with ESMTPSA id i187sm62263lfd.65.2020.09.01.00.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 00:15:45 -0700 (PDT) From: Denis Efremov To: julia.lawall@inria.fr Cc: Denis Efremov , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A . R . Silva" Subject: [PATCH v2] coccinelle: misc: add uninitialized_var.cocci script Date: Tue, 1 Sep 2020 10:15:33 +0300 Message-Id: <20200901071533.2725-1-efremov@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200811210127.11889-1-efremov@linux.com> References: <20200811210127.11889-1-efremov@linux.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 63a0895d960a ("compiler: Remove uninitialized_var() macro") and commit 4b19bec97c88 ("docs: deprecated.rst: Add uninitialized_var()") removed uninitialized_var() and deprecated it. The purpose of this script is to prevent new occurrences of open-coded variants of uninitialized_var(). Cc: Kees Cook Cc: Gustavo A. R. Silva Signed-off-by: Denis Efremov --- Changes in v2: - Documentation cited in the script's description - kernel.org link added to the diagnostics messages - "T *var = &var;" pattern removed - "var =@p var", "var =@p *(&(var))" patterns added .../coccinelle/misc/uninitialized_var.cocci | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 scripts/coccinelle/misc/uninitialized_var.cocci diff --git a/scripts/coccinelle/misc/uninitialized_var.cocci b/scripts/coccinelle/misc/uninitialized_var.cocci new file mode 100644 index 000000000000..8fa845cefe11 --- /dev/null +++ b/scripts/coccinelle/misc/uninitialized_var.cocci @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// +/// Please, don't reintroduce uninitialized_var(). +/// From Documentation/process/deprecated.rst: +/// For any compiler warnings about uninitialized variables, just add +/// an initializer. Using warning-silencing tricks is dangerous as it +/// papers over real bugs (or can in the future), and suppresses unrelated +/// compiler warnings (e.g. "unused variable"). If the compiler thinks it +/// is uninitialized, either simply initialize the variable or make compiler +/// changes. Keep in mind that in most cases, if an initialization is +/// obviously redundant, the compiler's dead-store elimination pass will make +/// sure there are no needless variable writes. +/// +// Confidence: High +// Copyright: (C) 2020 Denis Efremov ISPRAS +// Options: --no-includes --include-headers +// + +virtual context +virtual report +virtual org + +@r@ +identifier var; +type T; +position p; +@@ + +( +* T var =@p var; +| +* T var =@p *(&(var)); +| +* var =@p var +| +* var =@p *(&(var)) +) + +@script:python depends on report@ +p << r.p; +@@ + +coccilib.report.print_report(p[0], + "WARNING this kind of initialization is deprecated (https://www.kernel.org/doc/html/latest/process/deprecated.html#uninitialized-var)") + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], + "WARNING this kind of initialization is deprecated (https://www.kernel.org/doc/html/latest/process/deprecated.html#uninitialized-var)") -- 2.26.2