diff options
author | Joe Perches <joe@perches.com> | 2010-06-26 21:02:35 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-07-04 13:40:18 -0400 |
commit | 256df2f3879efdb2e9808bdb1b54b16fbb11fa38 (patch) | |
tree | ec7bd8e1e6d7d7066542420641ccd68e98e42bfa | |
parent | 99bcf217183e02ebae46373896fba7f12d588001 (diff) |
netdevice.h net/core/dev.c: Convert netdev_<level> logging macros to functions
Reduces an x86 defconfig text and data ~2k.
text is smaller, data is larger.
$ size vmlinux*
text data bss dec hex filename
7198862 720112 1366288 9285262 8dae8e vmlinux
7205273 716016 1366288 9287577 8db799 vmlinux.device_h
Uses %pV and struct va_format
Format arguments are verified before printk
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>
-rw-r--r-- | include/linux/netdevice.h | 36 | ||||
-rw-r--r-- | net/core/dev.c | 62 |
2 files changed, 79 insertions, 19 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 8fa5e5aa879a..0183901ea475 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h | |||
@@ -2250,25 +2250,23 @@ static inline const char *netdev_name(const struct net_device *dev) | |||
2250 | return dev->name; | 2250 | return dev->name; |
2251 | } | 2251 | } |
2252 | 2252 | ||
2253 | #define netdev_printk(level, netdev, format, args...) \ | 2253 | extern int netdev_printk(const char *level, const struct net_device *dev, |
2254 | dev_printk(level, (netdev)->dev.parent, \ | 2254 | const char *format, ...) |
2255 | "%s: " format, \ | 2255 | __attribute__ ((format (printf, 3, 4))); |
2256 | netdev_name(netdev), ##args) | 2256 | extern int netdev_emerg(const struct net_device *dev, const char *format, ...) |
2257 | 2257 | __attribute__ ((format (printf, 2, 3))); | |
2258 | #define netdev_emerg(dev, format, args...) \ | 2258 | extern int netdev_alert(const struct net_device *dev, const char *format, ...) |
2259 | netdev_printk(KERN_EMERG, dev, format, ##args) | 2259 | __attribute__ ((format (printf, 2, 3))); |
2260 | #define netdev_alert(dev, format, args...) \ | 2260 | extern int netdev_crit(const struct net_device *dev, const char *format, ...) |
2261 | netdev_printk(KERN_ALERT, dev, format, ##args) | 2261 | __attribute__ ((format (printf, 2, 3))); |
2262 | #define netdev_crit(dev, format, args...) \ | 2262 | extern int netdev_err(const struct net_device *dev, const char *format, ...) |
2263 | netdev_printk(KERN_CRIT, dev, format, ##args) | 2263 | __attribute__ ((format (printf, 2, 3))); |
2264 | #define netdev_err(dev, format, args...) \ | 2264 | extern int netdev_warn(const struct net_device *dev, const char *format, ...) |
2265 | netdev_printk(KERN_ERR, dev, format, ##args) | 2265 | __attribute__ ((format (printf, 2, 3))); |
2266 | #define netdev_warn(dev, format, args...) \ | 2266 | extern int netdev_notice(const struct net_device *dev, const char *format, ...) |
2267 | netdev_printk(KERN_WARNING, dev, format, ##args) | 2267 | __attribute__ ((format (printf, 2, 3))); |
2268 | #define netdev_notice(dev, format, args...) \ | 2268 | extern int netdev_info(const struct net_device *dev, const char *format, ...) |
2269 | netdev_printk(KERN_NOTICE, dev, format, ##args) | 2269 | __attribute__ ((format (printf, 2, 3))); |
2270 | #define netdev_info(dev, format, args...) \ | ||
2271 | netdev_printk(KERN_INFO, dev, format, ##args) | ||
2272 | 2270 | ||
2273 | #if defined(DEBUG) | 2271 | #if defined(DEBUG) |
2274 | #define netdev_dbg(__dev, format, args...) \ | 2272 | #define netdev_dbg(__dev, format, args...) \ |
diff --git a/net/core/dev.c b/net/core/dev.c index e85cc5fa3c4e..93b8929fa21d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -5802,6 +5802,68 @@ char *netdev_drivername(const struct net_device *dev, char *buffer, int len) | |||
5802 | return buffer; | 5802 | return buffer; |
5803 | } | 5803 | } |
5804 | 5804 | ||
5805 | static int __netdev_printk(const char *level, const struct net_device *dev, | ||
5806 | struct va_format *vaf) | ||
5807 | { | ||
5808 | int r; | ||
5809 | |||
5810 | if (dev && dev->dev.parent) | ||
5811 | r = dev_printk(level, dev->dev.parent, "%s: %pV", | ||
5812 | netdev_name(dev), vaf); | ||
5813 | else if (dev) | ||
5814 | r = printk("%s%s: %pV", level, netdev_name(dev), vaf); | ||
5815 | else | ||
5816 | r = printk("%s(NULL net_device): %pV", level, vaf); | ||
5817 | |||
5818 | return r; | ||
5819 | } | ||
5820 | |||
5821 | int netdev_printk(const char *level, const struct net_device *dev, | ||
5822 | const char *format, ...) | ||
5823 | { | ||
5824 | struct va_format vaf; | ||
5825 | va_list args; | ||
5826 | int r; | ||
5827 | |||
5828 | va_start(args, format); | ||
5829 | |||
5830 | vaf.fmt = format; | ||
5831 | vaf.va = &args; | ||
5832 | |||
5833 | r = __netdev_printk(level, dev, &vaf); | ||
5834 | va_end(args); | ||
5835 | |||
5836 | return r; | ||
5837 | } | ||
5838 | EXPORT_SYMBOL(netdev_printk); | ||
5839 | |||
5840 | #define define_netdev_printk_level(func, level) \ | ||
5841 | int func(const struct net_device *dev, const char *fmt, ...) \ | ||
5842 | { \ | ||
5843 | int r; \ | ||
5844 | struct va_format vaf; \ | ||
5845 | va_list args; \ | ||
5846 | \ | ||
5847 | va_start(args, fmt); \ | ||
5848 | \ | ||
5849 | vaf.fmt = fmt; \ | ||
5850 | vaf.va = &args; \ | ||
5851 | \ | ||
5852 | r = __netdev_printk(level, dev, &vaf); \ | ||
5853 | va_end(args); \ | ||
5854 | \ | ||
5855 | return r; \ | ||
5856 | } \ | ||
5857 | EXPORT_SYMBOL(func); | ||
5858 | |||
5859 | define_netdev_printk_level(netdev_emerg, KERN_EMERG); | ||
5860 | define_netdev_printk_level(netdev_alert, KERN_ALERT); | ||
5861 | define_netdev_printk_level(netdev_crit, KERN_CRIT); | ||
5862 | define_netdev_printk_level(netdev_err, KERN_ERR); | ||
5863 | define_netdev_printk_level(netdev_warn, KERN_WARNING); | ||
5864 | define_netdev_printk_level(netdev_notice, KERN_NOTICE); | ||
5865 | define_netdev_printk_level(netdev_info, KERN_INFO); | ||
5866 | |||
5805 | static void __net_exit netdev_exit(struct net *net) | 5867 | static void __net_exit netdev_exit(struct net *net) |
5806 | { | 5868 | { |
5807 | kfree(net->dev_name_head); | 5869 | kfree(net->dev_name_head); |