diff options
-rw-r--r-- | drivers/base/core.c | 64 | ||||
-rw-r--r-- | include/linux/device.h | 112 |
2 files changed, 150 insertions, 26 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index 9630fbdf4e6c..38bbbd029306 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -1819,3 +1819,67 @@ void device_shutdown(void) | |||
1819 | spin_unlock(&devices_kset->list_lock); | 1819 | spin_unlock(&devices_kset->list_lock); |
1820 | async_synchronize_full(); | 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 | ||
diff --git a/include/linux/device.h b/include/linux/device.h index 0713e10571dd..6a8276f683b6 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -638,43 +638,103 @@ extern void sysdev_shutdown(void); | |||
638 | 638 | ||
639 | /* debugging and troubleshooting/diagnostic helpers. */ | 639 | /* debugging and troubleshooting/diagnostic helpers. */ |
640 | extern const char *dev_driver_string(const struct device *dev); | 640 | extern const char *dev_driver_string(const struct device *dev); |
641 | #define dev_printk(level, dev, format, arg...) \ | 641 | |
642 | printk(level "%s %s: " format , dev_driver_string(dev) , \ | 642 | |
643 | dev_name(dev) , ## arg) | 643 | #ifdef CONFIG_PRINTK |
644 | 644 | ||
645 | #define dev_emerg(dev, format, arg...) \ | 645 | extern int dev_printk(const char *level, const struct device *dev, |
646 | dev_printk(KERN_EMERG , dev , format , ## arg) | 646 | const char *fmt, ...) |
647 | #define dev_alert(dev, format, arg...) \ | 647 | __attribute__ ((format (printf, 3, 4))); |
648 | dev_printk(KERN_ALERT , dev , format , ## arg) | 648 | extern int dev_emerg(const struct device *dev, const char *fmt, ...) |
649 | #define dev_crit(dev, format, arg...) \ | 649 | __attribute__ ((format (printf, 2, 3))); |
650 | dev_printk(KERN_CRIT , dev , format , ## arg) | 650 | extern int dev_alert(const struct device *dev, const char *fmt, ...) |
651 | #define dev_err(dev, format, arg...) \ | 651 | __attribute__ ((format (printf, 2, 3))); |
652 | dev_printk(KERN_ERR , dev , format , ## arg) | 652 | extern int dev_crit(const struct device *dev, const char *fmt, ...) |
653 | #define dev_warn(dev, format, arg...) \ | 653 | __attribute__ ((format (printf, 2, 3))); |
654 | dev_printk(KERN_WARNING , dev , format , ## arg) | 654 | extern int dev_err(const struct device *dev, const char *fmt, ...) |
655 | #define dev_notice(dev, format, arg...) \ | 655 | __attribute__ ((format (printf, 2, 3))); |
656 | dev_printk(KERN_NOTICE , dev , format , ## arg) | 656 | extern int dev_warn(const struct device *dev, const char *fmt, ...) |
657 | #define dev_info(dev, format, arg...) \ | 657 | __attribute__ ((format (printf, 2, 3))); |
658 | dev_printk(KERN_INFO , dev , format , ## arg) | 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) | ||
659 | 711 | ||
660 | #if defined(DEBUG) | 712 | #if defined(DEBUG) |
661 | #define dev_dbg(dev, format, arg...) \ | 713 | #define dev_dbg(dev, format, arg...) \ |
662 | dev_printk(KERN_DEBUG , dev , format , ## arg) | 714 | dev_printk(KERN_DEBUG, dev, format, ##arg) |
663 | #elif defined(CONFIG_DYNAMIC_DEBUG) | 715 | #elif defined(CONFIG_DYNAMIC_DEBUG) |
664 | #define dev_dbg(dev, format, ...) do { \ | 716 | #define dev_dbg(dev, format, ...) \ |
717 | do { \ | ||
665 | dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \ | 718 | dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \ |
666 | } while (0) | 719 | } while (0) |
667 | #else | 720 | #else |
668 | #define dev_dbg(dev, format, arg...) \ | 721 | #define dev_dbg(dev, format, arg...) \ |
669 | ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) | 722 | ({ \ |
723 | if (0) \ | ||
724 | dev_printk(KERN_DEBUG, dev, format, ##arg); \ | ||
725 | 0; \ | ||
726 | }) | ||
670 | #endif | 727 | #endif |
671 | 728 | ||
672 | #ifdef VERBOSE_DEBUG | 729 | #ifdef VERBOSE_DEBUG |
673 | #define dev_vdbg dev_dbg | 730 | #define dev_vdbg dev_dbg |
674 | #else | 731 | #else |
675 | 732 | #define dev_vdbg(dev, format, arg...) \ | |
676 | #define dev_vdbg(dev, format, arg...) \ | 733 | ({ \ |
677 | ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) | 734 | if (0) \ |
735 | dev_printk(KERN_DEBUG, dev, format, ##arg); \ | ||
736 | 0; \ | ||
737 | }) | ||
678 | #endif | 738 | #endif |
679 | 739 | ||
680 | /* | 740 | /* |