Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b004ff49 authored by Joe Perches's avatar Joe Perches Committed by Greg Kroah-Hartman
Browse files

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: default avatarJoe Perches <joe@perches.com>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Tested-by: default avatarJim Cromie <jim.cromie@gmail.com>
Acked-by: default avatarJason Baron <jbaron@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 798efc60
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -2720,9 +2720,6 @@ static inline const char *netdev_name(const struct net_device *dev)
	return dev->name;
}

extern int __netdev_printk(const char *level, const struct net_device *dev,
			struct va_format *vaf);

extern __printf(3, 4)
int netdev_printk(const char *level, const struct net_device *dev,
		  const char *format, ...);
+23 −3
Original line number Diff line number Diff line
@@ -616,15 +616,35 @@ int __dynamic_netdev_dbg(struct _ddebug *descriptor,
	struct va_format vaf;
	va_list args;
	int res;
	char buf[PREFIX_SIZE];

	BUG_ON(!descriptor);
	BUG_ON(!fmt);

	va_start(args, fmt);

	vaf.fmt = fmt;
	vaf.va = &args;
	res = __netdev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf);

	if (dev && dev->dev.parent) {
		char buf[PREFIX_SIZE];
		char dict[128];
		size_t dictlen;

		dictlen = create_syslog_header(dev->dev.parent,
					       dict, sizeof(dict));

		res = printk_emit(0, 7, dictlen ? dict : NULL, dictlen,
				  "%s%s %s: %s: %pV",
				  dynamic_emit_prefix(descriptor, buf),
				  dev_driver_string(dev->dev.parent),
				  dev_name(dev->dev.parent),
				  netdev_name(dev), &vaf);
	} else if (dev) {
		res = printk(KERN_DEBUG "%s: %pV", netdev_name(dev), &vaf);
	} else {
		res = printk(KERN_DEBUG "(NULL net_device): %pV", &vaf);
	}

	va_end(args);

	return res;
+17 −7
Original line number Diff line number Diff line
@@ -6423,22 +6423,30 @@ const char *netdev_drivername(const struct net_device *dev)
	return empty;
}

int __netdev_printk(const char *level, const struct net_device *dev,
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",
	if (dev && dev->dev.parent) {
		char dict[128];
		size_t dictlen = create_syslog_header(dev->dev.parent,
						      dict, sizeof(dict));

		r = printk_emit(0, level[1] - '0',
				dictlen ? dict : NULL, dictlen,
				"%s %s: %s: %pV",
				dev_driver_string(dev->dev.parent),
				dev_name(dev->dev.parent),
				netdev_name(dev), vaf);
	else if (dev)
	} else if (dev) {
		r = printk("%s%s: %pV", level, netdev_name(dev), vaf);
	else
	} else {
		r = printk("%s(NULL net_device): %pV", level, vaf);
	}

	return r;
}
EXPORT_SYMBOL(__netdev_printk);

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

	r = __netdev_printk(level, dev, &vaf);

	va_end(args);

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