Skip to content

Commit b004ff4

Browse files
JoePerchesgregkh
authored andcommitted
netdev_printk/dynamic_netdev_dbg: Directly call printk_emit
A lot of stack is used in recursive printks with %pV. Using multiple levels of %pV (a logging function with %pV that calls another logging function with %pV) can consume more stack than necessary. Avoid excessive stack use by not calling dev_printk from netdev_printk and dynamic_netdev_dbg. Duplicate the logic and form of dev_printk instead. Make __netdev_printk static. Remove EXPORT_SYMBOL(__netdev_printk) Whitespace and brace style neatening. Signed-off-by: Joe Perches <joe@perches.com> Acked-by: David S. Miller <davem@davemloft.net> Tested-by: Jim Cromie <jim.cromie@gmail.com> Acked-by: Jason Baron <jbaron@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 798efc6 commit b004ff4

3 files changed

Lines changed: 40 additions & 13 deletions

File tree

‎include/linux/netdevice.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,9 +2720,6 @@ static inline const char *netdev_name(const struct net_device *dev)
27202720
return dev->name;
27212721
}
27222722

2723-
extern int __netdev_printk(const char *level, const struct net_device *dev,
2724-
struct va_format *vaf);
2725-
27262723
extern __printf(3, 4)
27272724
int netdev_printk(const char *level, const struct net_device *dev,
27282725
const char *format, ...);

‎lib/dynamic_debug.c‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,20 +611,40 @@ EXPORT_SYMBOL(__dynamic_dev_dbg);
611611
#ifdef CONFIG_NET
612612

613613
int __dynamic_netdev_dbg(struct _ddebug *descriptor,
614-
const struct net_device *dev, const char *fmt, ...)
614+
const struct net_device *dev, const char *fmt, ...)
615615
{
616616
struct va_format vaf;
617617
va_list args;
618618
int res;
619-
char buf[PREFIX_SIZE];
620619

621620
BUG_ON(!descriptor);
622621
BUG_ON(!fmt);
623622

624623
va_start(args, fmt);
624+
625625
vaf.fmt = fmt;
626626
vaf.va = &args;
627-
res = __netdev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf);
627+
628+
if (dev && dev->dev.parent) {
629+
char buf[PREFIX_SIZE];
630+
char dict[128];
631+
size_t dictlen;
632+
633+
dictlen = create_syslog_header(dev->dev.parent,
634+
dict, sizeof(dict));
635+
636+
res = printk_emit(0, 7, dictlen ? dict : NULL, dictlen,
637+
"%s%s %s: %s: %pV",
638+
dynamic_emit_prefix(descriptor, buf),
639+
dev_driver_string(dev->dev.parent),
640+
dev_name(dev->dev.parent),
641+
netdev_name(dev), &vaf);
642+
} else if (dev) {
643+
res = printk(KERN_DEBUG "%s: %pV", netdev_name(dev), &vaf);
644+
} else {
645+
res = printk(KERN_DEBUG "(NULL net_device): %pV", &vaf);
646+
}
647+
628648
va_end(args);
629649

630650
return res;

‎net/core/dev.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6423,22 +6423,30 @@ const char *netdev_drivername(const struct net_device *dev)
64236423
return empty;
64246424
}
64256425

6426-
int __netdev_printk(const char *level, const struct net_device *dev,
6426+
static int __netdev_printk(const char *level, const struct net_device *dev,
64276427
struct va_format *vaf)
64286428
{
64296429
int r;
64306430

6431-
if (dev && dev->dev.parent)
6432-
r = dev_printk(level, dev->dev.parent, "%s: %pV",
6433-
netdev_name(dev), vaf);
6434-
else if (dev)
6431+
if (dev && dev->dev.parent) {
6432+
char dict[128];
6433+
size_t dictlen = create_syslog_header(dev->dev.parent,
6434+
dict, sizeof(dict));
6435+
6436+
r = printk_emit(0, level[1] - '0',
6437+
dictlen ? dict : NULL, dictlen,
6438+
"%s %s: %s: %pV",
6439+
dev_driver_string(dev->dev.parent),
6440+
dev_name(dev->dev.parent),
6441+
netdev_name(dev), vaf);
6442+
} else if (dev) {
64356443
r = printk("%s%s: %pV", level, netdev_name(dev), vaf);
6436-
else
6444+
} else {
64376445
r = printk("%s(NULL net_device): %pV", level, vaf);
6446+
}
64386447

64396448
return r;
64406449
}
6441-
EXPORT_SYMBOL(__netdev_printk);
64426450

64436451
int netdev_printk(const char *level, const struct net_device *dev,
64446452
const char *format, ...)
@@ -6453,6 +6461,7 @@ int netdev_printk(const char *level, const struct net_device *dev,
64536461
vaf.va = &args;
64546462

64556463
r = __netdev_printk(level, dev, &vaf);
6464+
64566465
va_end(args);
64576466

64586467
return r;
@@ -6472,6 +6481,7 @@ int func(const struct net_device *dev, const char *fmt, ...) \
64726481
vaf.va = &args; \
64736482
\
64746483
r = __netdev_printk(level, dev, &vaf); \
6484+
\
64756485
va_end(args); \
64766486
\
64776487
return r; \

0 commit comments

Comments
 (0)