Re: [PATCH v3 07/10] lib/vsprintf: Make use of fwnode API to obtain node names and separators

From: Sakari Ailus
Date: Mon Sep 02 2019 - 03:11:38 EST


Hi Andy,

On Fri, Aug 30, 2019 at 03:53:14PM +0300, Andy Shevchenko wrote:
> On Thu, Aug 29, 2019 at 01:10:40PM +0300, Sakari Ailus wrote:
> > Instead of implementing our own means of discovering parent nodes, node
> > names or counting how many parents a node has, use the newly added
> > functions in the fwnode API to obtain that information.
> >
>
> Some style comments below.
> Nevertheless,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

Thanks!

>
> > Signed-off-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>
> > ---
> > lib/vsprintf.c | 38 ++++++++++++++++----------------------
> > 1 file changed, 16 insertions(+), 22 deletions(-)
> >
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > index b00b57f9f911f..a04a2167101ef 100644
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -38,6 +38,7 @@
> > #include <net/addrconf.h>
> > #include <linux/siphash.h>
> > #include <linux/compiler.h>
> > +#include <linux/property.h>
> > #ifdef CONFIG_BLOCK
> > #include <linux/blkdev.h>
> > #endif
> > @@ -1863,32 +1864,24 @@ char *flags_string(char *buf, char *end, void *flags_ptr,
> > return format_flags(buf, end, flags, names);
> > }
> >
> > -static const char *device_node_name_for_depth(const struct device_node *np, int depth)
> > -{
> > - for ( ; np && depth; depth--)
> > - np = np->parent;
> > -
> > - return kbasename(np->full_name);
> > -}
> > -
> > static noinline_for_stack
> > -char *device_node_gen_full_name(const struct device_node *np, char *buf, char *end)
>
> > +char *fwnode_full_name_string(struct fwnode_handle *fwnode, char *buf,
> > + char *end)
>
> I would leave it on one line.
>
> > {
> > int depth;
> > - const struct device_node *parent = np->parent;
> >
> > - /* special case for root node */
> > - if (!parent)
> > - return string_nocheck(buf, end, "/", default_str_spec);
> > + for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) {
> > + struct fwnode_handle *__fwnode =
> > + fwnode_get_nth_parent(fwnode, depth);
>
> Ditto if you name temporary variable like fw / fh / fn / etc.
>
> >
> > - for (depth = 0; parent->parent; depth++)
> > - parent = parent->parent;
> > -
> > - for ( ; depth >= 0; depth--) {
> > - buf = string_nocheck(buf, end, "/", default_str_spec);
> > - buf = string(buf, end, device_node_name_for_depth(np, depth),
>
> > + buf = string(buf, end, fwnode_get_name_prefix(__fwnode),
> > + default_str_spec);
> > + buf = string(buf, end, fwnode_get_name(__fwnode),
> > default_str_spec);
>
> Ditto.
>
> > +
> > + fwnode_handle_put(__fwnode);
> > }
> > +
> > return buf;
> > }
> >
> > @@ -1933,10 +1926,11 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
> >
> > switch (*fmt) {
> > case 'f': /* full_name */
> > - buf = device_node_gen_full_name(dn, buf, end);
>
> > + buf = fwnode_full_name_string(of_fwnode_handle(dn), buf,
> > + end);
>
> Ditto, disregard checkpatch.

Why? I see no reason to avoid wrapping here; in fact, if I'd review a patch
that contained such code, I'd ask the submitter to wrap the lines.

--
Sakari Ailus
sakari.ailus@xxxxxxxxxxxxxxx