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

printk: add and use LOGLEVEL_<level> defines for KERN_<LEVEL> equivalents

Use #defines instead of magic values.

Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jason Baron <jbaron@akamai.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Joe Perches and committed by
Linus Torvalds
a39d4a85 f80e6968

+29 -18
+1 -1
drivers/usb/storage/debug.c
··· 188 188 189 189 va_start(args, fmt); 190 190 191 - r = dev_vprintk_emit(7, &us->pusb_dev->dev, fmt, args); 191 + r = dev_vprintk_emit(LOGLEVEL_DEBUG, &us->pusb_dev->dev, fmt, args); 192 192 193 193 va_end(args); 194 194
+13
include/linux/kern_levels.h
··· 22 22 */ 23 23 #define KERN_CONT "" 24 24 25 + /* integer equivalents of KERN_<LEVEL> */ 26 + #define LOGLEVEL_SCHED -2 /* Deferred messages from sched code 27 + * are set to this special level */ 28 + #define LOGLEVEL_DEFAULT -1 /* default (or last) loglevel */ 29 + #define LOGLEVEL_EMERG 0 /* system is unusable */ 30 + #define LOGLEVEL_ALERT 1 /* action must be taken immediately */ 31 + #define LOGLEVEL_CRIT 2 /* critical conditions */ 32 + #define LOGLEVEL_ERR 3 /* error conditions */ 33 + #define LOGLEVEL_WARNING 4 /* warning conditions */ 34 + #define LOGLEVEL_NOTICE 5 /* normal but significant condition */ 35 + #define LOGLEVEL_INFO 6 /* informational */ 36 + #define LOGLEVEL_DEBUG 7 /* debug-level messages */ 37 + 25 38 #endif
+13 -15
kernel/printk/printk.c
··· 62 62 CONSOLE_LOGLEVEL_DEFAULT, /* default_console_loglevel */ 63 63 }; 64 64 65 - /* Deferred messaged from sched code are marked by this special level */ 66 - #define SCHED_MESSAGE_LOGLEVEL -2 67 - 68 65 /* 69 66 * Low level drivers may need that to know if they can schedule in 70 67 * their unblank() callback or not. So let's export it. ··· 1256 1259 int do_syslog(int type, char __user *buf, int len, bool from_file) 1257 1260 { 1258 1261 bool clear = false; 1259 - static int saved_console_loglevel = -1; 1262 + static int saved_console_loglevel = LOGLEVEL_DEFAULT; 1260 1263 int error; 1261 1264 1262 1265 error = check_syslog_permissions(type, from_file); ··· 1313 1316 break; 1314 1317 /* Disable logging to console */ 1315 1318 case SYSLOG_ACTION_CONSOLE_OFF: 1316 - if (saved_console_loglevel == -1) 1319 + if (saved_console_loglevel == LOGLEVEL_DEFAULT) 1317 1320 saved_console_loglevel = console_loglevel; 1318 1321 console_loglevel = minimum_console_loglevel; 1319 1322 break; 1320 1323 /* Enable logging to console */ 1321 1324 case SYSLOG_ACTION_CONSOLE_ON: 1322 - if (saved_console_loglevel != -1) { 1325 + if (saved_console_loglevel != LOGLEVEL_DEFAULT) { 1323 1326 console_loglevel = saved_console_loglevel; 1324 - saved_console_loglevel = -1; 1327 + saved_console_loglevel = LOGLEVEL_DEFAULT; 1325 1328 } 1326 1329 break; 1327 1330 /* Set level of messages printed to console */ ··· 1333 1336 len = minimum_console_loglevel; 1334 1337 console_loglevel = len; 1335 1338 /* Implicitly re-enable logging to console */ 1336 - saved_console_loglevel = -1; 1339 + saved_console_loglevel = LOGLEVEL_DEFAULT; 1337 1340 error = 0; 1338 1341 break; 1339 1342 /* Number of chars in the log buffer */ ··· 1626 1629 /* cpu currently holding logbuf_lock in this function */ 1627 1630 static volatile unsigned int logbuf_cpu = UINT_MAX; 1628 1631 1629 - if (level == SCHED_MESSAGE_LOGLEVEL) { 1630 - level = -1; 1632 + if (level == LOGLEVEL_SCHED) { 1633 + level = LOGLEVEL_DEFAULT; 1631 1634 in_sched = true; 1632 1635 } 1633 1636 ··· 1692 1695 const char *end_of_header = printk_skip_level(text); 1693 1696 switch (kern_level) { 1694 1697 case '0' ... '7': 1695 - if (level == -1) 1698 + if (level == LOGLEVEL_DEFAULT) 1696 1699 level = kern_level - '0'; 1700 + /* fallthrough */ 1697 1701 case 'd': /* KERN_DEFAULT */ 1698 1702 lflags |= LOG_PREFIX; 1699 1703 } ··· 1708 1710 } 1709 1711 } 1710 1712 1711 - if (level == -1) 1713 + if (level == LOGLEVEL_DEFAULT) 1712 1714 level = default_message_loglevel; 1713 1715 1714 1716 if (dict) ··· 1786 1788 1787 1789 asmlinkage int vprintk(const char *fmt, va_list args) 1788 1790 { 1789 - return vprintk_emit(0, -1, NULL, 0, fmt, args); 1791 + return vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); 1790 1792 } 1791 1793 EXPORT_SYMBOL(vprintk); 1792 1794 ··· 1840 1842 } 1841 1843 #endif 1842 1844 va_start(args, fmt); 1843 - r = vprintk_emit(0, -1, NULL, 0, fmt, args); 1845 + r = vprintk_emit(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); 1844 1846 va_end(args); 1845 1847 1846 1848 return r; ··· 2629 2631 2630 2632 preempt_disable(); 2631 2633 va_start(args, fmt); 2632 - r = vprintk_emit(0, SCHED_MESSAGE_LOGLEVEL, NULL, 0, fmt, args); 2634 + r = vprintk_emit(0, LOGLEVEL_SCHED, NULL, 0, fmt, args); 2633 2635 va_end(args); 2634 2636 2635 2637 __this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT);
+2 -2
lib/dynamic_debug.c
··· 576 576 } else { 577 577 char buf[PREFIX_SIZE]; 578 578 579 - dev_printk_emit(7, dev, "%s%s %s: %pV", 579 + dev_printk_emit(LOGLEVEL_DEBUG, dev, "%s%s %s: %pV", 580 580 dynamic_emit_prefix(descriptor, buf), 581 581 dev_driver_string(dev), dev_name(dev), 582 582 &vaf); ··· 605 605 if (dev && dev->dev.parent) { 606 606 char buf[PREFIX_SIZE]; 607 607 608 - dev_printk_emit(7, dev->dev.parent, 608 + dev_printk_emit(LOGLEVEL_DEBUG, dev->dev.parent, 609 609 "%s%s %s %s%s: %pV", 610 610 dynamic_emit_prefix(descriptor, buf), 611 611 dev_driver_string(dev->dev.parent),