Re: [PATCH 1/1] lib/vsprintf: Fix %pfwf when current node refcount == 0

From: Herve Codina
Date: Tue Nov 14 2023 - 06:48:39 EST


Hi Sakari,

On Tue, 14 Nov 2023 11:28:43 +0000
Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx> wrote:

> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -2108,8 +2108,8 @@ char *fwnode_full_name_string(struct fwnode_handle *fwnode, char *buf,
> > {
> > int depth;
> >
> > - /* Loop starting from the root node to the current node. */
> > - for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) {
> > + /* Loop starting from the root node to the parent of current node. */
> > + for (depth = fwnode_count_parents(fwnode); depth > 0; depth--) {
> > struct fwnode_handle *__fwnode =
> > fwnode_get_nth_parent(fwnode, depth);
>
> How about, without changing the loop:
>
> /*
> * Only get a reference for other nodes, fwnode refcount
> * may be 0 here.
> */
> struct fwnode_handle *__fwnode =
> depth ? fwnode_get_nth_parent(fwnode, depth) : fwnode;
>
> >
> > @@ -2121,6 +2121,16 @@ char *fwnode_full_name_string(struct fwnode_handle *fwnode, char *buf,
> > fwnode_handle_put(__fwnode);
>
> And:
>
> if (__fwnode != fwnode)
> fwnode_handle_put(__fwnode);
>

Sure.
I will just change to keep the both tests consistent.
I mean test with depth or test with __fwnode != fwnode but avoid
mixing them.

What do you think about testing using depth in all cases and so:
if (depth)
fwnode_handle_put(__fwnode);

Best regards,
Hervé