Skip to content

Commit 47d4b26

Browse files
keestorvalds
authored andcommitted
taint: convert to indexed initialization
This converts to using indexed initializers instead of comments, adds a comment on why the taint flags can't be an enum, and make sure that no one forgets to update the taint_flags when adding new bits. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Al Viro <[email protected]> Cc: Alexey Dobriyan <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Randy Dunlap <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1f5bd05 commit 47d4b26

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

include/linux/kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ extern enum system_states {
544544
SYSTEM_RESTART,
545545
} system_state;
546546

547+
/* This cannot be an enum because some may be used in assembly source. */
547548
#define TAINT_PROPRIETARY_MODULE 0
548549
#define TAINT_FORCED_MODULE 1
549550
#define TAINT_CPU_OUT_OF_SPEC 2

kernel/panic.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,23 @@ EXPORT_SYMBOL(panic);
308308
* is being removed anyway.
309309
*/
310310
const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
311-
{ 'P', 'G', true }, /* TAINT_PROPRIETARY_MODULE */
312-
{ 'F', ' ', true }, /* TAINT_FORCED_MODULE */
313-
{ 'S', ' ', false }, /* TAINT_CPU_OUT_OF_SPEC */
314-
{ 'R', ' ', false }, /* TAINT_FORCED_RMMOD */
315-
{ 'M', ' ', false }, /* TAINT_MACHINE_CHECK */
316-
{ 'B', ' ', false }, /* TAINT_BAD_PAGE */
317-
{ 'U', ' ', false }, /* TAINT_USER */
318-
{ 'D', ' ', false }, /* TAINT_DIE */
319-
{ 'A', ' ', false }, /* TAINT_OVERRIDDEN_ACPI_TABLE */
320-
{ 'W', ' ', false }, /* TAINT_WARN */
321-
{ 'C', ' ', true }, /* TAINT_CRAP */
322-
{ 'I', ' ', false }, /* TAINT_FIRMWARE_WORKAROUND */
323-
{ 'O', ' ', true }, /* TAINT_OOT_MODULE */
324-
{ 'E', ' ', true }, /* TAINT_UNSIGNED_MODULE */
325-
{ 'L', ' ', false }, /* TAINT_SOFTLOCKUP */
326-
{ 'K', ' ', true }, /* TAINT_LIVEPATCH */
327-
{ 'X', ' ', true }, /* TAINT_AUX */
311+
[ TAINT_PROPRIETARY_MODULE ] = { 'P', 'G', true },
312+
[ TAINT_FORCED_MODULE ] = { 'F', ' ', true },
313+
[ TAINT_CPU_OUT_OF_SPEC ] = { 'S', ' ', false },
314+
[ TAINT_FORCED_RMMOD ] = { 'R', ' ', false },
315+
[ TAINT_MACHINE_CHECK ] = { 'M', ' ', false },
316+
[ TAINT_BAD_PAGE ] = { 'B', ' ', false },
317+
[ TAINT_USER ] = { 'U', ' ', false },
318+
[ TAINT_DIE ] = { 'D', ' ', false },
319+
[ TAINT_OVERRIDDEN_ACPI_TABLE ] = { 'A', ' ', false },
320+
[ TAINT_WARN ] = { 'W', ' ', false },
321+
[ TAINT_CRAP ] = { 'C', ' ', true },
322+
[ TAINT_FIRMWARE_WORKAROUND ] = { 'I', ' ', false },
323+
[ TAINT_OOT_MODULE ] = { 'O', ' ', true },
324+
[ TAINT_UNSIGNED_MODULE ] = { 'E', ' ', true },
325+
[ TAINT_SOFTLOCKUP ] = { 'L', ' ', false },
326+
[ TAINT_LIVEPATCH ] = { 'K', ' ', true },
327+
[ TAINT_AUX ] = { 'X', ' ', true },
328328
};
329329

330330
/**
@@ -354,6 +354,8 @@ const char *print_tainted(void)
354354
{
355355
static char buf[TAINT_FLAGS_COUNT + sizeof("Tainted: ")];
356356

357+
BUILD_BUG_ON(ARRAY_SIZE(taint_flags) != TAINT_FLAGS_COUNT);
358+
357359
if (tainted_mask) {
358360
char *s;
359361
int i;

0 commit comments

Comments
 (0)