Commit 99bcf217183e02ebae46373896fba7f12d588001
Committed by
David S. Miller
1 parent
7db6f5fb65
Exists in
master
and in
7 other branches
device.h drivers/base/core.c Convert dev_<level> logging macros to functions
Reduces an x86 defconfig text and data ~55k, .6% smaller. $ size vmlinux* text data bss dec hex filename 7205273 716016 1366288 9287577 8db799 vmlinux 7258890 719768 1366288 9344946 8e97b2 vmlinux.master Uses %pV and struct va_format Format arguments are verified before printk The dev_info macro is converted to _dev_info because there are existing uses of variables named dev_info in the kernel tree like drivers/net/pcmcia/pcnet_cs.c A dev_info macro is created to call _dev_info Signed-off-by: Joe Perches <joe@perches.com> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 2 changed files with 150 additions and 26 deletions Side-by-side Diff
drivers/base/core.c
... | ... | @@ -1819,4 +1819,68 @@ |
1819 | 1819 | spin_unlock(&devices_kset->list_lock); |
1820 | 1820 | async_synchronize_full(); |
1821 | 1821 | } |
1822 | + | |
1823 | +/* | |
1824 | + * Device logging functions | |
1825 | + */ | |
1826 | + | |
1827 | +#ifdef CONFIG_PRINTK | |
1828 | + | |
1829 | +static int __dev_printk(const char *level, const struct device *dev, | |
1830 | + struct va_format *vaf) | |
1831 | +{ | |
1832 | + if (!dev) | |
1833 | + return printk("%s(NULL device *): %pV", level, vaf); | |
1834 | + | |
1835 | + return printk("%s%s %s: %pV", | |
1836 | + level, dev_driver_string(dev), dev_name(dev), vaf); | |
1837 | +} | |
1838 | + | |
1839 | +int dev_printk(const char *level, const struct device *dev, | |
1840 | + const char *fmt, ...) | |
1841 | +{ | |
1842 | + struct va_format vaf; | |
1843 | + va_list args; | |
1844 | + int r; | |
1845 | + | |
1846 | + va_start(args, fmt); | |
1847 | + | |
1848 | + vaf.fmt = fmt; | |
1849 | + vaf.va = &args; | |
1850 | + | |
1851 | + r = __dev_printk(level, dev, &vaf); | |
1852 | + va_end(args); | |
1853 | + | |
1854 | + return r; | |
1855 | +} | |
1856 | +EXPORT_SYMBOL(dev_printk); | |
1857 | + | |
1858 | +#define define_dev_printk_level(func, kern_level) \ | |
1859 | +int func(const struct device *dev, const char *fmt, ...) \ | |
1860 | +{ \ | |
1861 | + struct va_format vaf; \ | |
1862 | + va_list args; \ | |
1863 | + int r; \ | |
1864 | + \ | |
1865 | + va_start(args, fmt); \ | |
1866 | + \ | |
1867 | + vaf.fmt = fmt; \ | |
1868 | + vaf.va = &args; \ | |
1869 | + \ | |
1870 | + r = __dev_printk(kern_level, dev, &vaf); \ | |
1871 | + va_end(args); \ | |
1872 | + \ | |
1873 | + return r; \ | |
1874 | +} \ | |
1875 | +EXPORT_SYMBOL(func); | |
1876 | + | |
1877 | +define_dev_printk_level(dev_emerg, KERN_EMERG); | |
1878 | +define_dev_printk_level(dev_alert, KERN_ALERT); | |
1879 | +define_dev_printk_level(dev_crit, KERN_CRIT); | |
1880 | +define_dev_printk_level(dev_err, KERN_ERR); | |
1881 | +define_dev_printk_level(dev_warn, KERN_WARNING); | |
1882 | +define_dev_printk_level(dev_notice, KERN_NOTICE); | |
1883 | +define_dev_printk_level(_dev_info, KERN_INFO); | |
1884 | + | |
1885 | +#endif |
include/linux/device.h
... | ... | @@ -638,43 +638,103 @@ |
638 | 638 | |
639 | 639 | /* debugging and troubleshooting/diagnostic helpers. */ |
640 | 640 | extern const char *dev_driver_string(const struct device *dev); |
641 | -#define dev_printk(level, dev, format, arg...) \ | |
642 | - printk(level "%s %s: " format , dev_driver_string(dev) , \ | |
643 | - dev_name(dev) , ## arg) | |
644 | 641 | |
645 | -#define dev_emerg(dev, format, arg...) \ | |
646 | - dev_printk(KERN_EMERG , dev , format , ## arg) | |
647 | -#define dev_alert(dev, format, arg...) \ | |
648 | - dev_printk(KERN_ALERT , dev , format , ## arg) | |
649 | -#define dev_crit(dev, format, arg...) \ | |
650 | - dev_printk(KERN_CRIT , dev , format , ## arg) | |
651 | -#define dev_err(dev, format, arg...) \ | |
652 | - dev_printk(KERN_ERR , dev , format , ## arg) | |
653 | -#define dev_warn(dev, format, arg...) \ | |
654 | - dev_printk(KERN_WARNING , dev , format , ## arg) | |
655 | -#define dev_notice(dev, format, arg...) \ | |
656 | - dev_printk(KERN_NOTICE , dev , format , ## arg) | |
657 | -#define dev_info(dev, format, arg...) \ | |
658 | - dev_printk(KERN_INFO , dev , format , ## arg) | |
659 | 642 | |
643 | +#ifdef CONFIG_PRINTK | |
644 | + | |
645 | +extern int dev_printk(const char *level, const struct device *dev, | |
646 | + const char *fmt, ...) | |
647 | + __attribute__ ((format (printf, 3, 4))); | |
648 | +extern int dev_emerg(const struct device *dev, const char *fmt, ...) | |
649 | + __attribute__ ((format (printf, 2, 3))); | |
650 | +extern int dev_alert(const struct device *dev, const char *fmt, ...) | |
651 | + __attribute__ ((format (printf, 2, 3))); | |
652 | +extern int dev_crit(const struct device *dev, const char *fmt, ...) | |
653 | + __attribute__ ((format (printf, 2, 3))); | |
654 | +extern int dev_err(const struct device *dev, const char *fmt, ...) | |
655 | + __attribute__ ((format (printf, 2, 3))); | |
656 | +extern int dev_warn(const struct device *dev, const char *fmt, ...) | |
657 | + __attribute__ ((format (printf, 2, 3))); | |
658 | +extern int dev_notice(const struct device *dev, const char *fmt, ...) | |
659 | + __attribute__ ((format (printf, 2, 3))); | |
660 | +extern int _dev_info(const struct device *dev, const char *fmt, ...) | |
661 | + __attribute__ ((format (printf, 2, 3))); | |
662 | + | |
663 | +#else | |
664 | + | |
665 | +static inline int dev_printk(const char *level, const struct device *dev, | |
666 | + const char *fmt, ...) | |
667 | + __attribute__ ((format (printf, 3, 4))); | |
668 | +static inline int dev_printk(const char *level, const struct device *dev, | |
669 | + const char *fmt, ...) | |
670 | + { return 0; } | |
671 | + | |
672 | +static inline int dev_emerg(const struct device *dev, const char *fmt, ...) | |
673 | + __attribute__ ((format (printf, 2, 3))); | |
674 | +static inline int dev_emerg(const struct device *dev, const char *fmt, ...) | |
675 | + { return 0; } | |
676 | +static inline int dev_crit(const struct device *dev, const char *fmt, ...) | |
677 | + __attribute__ ((format (printf, 2, 3))); | |
678 | +static inline int dev_crit(const struct device *dev, const char *fmt, ...) | |
679 | + { return 0; } | |
680 | +static inline int dev_alert(const struct device *dev, const char *fmt, ...) | |
681 | + __attribute__ ((format (printf, 2, 3))); | |
682 | +static inline int dev_alert(const struct device *dev, const char *fmt, ...) | |
683 | + { return 0; } | |
684 | +static inline int dev_err(const struct device *dev, const char *fmt, ...) | |
685 | + __attribute__ ((format (printf, 2, 3))); | |
686 | +static inline int dev_err(const struct device *dev, const char *fmt, ...) | |
687 | + { return 0; } | |
688 | +static inline int dev_warn(const struct device *dev, const char *fmt, ...) | |
689 | + __attribute__ ((format (printf, 2, 3))); | |
690 | +static inline int dev_warn(const struct device *dev, const char *fmt, ...) | |
691 | + { return 0; } | |
692 | +static inline int dev_notice(const struct device *dev, const char *fmt, ...) | |
693 | + __attribute__ ((format (printf, 2, 3))); | |
694 | +static inline int dev_notice(const struct device *dev, const char *fmt, ...) | |
695 | + { return 0; } | |
696 | +static inline int _dev_info(const struct device *dev, const char *fmt, ...) | |
697 | + __attribute__ ((format (printf, 2, 3))); | |
698 | +static inline int _dev_info(const struct device *dev, const char *fmt, ...) | |
699 | + { return 0; } | |
700 | + | |
701 | +#endif | |
702 | + | |
703 | +/* | |
704 | + * Stupid hackaround for existing uses of non-printk uses dev_info | |
705 | + * | |
706 | + * Note that the definition of dev_info below is actually _dev_info | |
707 | + * and a macro is used to avoid redefining dev_info | |
708 | + */ | |
709 | + | |
710 | +#define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg) | |
711 | + | |
660 | 712 | #if defined(DEBUG) |
661 | 713 | #define dev_dbg(dev, format, arg...) \ |
662 | - dev_printk(KERN_DEBUG , dev , format , ## arg) | |
714 | + dev_printk(KERN_DEBUG, dev, format, ##arg) | |
663 | 715 | #elif defined(CONFIG_DYNAMIC_DEBUG) |
664 | -#define dev_dbg(dev, format, ...) do { \ | |
716 | +#define dev_dbg(dev, format, ...) \ | |
717 | +do { \ | |
665 | 718 | dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \ |
666 | - } while (0) | |
719 | +} while (0) | |
667 | 720 | #else |
668 | -#define dev_dbg(dev, format, arg...) \ | |
669 | - ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) | |
721 | +#define dev_dbg(dev, format, arg...) \ | |
722 | +({ \ | |
723 | + if (0) \ | |
724 | + dev_printk(KERN_DEBUG, dev, format, ##arg); \ | |
725 | + 0; \ | |
726 | +}) | |
670 | 727 | #endif |
671 | 728 | |
672 | 729 | #ifdef VERBOSE_DEBUG |
673 | 730 | #define dev_vdbg dev_dbg |
674 | 731 | #else |
675 | - | |
676 | -#define dev_vdbg(dev, format, arg...) \ | |
677 | - ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) | |
732 | +#define dev_vdbg(dev, format, arg...) \ | |
733 | +({ \ | |
734 | + if (0) \ | |
735 | + dev_printk(KERN_DEBUG, dev, format, ##arg); \ | |
736 | + 0; \ | |
737 | +}) | |
678 | 738 | #endif |
679 | 739 | |
680 | 740 | /* |