Commit 256df2f3 authored by Joe Perches's avatar Joe Perches Committed by David S. Miller

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: default avatarJoe Perches <joe@perches.com>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 99bcf217
...@@ -2250,25 +2250,23 @@ static inline const char *netdev_name(const struct net_device *dev) ...@@ -2250,25 +2250,23 @@ static inline const char *netdev_name(const struct net_device *dev)
return dev->name; return dev->name;
} }
#define netdev_printk(level, netdev, format, args...) \ extern int netdev_printk(const char *level, const struct net_device *dev,
dev_printk(level, (netdev)->dev.parent, \ const char *format, ...)
"%s: " format, \ __attribute__ ((format (printf, 3, 4)));
netdev_name(netdev), ##args) extern int netdev_emerg(const struct net_device *dev, const char *format, ...)
__attribute__ ((format (printf, 2, 3)));
#define netdev_emerg(dev, format, args...) \ extern int netdev_alert(const struct net_device *dev, const char *format, ...)
netdev_printk(KERN_EMERG, dev, format, ##args) __attribute__ ((format (printf, 2, 3)));
#define netdev_alert(dev, format, args...) \ extern int netdev_crit(const struct net_device *dev, const char *format, ...)
netdev_printk(KERN_ALERT, dev, format, ##args) __attribute__ ((format (printf, 2, 3)));
#define netdev_crit(dev, format, args...) \ extern int netdev_err(const struct net_device *dev, const char *format, ...)
netdev_printk(KERN_CRIT, dev, format, ##args) __attribute__ ((format (printf, 2, 3)));
#define netdev_err(dev, format, args...) \ extern int netdev_warn(const struct net_device *dev, const char *format, ...)
netdev_printk(KERN_ERR, dev, format, ##args) __attribute__ ((format (printf, 2, 3)));
#define netdev_warn(dev, format, args...) \ extern int netdev_notice(const struct net_device *dev, const char *format, ...)
netdev_printk(KERN_WARNING, dev, format, ##args) __attribute__ ((format (printf, 2, 3)));
#define netdev_notice(dev, format, args...) \ extern int netdev_info(const struct net_device *dev, const char *format, ...)
netdev_printk(KERN_NOTICE, dev, format, ##args) __attribute__ ((format (printf, 2, 3)));
#define netdev_info(dev, format, args...) \
netdev_printk(KERN_INFO, dev, format, ##args)
#if defined(DEBUG) #if defined(DEBUG)
#define netdev_dbg(__dev, format, args...) \ #define netdev_dbg(__dev, format, args...) \
......
...@@ -5802,6 +5802,68 @@ char *netdev_drivername(const struct net_device *dev, char *buffer, int len) ...@@ -5802,6 +5802,68 @@ char *netdev_drivername(const struct net_device *dev, char *buffer, int len)
return buffer; return buffer;
} }
static int __netdev_printk(const char *level, const struct net_device *dev,
struct va_format *vaf)
{
int r;
if (dev && dev->dev.parent)
r = dev_printk(level, dev->dev.parent, "%s: %pV",
netdev_name(dev), vaf);
else if (dev)
r = printk("%s%s: %pV", level, netdev_name(dev), vaf);
else
r = printk("%s(NULL net_device): %pV", level, vaf);
return r;
}
int netdev_printk(const char *level, const struct net_device *dev,
const char *format, ...)
{
struct va_format vaf;
va_list args;
int r;
va_start(args, format);
vaf.fmt = format;
vaf.va = &args;
r = __netdev_printk(level, dev, &vaf);
va_end(args);
return r;
}
EXPORT_SYMBOL(netdev_printk);
#define define_netdev_printk_level(func, level) \
int func(const struct net_device *dev, const char *fmt, ...) \
{ \
int r; \
struct va_format vaf; \
va_list args; \
\
va_start(args, fmt); \
\
vaf.fmt = fmt; \
vaf.va = &args; \
\
r = __netdev_printk(level, dev, &vaf); \
va_end(args); \
\
return r; \
} \
EXPORT_SYMBOL(func);
define_netdev_printk_level(netdev_emerg, KERN_EMERG);
define_netdev_printk_level(netdev_alert, KERN_ALERT);
define_netdev_printk_level(netdev_crit, KERN_CRIT);
define_netdev_printk_level(netdev_err, KERN_ERR);
define_netdev_printk_level(netdev_warn, KERN_WARNING);
define_netdev_printk_level(netdev_notice, KERN_NOTICE);
define_netdev_printk_level(netdev_info, KERN_INFO);
static void __net_exit netdev_exit(struct net *net) static void __net_exit netdev_exit(struct net *net)
{ {
kfree(net->dev_name_head); kfree(net->dev_name_head);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment