Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1673186

Re: [PATCH v2] vsprintf: Add %p extension "%pOF" for device tree

From Joe Perches <joe@perches.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] vsprintf: Add %p extension "%pOF" for device tree
Date 2017-06-23 05:10 +0200
Message-ID <tVn8S-593-19@gated-at.bofh.it> (permalink)
References <tSnf3-1rl-3@gated-at.bofh.it> <tVhd8-1bE-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, 2017-06-22 at 15:44 -0500, Rob Herring wrote:
> From: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> 
> 90% of the usage of device node's full_name is printing it out in a
> kernel message. However, storing the full path for every node is
> wasteful and redundant. With a custom format specifier, we can generate
> the full path at run-time and eventually remove the full path from every
> node.
> 
> For instance typical use is:
> 	pr_info("Frobbing node %s\n", node->full_name);
> 
> Which can be written now as:
> 	pr_info("Frobbing node %pOF\n", node);

I still think this should use another identifier like
%pO for object then another letter for type of object
maybe N for node.

And F is flags, f is name

> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
[]
> @@ -1470,6 +1471,131 @@ char *flags_string(char *buf, char *end, void *flags_ptr, const char *fmt)
>  	return format_flags(buf, end, flags, names);
>  }
>  
> +static int device_node_calc_depth(const struct device_node *np)
> +{
> +	int d;
> +
> +	for (d = 0; np; d++)
> +		np = np->parent;
> +
> +	return d;
> +}
> +
> +static noinline_for_stack
> +char *device_node_gen_full_name(const struct device_node *np, char *buf, char *end)
> +{
> +	int i;
> +	int depth = device_node_calc_depth(np);
> +	static const struct printf_spec strspec = {
> +		.field_width = -1,
> +		.precision = -1,
> +	};
> +	const struct device_node *nodes[depth];
> +
> +	if (!depth)
> +		returnuf;
> +	/* special case for root node */
> +	if (depth == 1)
> +		return string(buf, end, "/", strspec);
> +
> +	depth--;
> +	for (i = depth - 1; i >= 0; i--) {
> +		nodes[i] = np;
> +		np = np->parent;
> +	}
> +	for (i = 0; i < depth; i++) {
> +		buf = string(buf, end, "/", strspec);
> +		buf = string(buf, end, kbasename(nodes[i]->full_name), strspec);
> +	}
> +	return buf;
> +}

I think there should be another function to get
a particular struct device_node * at a particular
depth to avoid all the pointers on stack.

Basically, adapt the for (i = depth - 1 loop to
a function that returns nodes[i]

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2] vsprintf: Add %p extension "%pOF" for device tree Rob Herring <robh@kernel.org> - 2017-06-22 22:50 +0200
  Re: [PATCH v2] vsprintf: Add %p extension "%pOF" for device tree Randy Dunlap <rdunlap@infradead.org> - 2017-06-23 00:50 +0200
    Re: [PATCH v2] vsprintf: Add %p extension "%pOF" for device tree Rob Herring <robh@kernel.org> - 2017-06-23 16:10 +0200
  Re: [PATCH v2] vsprintf: Add %p extension "%pOF" for device tree Joe Perches <joe@perches.com> - 2017-06-23 05:10 +0200
    Re: [PATCH v2] vsprintf: Add %p extension "%pOF" for device tree Rob Herring <robh@kernel.org> - 2017-06-23 16:20 +0200
  Re: [PATCH v3] vsprintf: Add %p extension "%pOF" for device tree Joe Perches <joe@perches.com> - 2017-06-23 19:40 +0200
  [PATCH v3] vsprintf: Add %p extension "%pOF" for device tree Rob Herring <robh@kernel.org> - 2017-06-23 19:40 +0200

csiph-web