Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

coccinelle: misc: add uninitialized_var.cocci script

uninitialized_var() macro was removed from the sources [1] and
other warning-silencing tricks were deprecated [2]. The purpose of this
cocci script is to prevent new occurrences of uninitialized_var()
open-coded variants.

[1] commit 63a0895d960a ("compiler: Remove uninitialized_var() macro")
[2] commit 4b19bec97c88 ("docs: deprecated.rst: Add uninitialized_var()")

Cc: Kees Cook <keescook@chromium.org>
Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Denis Efremov <efremov@linux.com>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>

authored by

Denis Efremov and committed by
Julia Lawall
7c9dc603 5e0c074e

+51
+51
scripts/coccinelle/misc/uninitialized_var.cocci
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /// 3 + /// Please, don't reintroduce uninitialized_var(). 4 + /// From Documentation/process/deprecated.rst: 5 + /// For any compiler warnings about uninitialized variables, just add 6 + /// an initializer. Using warning-silencing tricks is dangerous as it 7 + /// papers over real bugs (or can in the future), and suppresses unrelated 8 + /// compiler warnings (e.g. "unused variable"). If the compiler thinks it 9 + /// is uninitialized, either simply initialize the variable or make compiler 10 + /// changes. Keep in mind that in most cases, if an initialization is 11 + /// obviously redundant, the compiler's dead-store elimination pass will make 12 + /// sure there are no needless variable writes. 13 + /// 14 + // Confidence: High 15 + // Copyright: (C) 2020 Denis Efremov ISPRAS 16 + // Options: --no-includes --include-headers 17 + // 18 + 19 + virtual context 20 + virtual report 21 + virtual org 22 + 23 + @r@ 24 + identifier var; 25 + type T; 26 + position p; 27 + @@ 28 + 29 + ( 30 + * T var =@p var; 31 + | 32 + * T var =@p *(&(var)); 33 + | 34 + * var =@p var 35 + | 36 + * var =@p *(&(var)) 37 + ) 38 + 39 + @script:python depends on report@ 40 + p << r.p; 41 + @@ 42 + 43 + coccilib.report.print_report(p[0], 44 + "WARNING this kind of initialization is deprecated (https://www.kernel.org/doc/html/latest/process/deprecated.html#uninitialized-var)") 45 + 46 + @script:python depends on org@ 47 + p << r.p; 48 + @@ 49 + 50 + coccilib.org.print_todo(p[0], 51 + "WARNING this kind of initialization is deprecated (https://www.kernel.org/doc/html/latest/process/deprecated.html#uninitialized-var)")