aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/netdevice.h36
-rw-r--r--net/core/dev.c62
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...) \ 2253extern 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) 2256extern 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...) \ 2258extern 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...) \ 2260extern 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...) \ 2262extern 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...) \ 2264extern 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...) \ 2266extern 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...) \ 2268extern 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
5805static 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
5821int 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}
5838EXPORT_SYMBOL(netdev_printk);
5839
5840#define define_netdev_printk_level(func, level) \
5841int 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} \
5857EXPORT_SYMBOL(func);
5858
5859define_netdev_printk_level(netdev_emerg, KERN_EMERG);
5860define_netdev_printk_level(netdev_alert, KERN_ALERT);
5861define_netdev_printk_level(netdev_crit, KERN_CRIT);
5862define_netdev_printk_level(netdev_err, KERN_ERR);
5863define_netdev_printk_level(netdev_warn, KERN_WARNING);
5864define_netdev_printk_level(netdev_notice, KERN_NOTICE);
5865define_netdev_printk_level(netdev_info, KERN_INFO);
5866
5805static void __net_exit netdev_exit(struct net *net) 5867static void __net_exit netdev_exit(struct net *net)
5806{ 5868{
5807 kfree(net->dev_name_head); 5869 kfree(net->dev_name_head);