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

docs: deprecated.rst: Add uninitialized_var()

Nothing should be using this macro, and the entire idea of tricking the
compiler into silencing such warnings is a mistake.

Cc: Jonathan Corbet <corbet@lwn.net>
Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: Joe Perches <joe@perches.com>
Cc: linux-doc@vger.kernel.org
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>

+18
+18
Documentation/process/deprecated.rst
··· 51 51 "unreachable" conditions. (For example, see commits like `this one 52 52 <https://git.kernel.org/linus/d4689846881d160a4d12a514e991a740bcb5d65a>`_.) 53 53 54 + uninitialized_var() 55 + ------------------- 56 + For any compiler warnings about uninitialized variables, just add 57 + an initializer. Using the uninitialized_var() macro (or similar 58 + warning-silencing tricks) is dangerous as it papers over `real bugs 59 + <https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/>`_ 60 + (or can in the future), and suppresses unrelated compiler warnings 61 + (e.g. "unused variable"). If the compiler thinks it is uninitialized, 62 + either simply initialize the variable or make compiler changes. Keep in 63 + mind that in most cases, if an initialization is obviously redundant, 64 + the compiler's dead-store elimination pass will make sure there are no 65 + needless variable writes. 66 + 67 + As Linus has said, this macro 68 + `must <https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/>`_ 69 + `be <https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/>`_ 70 + `removed <https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/>`_. 71 + 54 72 open-coded arithmetic in allocator arguments 55 73 -------------------------------------------- 56 74 Dynamic size calculations (especially multiplication) should not be